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.ulp_components; 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.Asn1UTCTime; 30 import android.location.cts.asn1.base.BitStream; 31 import android.location.cts.asn1.base.BitStreamReader; 32 import android.location.cts.asn1.base.SequenceComponent; 33 import com.google.common.collect.ImmutableList; 34 import java.util.Collection; 35 import javax.annotation.Nullable; 36 37 38 /** 39 */ 40 public class Position extends Asn1Sequence { 41 // 42 43 private static final Asn1Tag TAG_Position 44 = Asn1Tag.fromClassAndNumber(-1, -1); 45 Position()46 public Position() { 47 super(); 48 } 49 50 @Override 51 @Nullable getTag()52 protected Asn1Tag getTag() { 53 return TAG_Position; 54 } 55 56 @Override isTagImplicit()57 protected boolean isTagImplicit() { 58 return true; 59 } 60 getPossibleFirstTags()61 public static Collection<Asn1Tag> getPossibleFirstTags() { 62 if (TAG_Position != null) { 63 return ImmutableList.of(TAG_Position); 64 } else { 65 return Asn1Sequence.getPossibleFirstTags(); 66 } 67 } 68 69 /** 70 * Creates a new Position from encoded stream. 71 */ fromPerUnaligned(byte[] encodedBytes)72 public static Position fromPerUnaligned(byte[] encodedBytes) { 73 Position result = new Position(); 74 result.decodePerUnaligned(new BitStreamReader(encodedBytes)); 75 return result; 76 } 77 78 /** 79 * Creates a new Position from encoded stream. 80 */ fromPerAligned(byte[] encodedBytes)81 public static Position fromPerAligned(byte[] encodedBytes) { 82 Position result = new Position(); 83 result.decodePerAligned(new BitStreamReader(encodedBytes)); 84 return result; 85 } 86 87 88 isExtensible()89 @Override protected boolean isExtensible() { 90 return true; 91 } 92 containsExtensionValues()93 @Override public boolean containsExtensionValues() { 94 for (SequenceComponent extensionComponent : getExtensionComponents()) { 95 if (extensionComponent.isExplicitlySet()) return true; 96 } 97 return false; 98 } 99 100 101 private Position.timestampType timestamp_; getTimestamp()102 public Position.timestampType getTimestamp() { 103 return timestamp_; 104 } 105 /** 106 * @throws ClassCastException if value is not a Position.timestampType 107 */ setTimestamp(Asn1Object value)108 public void setTimestamp(Asn1Object value) { 109 this.timestamp_ = (Position.timestampType) value; 110 } setTimestampToNewInstance()111 public Position.timestampType setTimestampToNewInstance() { 112 timestamp_ = new Position.timestampType(); 113 return timestamp_; 114 } 115 116 private PositionEstimate positionEstimate_; getPositionEstimate()117 public PositionEstimate getPositionEstimate() { 118 return positionEstimate_; 119 } 120 /** 121 * @throws ClassCastException if value is not a PositionEstimate 122 */ setPositionEstimate(Asn1Object value)123 public void setPositionEstimate(Asn1Object value) { 124 this.positionEstimate_ = (PositionEstimate) value; 125 } setPositionEstimateToNewInstance()126 public PositionEstimate setPositionEstimateToNewInstance() { 127 positionEstimate_ = new PositionEstimate(); 128 return positionEstimate_; 129 } 130 131 private Velocity velocity_; getVelocity()132 public Velocity getVelocity() { 133 return velocity_; 134 } 135 /** 136 * @throws ClassCastException if value is not a Velocity 137 */ setVelocity(Asn1Object value)138 public void setVelocity(Asn1Object value) { 139 this.velocity_ = (Velocity) value; 140 } setVelocityToNewInstance()141 public Velocity setVelocityToNewInstance() { 142 velocity_ = new Velocity(); 143 return velocity_; 144 } 145 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 getTimestamp() != 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 getTimestamp(); 171 } 172 173 @Override public void setToNewInstance() { 174 setTimestampToNewInstance(); 175 } 176 177 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 178 return tag == null ? Position.timestampType.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 "timestamp : " 193 + getTimestamp().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 getPositionEstimate() != null; 202 } 203 204 @Override public boolean hasDefaultValue() { 205 return false; 206 } 207 208 @Override public boolean isOptional() { 209 return false; 210 } 211 212 @Override public Asn1Object getComponentValue() { 213 return getPositionEstimate(); 214 } 215 216 @Override public void setToNewInstance() { 217 setPositionEstimateToNewInstance(); 218 } 219 220 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 221 return tag == null ? PositionEstimate.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 "positionEstimate : " 236 + getPositionEstimate().toIndentedString(indent); 237 } 238 }); 239 240 builder.add(new SequenceComponent() { 241 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 2); 242 243 @Override public boolean isExplicitlySet() { 244 return getVelocity() != null; 245 } 246 247 @Override public boolean hasDefaultValue() { 248 return false; 249 } 250 251 @Override public boolean isOptional() { 252 return true; 253 } 254 255 @Override public Asn1Object getComponentValue() { 256 return getVelocity(); 257 } 258 259 @Override public void setToNewInstance() { 260 setVelocityToNewInstance(); 261 } 262 263 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 264 return tag == null ? Velocity.getPossibleFirstTags() : ImmutableList.of(tag); 265 } 266 267 @Override 268 public Asn1Tag getTag() { 269 return tag; 270 } 271 272 @Override 273 public boolean isImplicitTagging() { 274 return true; 275 } 276 277 @Override public String toIndentedString(String indent) { 278 return "velocity : " 279 + getVelocity().toIndentedString(indent); 280 } 281 }); 282 283 return builder.build(); 284 } 285 286 @Override public Iterable<? extends SequenceComponent> getExtensionComponents()287 getExtensionComponents() { 288 ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder(); 289 290 return builder.build(); 291 } 292 293 294 /* 295 */ 296 297 298 // 299 300 /** 301 */ 302 public static class timestampType extends Asn1UTCTime { 303 // 304 305 private static final Asn1Tag TAG_timestampType 306 = Asn1Tag.fromClassAndNumber(-1, -1); 307 timestampType()308 public timestampType() { 309 super(); 310 } 311 312 @Override 313 @Nullable getTag()314 protected Asn1Tag getTag() { 315 return TAG_timestampType; 316 } 317 318 @Override isTagImplicit()319 protected boolean isTagImplicit() { 320 return true; 321 } 322 getPossibleFirstTags()323 public static Collection<Asn1Tag> getPossibleFirstTags() { 324 if (TAG_timestampType != null) { 325 return ImmutableList.of(TAG_timestampType); 326 } else { 327 return Asn1UTCTime.getPossibleFirstTags(); 328 } 329 } 330 331 /** 332 * Creates a new timestampType from encoded stream. 333 */ fromPerUnaligned(byte[] encodedBytes)334 public static timestampType fromPerUnaligned(byte[] encodedBytes) { 335 timestampType result = new timestampType(); 336 result.decodePerUnaligned(new BitStreamReader(encodedBytes)); 337 return result; 338 } 339 340 /** 341 * Creates a new timestampType from encoded stream. 342 */ fromPerAligned(byte[] encodedBytes)343 public static timestampType fromPerAligned(byte[] encodedBytes) { 344 timestampType result = new timestampType(); 345 result.decodePerAligned(new BitStreamReader(encodedBytes)); 346 return result; 347 } 348 encodePerUnaligned()349 @Override public Iterable<BitStream> encodePerUnaligned() { 350 return super.encodePerUnaligned(); 351 } 352 encodePerAligned()353 @Override public Iterable<BitStream> encodePerAligned() { 354 return super.encodePerAligned(); 355 } 356 decodePerUnaligned(BitStreamReader reader)357 @Override public void decodePerUnaligned(BitStreamReader reader) { 358 super.decodePerUnaligned(reader); 359 } 360 decodePerAligned(BitStreamReader reader)361 @Override public void decodePerAligned(BitStreamReader reader) { 362 super.decodePerAligned(reader); 363 } 364 toString()365 @Override public String toString() { 366 return toIndentedString(""); 367 } 368 toIndentedString(String indent)369 public String toIndentedString(String indent) { 370 return "timestampType = [ " + toHumanReadableString() + " ];\n"; 371 } 372 373 } 374 375 376 377 378 379 380 381 382 encodePerUnaligned()383 @Override public Iterable<BitStream> encodePerUnaligned() { 384 return super.encodePerUnaligned(); 385 } 386 encodePerAligned()387 @Override public Iterable<BitStream> encodePerAligned() { 388 return super.encodePerAligned(); 389 } 390 decodePerUnaligned(BitStreamReader reader)391 @Override public void decodePerUnaligned(BitStreamReader reader) { 392 super.decodePerUnaligned(reader); 393 } 394 decodePerAligned(BitStreamReader reader)395 @Override public void decodePerAligned(BitStreamReader reader) { 396 super.decodePerAligned(reader); 397 } 398 toString()399 @Override public String toString() { 400 return toIndentedString(""); 401 } 402 toIndentedString(String indent)403 public String toIndentedString(String indent) { 404 StringBuilder builder = new StringBuilder(); 405 builder.append("Position = {\n"); 406 final String internalIndent = indent + " "; 407 for (SequenceComponent component : getComponents()) { 408 if (component.isExplicitlySet()) { 409 builder.append(internalIndent) 410 .append(component.toIndentedString(internalIndent)); 411 } 412 } 413 if (isExtensible()) { 414 builder.append(internalIndent).append("...\n"); 415 for (SequenceComponent component : getExtensionComponents()) { 416 if (component.isExplicitlySet()) { 417 builder.append(internalIndent) 418 .append(component.toIndentedString(internalIndent)); 419 } 420 } 421 } 422 builder.append(indent).append("};\n"); 423 return builder.toString(); 424 } 425 } 426