1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.location.cts.asn1.supl2.supl_pos; 18 19 /* 20 */ 21 22 23 // 24 // 25 import android.location.cts.asn1.base.Asn1Null; 26 import android.location.cts.asn1.base.Asn1Object; 27 import android.location.cts.asn1.base.Asn1Sequence; 28 import android.location.cts.asn1.base.Asn1Tag; 29 import android.location.cts.asn1.base.BitStream; 30 import android.location.cts.asn1.base.BitStreamReader; 31 import android.location.cts.asn1.base.SequenceComponent; 32 import android.location.cts.asn1.supl2.ulp_components.Velocity; 33 import android.location.cts.asn1.supl2.ulp_version_2_message_extensions.Ver2_SUPL_POS_extension; 34 import com.google.common.collect.ImmutableList; 35 import java.util.Collection; 36 import javax.annotation.Nullable; 37 38 39 /** 40 */ 41 public class SUPLPOS extends Asn1Sequence { 42 // 43 44 private static final Asn1Tag TAG_SUPLPOS 45 = Asn1Tag.fromClassAndNumber(-1, -1); 46 SUPLPOS()47 public SUPLPOS() { 48 super(); 49 } 50 51 @Override 52 @Nullable getTag()53 protected Asn1Tag getTag() { 54 return TAG_SUPLPOS; 55 } 56 57 @Override isTagImplicit()58 protected boolean isTagImplicit() { 59 return true; 60 } 61 getPossibleFirstTags()62 public static Collection<Asn1Tag> getPossibleFirstTags() { 63 if (TAG_SUPLPOS != null) { 64 return ImmutableList.of(TAG_SUPLPOS); 65 } else { 66 return Asn1Sequence.getPossibleFirstTags(); 67 } 68 } 69 70 /** 71 * Creates a new SUPLPOS from encoded stream. 72 */ fromPerUnaligned(byte[] encodedBytes)73 public static SUPLPOS fromPerUnaligned(byte[] encodedBytes) { 74 SUPLPOS result = new SUPLPOS(); 75 result.decodePerUnaligned(new BitStreamReader(encodedBytes)); 76 return result; 77 } 78 79 /** 80 * Creates a new SUPLPOS from encoded stream. 81 */ fromPerAligned(byte[] encodedBytes)82 public static SUPLPOS fromPerAligned(byte[] encodedBytes) { 83 SUPLPOS result = new SUPLPOS(); 84 result.decodePerAligned(new BitStreamReader(encodedBytes)); 85 return result; 86 } 87 88 89 isExtensible()90 @Override protected boolean isExtensible() { 91 return true; 92 } 93 containsExtensionValues()94 @Override public boolean containsExtensionValues() { 95 for (SequenceComponent extensionComponent : getExtensionComponents()) { 96 if (extensionComponent.isExplicitlySet()) return true; 97 } 98 return false; 99 } 100 101 102 private PosPayLoad posPayLoad_; getPosPayLoad()103 public PosPayLoad getPosPayLoad() { 104 return posPayLoad_; 105 } 106 /** 107 * @throws ClassCastException if value is not a PosPayLoad 108 */ setPosPayLoad(Asn1Object value)109 public void setPosPayLoad(Asn1Object value) { 110 this.posPayLoad_ = (PosPayLoad) value; 111 } setPosPayLoadToNewInstance()112 public PosPayLoad setPosPayLoadToNewInstance() { 113 posPayLoad_ = new PosPayLoad(); 114 return posPayLoad_; 115 } 116 117 private Velocity velocity_; getVelocity()118 public Velocity getVelocity() { 119 return velocity_; 120 } 121 /** 122 * @throws ClassCastException if value is not a Velocity 123 */ setVelocity(Asn1Object value)124 public void setVelocity(Asn1Object value) { 125 this.velocity_ = (Velocity) value; 126 } setVelocityToNewInstance()127 public Velocity setVelocityToNewInstance() { 128 velocity_ = new Velocity(); 129 return velocity_; 130 } 131 132 133 134 private Ver2_SUPL_POS_extension extensionVer2_SUPL_POS_extension; getExtensionVer2_SUPL_POS_extension()135 public Ver2_SUPL_POS_extension getExtensionVer2_SUPL_POS_extension() { 136 return extensionVer2_SUPL_POS_extension; 137 } 138 /** 139 * @throws ClassCastException if value is not a Ver2_SUPL_POS_extension 140 */ setExtensionVer2_SUPL_POS_extension(Asn1Object value)141 public void setExtensionVer2_SUPL_POS_extension(Asn1Object value) { 142 extensionVer2_SUPL_POS_extension = (Ver2_SUPL_POS_extension) value; 143 } setExtensionVer2_SUPL_POS_extensionToNewInstance()144 public void setExtensionVer2_SUPL_POS_extensionToNewInstance() { 145 extensionVer2_SUPL_POS_extension = new Ver2_SUPL_POS_extension(); 146 } 147 148 149 150 getComponents()151 @Override public Iterable<? extends SequenceComponent> getComponents() { 152 ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder(); 153 154 builder.add(new SequenceComponent() { 155 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 0); 156 157 @Override public boolean isExplicitlySet() { 158 return getPosPayLoad() != null; 159 } 160 161 @Override public boolean hasDefaultValue() { 162 return false; 163 } 164 165 @Override public boolean isOptional() { 166 return false; 167 } 168 169 @Override public Asn1Object getComponentValue() { 170 return getPosPayLoad(); 171 } 172 173 @Override public void setToNewInstance() { 174 setPosPayLoadToNewInstance(); 175 } 176 177 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 178 return tag == null ? PosPayLoad.getPossibleFirstTags() : ImmutableList.of(tag); 179 } 180 181 @Override 182 public Asn1Tag getTag() { 183 return tag; 184 } 185 186 @Override 187 public boolean isImplicitTagging() { 188 return true; 189 } 190 191 @Override public String toIndentedString(String indent) { 192 return "posPayLoad : " 193 + getPosPayLoad().toIndentedString(indent); 194 } 195 }); 196 197 builder.add(new SequenceComponent() { 198 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 1); 199 200 @Override public boolean isExplicitlySet() { 201 return getVelocity() != null; 202 } 203 204 @Override public boolean hasDefaultValue() { 205 return false; 206 } 207 208 @Override public boolean isOptional() { 209 return true; 210 } 211 212 @Override public Asn1Object getComponentValue() { 213 return getVelocity(); 214 } 215 216 @Override public void setToNewInstance() { 217 setVelocityToNewInstance(); 218 } 219 220 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 221 return tag == null ? Velocity.getPossibleFirstTags() : ImmutableList.of(tag); 222 } 223 224 @Override 225 public Asn1Tag getTag() { 226 return tag; 227 } 228 229 @Override 230 public boolean isImplicitTagging() { 231 return true; 232 } 233 234 @Override public String toIndentedString(String indent) { 235 return "velocity : " 236 + getVelocity().toIndentedString(indent); 237 } 238 }); 239 240 return builder.build(); 241 } 242 243 @Override public Iterable<? extends SequenceComponent> getExtensionComponents()244 getExtensionComponents() { 245 ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder(); 246 247 builder.add(new SequenceComponent() { 248 @Override public boolean isExplicitlySet() { 249 return getExtensionVer2_SUPL_POS_extension() != null; 250 } 251 252 @Override public boolean hasDefaultValue() { 253 return false; 254 } 255 256 @Override public boolean isOptional() { 257 return true; 258 } 259 260 @Override public Asn1Object getComponentValue() { 261 return getExtensionVer2_SUPL_POS_extension(); 262 } 263 264 @Override public void setToNewInstance() { 265 setExtensionVer2_SUPL_POS_extensionToNewInstance(); 266 } 267 268 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 269 throw new UnsupportedOperationException( 270 "BER decoding not supported for extension elements"); 271 } 272 273 @Override 274 public Asn1Tag getTag() { 275 throw new UnsupportedOperationException( 276 "BER is not supported for extension elements"); 277 } 278 279 @Override 280 public boolean isImplicitTagging() { 281 throw new UnsupportedOperationException( 282 "BER is not supported for extension elements"); 283 } 284 285 @Override public String toIndentedString(String indent) { 286 return "ver2_SUPL_POS_extension : " 287 + getExtensionVer2_SUPL_POS_extension().toIndentedString(indent); 288 } 289 }); 290 291 return builder.build(); 292 } 293 294 295 296 297 298 299 300 301 302 303 encodePerUnaligned()304 @Override public Iterable<BitStream> encodePerUnaligned() { 305 return super.encodePerUnaligned(); 306 } 307 encodePerAligned()308 @Override public Iterable<BitStream> encodePerAligned() { 309 return super.encodePerAligned(); 310 } 311 decodePerUnaligned(BitStreamReader reader)312 @Override public void decodePerUnaligned(BitStreamReader reader) { 313 super.decodePerUnaligned(reader); 314 } 315 decodePerAligned(BitStreamReader reader)316 @Override public void decodePerAligned(BitStreamReader reader) { 317 super.decodePerAligned(reader); 318 } 319 toString()320 @Override public String toString() { 321 return toIndentedString(""); 322 } 323 toIndentedString(String indent)324 public String toIndentedString(String indent) { 325 StringBuilder builder = new StringBuilder(); 326 builder.append("SUPLPOS = {\n"); 327 final String internalIndent = indent + " "; 328 for (SequenceComponent component : getComponents()) { 329 if (component.isExplicitlySet()) { 330 builder.append(internalIndent) 331 .append(component.toIndentedString(internalIndent)); 332 } 333 } 334 if (isExtensible()) { 335 builder.append(internalIndent).append("...\n"); 336 for (SequenceComponent component : getExtensionComponents()) { 337 if (component.isExplicitlySet()) { 338 builder.append(internalIndent) 339 .append(component.toIndentedString(internalIndent)); 340 } 341 } 342 } 343 builder.append(indent).append("};\n"); 344 return builder.toString(); 345 } 346 } 347