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_triggered_response; 18 19 /* 20 */ 21 22 23 // 24 // 25 import android.location.cts.asn1.base.Asn1Choice; 26 import android.location.cts.asn1.base.Asn1Integer; 27 import android.location.cts.asn1.base.Asn1Null; 28 import android.location.cts.asn1.base.Asn1Object; 29 import android.location.cts.asn1.base.Asn1Tag; 30 import android.location.cts.asn1.base.BitStream; 31 import android.location.cts.asn1.base.BitStreamReader; 32 import android.location.cts.asn1.base.ChoiceComponent; 33 import com.google.common.collect.ImmutableList; 34 import java.nio.ByteBuffer; 35 import java.util.Collection; 36 import java.util.HashMap; 37 import java.util.Map; 38 import javax.annotation.Nullable; 39 40 41 /** 42 */ 43 public class BatchRepConditions extends Asn1Choice { 44 // 45 46 private static final Asn1Tag TAG_BatchRepConditions 47 = Asn1Tag.fromClassAndNumber(-1, -1); 48 49 private static final Map<Asn1Tag, Select> tagToSelection = new HashMap<>(); 50 51 private boolean extension; 52 private ChoiceComponent selection; 53 private Asn1Object element; 54 55 static { 56 for (Select select : Select.values()) { 57 for (Asn1Tag tag : select.getPossibleFirstTags()) { 58 Select select0; 59 if ((select0 = tagToSelection.put(tag, select)) != null) { 60 throw new IllegalStateException( 61 "BatchRepConditions: " + tag + " maps to both " + select0 + " and " + select); 62 } 63 } 64 } 65 } 66 67 public BatchRepConditions() { 68 super(); 69 } 70 71 @Override 72 @Nullable 73 protected Asn1Tag getTag() { 74 return TAG_BatchRepConditions; 75 } 76 77 @Override 78 protected boolean isTagImplicit() { 79 return true; 80 } 81 82 public static Collection<Asn1Tag> getPossibleFirstTags() { 83 if (TAG_BatchRepConditions != null) { 84 return ImmutableList.of(TAG_BatchRepConditions); 85 } else { 86 return tagToSelection.keySet(); 87 } 88 } 89 90 /** 91 * Creates a new BatchRepConditions from encoded stream. 92 */ 93 public static BatchRepConditions fromPerUnaligned(byte[] encodedBytes) { 94 BatchRepConditions result = new BatchRepConditions(); 95 result.decodePerUnaligned(new BitStreamReader(encodedBytes)); 96 return result; 97 } 98 99 /** 100 * Creates a new BatchRepConditions from encoded stream. 101 */ 102 public static BatchRepConditions fromPerAligned(byte[] encodedBytes) { 103 BatchRepConditions result = new BatchRepConditions(); 104 result.decodePerAligned(new BitStreamReader(encodedBytes)); 105 return result; 106 } 107 108 109 110 @Override protected boolean hasExtensionValue() { 111 return extension; 112 } 113 114 @Override protected Integer getSelectionOrdinal() { 115 return selection.ordinal(); 116 } 117 118 @Nullable 119 @Override 120 protected ChoiceComponent getSelectedComponent() { 121 return selection; 122 } 123 124 @Override protected int getOptionCount() { 125 if (hasExtensionValue()) { 126 return Extend.values().length; 127 } 128 return Select.values().length; 129 } 130 131 protected Asn1Object createAndSetValue(boolean isExtensionValue, 132 int ordinal) { 133 extension = isExtensionValue; 134 if (isExtensionValue) { 135 selection = Extend.values()[ordinal]; 136 } else { 137 selection = Select.values()[ordinal]; 138 } 139 element = selection.createElement(); 140 return element; 141 } 142 143 @Override protected ChoiceComponent createAndSetValue(Asn1Tag tag) { 144 Select select = tagToSelection.get(tag); 145 if (select == null) { 146 throw new IllegalArgumentException("Unknown selection tag: " + tag); 147 } 148 element = select.createElement(); 149 selection = select; 150 extension = false; 151 return select; 152 } 153 154 @Override protected boolean isExtensible() { 155 return true; 156 } 157 158 @Override protected Asn1Object getValue() { 159 return element; 160 } 161 162 163 private static enum Select implements ChoiceComponent { 164 165 $Num_interval(Asn1Tag.fromClassAndNumber(2, 0), 166 true) { 167 @Override 168 public Asn1Object createElement() { 169 return new BatchRepConditions.num_intervalType(); 170 } 171 172 @Override 173 Collection<Asn1Tag> getPossibleFirstTags() { 174 return tag == null ? BatchRepConditions.num_intervalType.getPossibleFirstTags() : ImmutableList.of(tag); 175 } 176 177 @Override 178 String elementIndentedString(Asn1Object element, String indent) { 179 return toString() + " : " + element.toIndentedString(indent); 180 } 181 }, 182 183 $Num_minutes(Asn1Tag.fromClassAndNumber(2, 1), 184 true) { 185 @Override 186 public Asn1Object createElement() { 187 return new BatchRepConditions.num_minutesType(); 188 } 189 190 @Override 191 Collection<Asn1Tag> getPossibleFirstTags() { 192 return tag == null ? BatchRepConditions.num_minutesType.getPossibleFirstTags() : ImmutableList.of(tag); 193 } 194 195 @Override 196 String elementIndentedString(Asn1Object element, String indent) { 197 return toString() + " : " + element.toIndentedString(indent); 198 } 199 }, 200 201 $Endofsession(Asn1Tag.fromClassAndNumber(2, 2), 202 true) { 203 @Override 204 public Asn1Object createElement() { 205 return new BatchRepConditions.endofsessionType(); 206 } 207 208 @Override 209 Collection<Asn1Tag> getPossibleFirstTags() { 210 return tag == null ? BatchRepConditions.endofsessionType.getPossibleFirstTags() : ImmutableList.of(tag); 211 } 212 213 @Override 214 String elementIndentedString(Asn1Object element, String indent) { 215 return toString() + " : " + element.toIndentedString(indent); 216 } 217 }, 218 219 ; 220 221 @Nullable final Asn1Tag tag; 222 final boolean isImplicitTagging; 223 224 Select(@Nullable Asn1Tag tag, boolean isImplicitTagging) { 225 this.tag = tag; 226 this.isImplicitTagging = isImplicitTagging; 227 } 228 229 @Override 230 public Asn1Object createElement() { 231 throw new IllegalStateException("Select template error"); 232 } 233 234 @Override 235 @Nullable 236 public Asn1Tag getTag() { 237 return tag; 238 } 239 240 @Override 241 public boolean isImplicitTagging() { 242 return isImplicitTagging; 243 } 244 245 abstract Collection<Asn1Tag> getPossibleFirstTags(); 246 247 abstract String elementIndentedString(Asn1Object element, String indent); 248 } 249 250 /* 251 */ 252 253 254 // 255 256 /** 257 */ 258 public static class num_intervalType extends Asn1Integer { 259 // 260 261 private static final Asn1Tag TAG_num_intervalType 262 = Asn1Tag.fromClassAndNumber(-1, -1); 263 264 public num_intervalType() { 265 super(); 266 setValueRange("1", "1024"); 267 268 } 269 270 @Override 271 @Nullable 272 protected Asn1Tag getTag() { 273 return TAG_num_intervalType; 274 } 275 276 @Override 277 protected boolean isTagImplicit() { 278 return true; 279 } 280 281 public static Collection<Asn1Tag> getPossibleFirstTags() { 282 if (TAG_num_intervalType != null) { 283 return ImmutableList.of(TAG_num_intervalType); 284 } else { 285 return Asn1Integer.getPossibleFirstTags(); 286 } 287 } 288 289 /** 290 * Creates a new num_intervalType from encoded stream. 291 */ 292 public static num_intervalType fromPerUnaligned(byte[] encodedBytes) { 293 num_intervalType result = new num_intervalType(); 294 result.decodePerUnaligned(new BitStreamReader(encodedBytes)); 295 return result; 296 } 297 298 /** 299 * Creates a new num_intervalType from encoded stream. 300 */ 301 public static num_intervalType fromPerAligned(byte[] encodedBytes) { 302 num_intervalType result = new num_intervalType(); 303 result.decodePerAligned(new BitStreamReader(encodedBytes)); 304 return result; 305 } 306 307 @Override public Iterable<BitStream> encodePerUnaligned() { 308 return super.encodePerUnaligned(); 309 } 310 311 @Override public Iterable<BitStream> encodePerAligned() { 312 return super.encodePerAligned(); 313 } 314 315 @Override public void decodePerUnaligned(BitStreamReader reader) { 316 super.decodePerUnaligned(reader); 317 } 318 319 @Override public void decodePerAligned(BitStreamReader reader) { 320 super.decodePerAligned(reader); 321 } 322 323 @Override public String toString() { 324 return toIndentedString(""); 325 } 326 327 public String toIndentedString(String indent) { 328 return "num_intervalType = " + getInteger() + ";\n"; 329 } 330 } 331 332 333 public boolean isNum_interval() { 334 return !hasExtensionValue() && Select.$Num_interval == selection; 335 } 336 337 /** 338 * @throws {@code IllegalStateException} if {@code !isNum_interval}. 339 */ 340 @SuppressWarnings("unchecked") 341 public BatchRepConditions.num_intervalType getNum_interval() { 342 if (!isNum_interval()) { 343 throw new IllegalStateException("BatchRepConditions value not a Num_interval"); 344 } 345 return (BatchRepConditions.num_intervalType) element; 346 } 347 348 public void setNum_interval(BatchRepConditions.num_intervalType selected) { 349 selection = Select.$Num_interval; 350 extension = false; 351 element = selected; 352 } 353 354 public BatchRepConditions.num_intervalType setNum_intervalToNewInstance() { 355 BatchRepConditions.num_intervalType element = new BatchRepConditions.num_intervalType(); 356 setNum_interval(element); 357 return element; 358 } 359 360 /* 361 */ 362 363 364 // 365 366 /** 367 */ 368 public static class num_minutesType extends Asn1Integer { 369 // 370 371 private static final Asn1Tag TAG_num_minutesType 372 = Asn1Tag.fromClassAndNumber(-1, -1); 373 374 public num_minutesType() { 375 super(); 376 setValueRange("1", "2048"); 377 378 } 379 380 @Override 381 @Nullable 382 protected Asn1Tag getTag() { 383 return TAG_num_minutesType; 384 } 385 386 @Override 387 protected boolean isTagImplicit() { 388 return true; 389 } 390 391 public static Collection<Asn1Tag> getPossibleFirstTags() { 392 if (TAG_num_minutesType != null) { 393 return ImmutableList.of(TAG_num_minutesType); 394 } else { 395 return Asn1Integer.getPossibleFirstTags(); 396 } 397 } 398 399 /** 400 * Creates a new num_minutesType from encoded stream. 401 */ 402 public static num_minutesType fromPerUnaligned(byte[] encodedBytes) { 403 num_minutesType result = new num_minutesType(); 404 result.decodePerUnaligned(new BitStreamReader(encodedBytes)); 405 return result; 406 } 407 408 /** 409 * Creates a new num_minutesType from encoded stream. 410 */ 411 public static num_minutesType fromPerAligned(byte[] encodedBytes) { 412 num_minutesType result = new num_minutesType(); 413 result.decodePerAligned(new BitStreamReader(encodedBytes)); 414 return result; 415 } 416 417 @Override public Iterable<BitStream> encodePerUnaligned() { 418 return super.encodePerUnaligned(); 419 } 420 421 @Override public Iterable<BitStream> encodePerAligned() { 422 return super.encodePerAligned(); 423 } 424 425 @Override public void decodePerUnaligned(BitStreamReader reader) { 426 super.decodePerUnaligned(reader); 427 } 428 429 @Override public void decodePerAligned(BitStreamReader reader) { 430 super.decodePerAligned(reader); 431 } 432 433 @Override public String toString() { 434 return toIndentedString(""); 435 } 436 437 public String toIndentedString(String indent) { 438 return "num_minutesType = " + getInteger() + ";\n"; 439 } 440 } 441 442 443 public boolean isNum_minutes() { 444 return !hasExtensionValue() && Select.$Num_minutes == selection; 445 } 446 447 /** 448 * @throws {@code IllegalStateException} if {@code !isNum_minutes}. 449 */ 450 @SuppressWarnings("unchecked") 451 public BatchRepConditions.num_minutesType getNum_minutes() { 452 if (!isNum_minutes()) { 453 throw new IllegalStateException("BatchRepConditions value not a Num_minutes"); 454 } 455 return (BatchRepConditions.num_minutesType) element; 456 } 457 458 public void setNum_minutes(BatchRepConditions.num_minutesType selected) { 459 selection = Select.$Num_minutes; 460 extension = false; 461 element = selected; 462 } 463 464 public BatchRepConditions.num_minutesType setNum_minutesToNewInstance() { 465 BatchRepConditions.num_minutesType element = new BatchRepConditions.num_minutesType(); 466 setNum_minutes(element); 467 return element; 468 } 469 470 /* 471 */ 472 473 474 // 475 476 /** 477 */ 478 public static class endofsessionType extends Asn1Null { 479 // 480 481 private static final Asn1Tag TAG_endofsessionType 482 = Asn1Tag.fromClassAndNumber(-1, -1); 483 484 public endofsessionType() { 485 super(); 486 } 487 488 @Override 489 @Nullable 490 protected Asn1Tag getTag() { 491 return TAG_endofsessionType; 492 } 493 494 @Override 495 protected boolean isTagImplicit() { 496 return true; 497 } 498 499 public static Collection<Asn1Tag> getPossibleFirstTags() { 500 if (TAG_endofsessionType != null) { 501 return ImmutableList.of(TAG_endofsessionType); 502 } else { 503 return Asn1Null.getPossibleFirstTags(); 504 } 505 } 506 507 /** 508 * Creates a new endofsessionType from encoded stream. 509 */ 510 public static endofsessionType fromPerUnaligned(byte[] encodedBytes) { 511 endofsessionType result = new endofsessionType(); 512 result.decodePerUnaligned(new BitStreamReader(encodedBytes)); 513 return result; 514 } 515 516 /** 517 * Creates a new endofsessionType from encoded stream. 518 */ 519 public static endofsessionType fromPerAligned(byte[] encodedBytes) { 520 endofsessionType result = new endofsessionType(); 521 result.decodePerAligned(new BitStreamReader(encodedBytes)); 522 return result; 523 } 524 525 @Override public Iterable<BitStream> encodePerUnaligned() { 526 return super.encodePerUnaligned(); 527 } 528 529 @Override public Iterable<BitStream> encodePerAligned() { 530 return super.encodePerAligned(); 531 } 532 533 @Override public void decodePerUnaligned(BitStreamReader reader) { 534 super.decodePerUnaligned(reader); 535 } 536 537 @Override public void decodePerAligned(BitStreamReader reader) { 538 super.decodePerAligned(reader); 539 } 540 541 @Override public String toString() { 542 return toIndentedString(""); 543 } 544 545 public String toIndentedString(String indent) { 546 return "endofsessionType (null value);\n"; 547 } 548 } 549 550 551 public boolean isEndofsession() { 552 return !hasExtensionValue() && Select.$Endofsession == selection; 553 } 554 555 /** 556 * @throws {@code IllegalStateException} if {@code !isEndofsession}. 557 */ 558 @SuppressWarnings("unchecked") 559 public BatchRepConditions.endofsessionType getEndofsession() { 560 if (!isEndofsession()) { 561 throw new IllegalStateException("BatchRepConditions value not a Endofsession"); 562 } 563 return (BatchRepConditions.endofsessionType) element; 564 } 565 566 public void setEndofsession(BatchRepConditions.endofsessionType selected) { 567 selection = Select.$Endofsession; 568 extension = false; 569 element = selected; 570 } 571 572 public BatchRepConditions.endofsessionType setEndofsessionToNewInstance() { 573 BatchRepConditions.endofsessionType element = new BatchRepConditions.endofsessionType(); 574 setEndofsession(element); 575 return element; 576 } 577 578 579 private static enum Extend implements ChoiceComponent { 580 581 ; 582 @Nullable private final Asn1Tag tag; 583 private final boolean isImplicitTagging; 584 585 Extend(@Nullable Asn1Tag tag, boolean isImplicitTagging) { 586 this.tag = tag; 587 this.isImplicitTagging = isImplicitTagging; 588 } 589 590 public Asn1Object createElement() { 591 throw new IllegalStateException("Extend template error"); 592 } 593 594 @Override 595 @Nullable 596 public Asn1Tag getTag() { 597 return tag; 598 } 599 600 @Override 601 public boolean isImplicitTagging() { 602 return isImplicitTagging; 603 } 604 605 String elementIndentedString(Asn1Object element, String indent) { 606 throw new IllegalStateException("Extend template error"); 607 } 608 } 609 610 611 @Override public Iterable<BitStream> encodePerUnaligned() { 612 return super.encodePerUnaligned(); 613 } 614 615 @Override public Iterable<BitStream> encodePerAligned() { 616 return super.encodePerAligned(); 617 } 618 619 @Override public void decodePerUnaligned(BitStreamReader reader) { 620 super.decodePerUnaligned(reader); 621 } 622 623 @Override public void decodePerAligned(BitStreamReader reader) { 624 super.decodePerAligned(reader); 625 } 626 627 @Override public String toString() { 628 return toIndentedString(""); 629 } 630 631 private String elementIndentedString(String indent) { 632 if (element == null) { 633 return "null;\n"; 634 } 635 if (extension) { 636 return Extend.values()[selection.ordinal()] 637 .elementIndentedString(element, indent + " "); 638 } else { 639 return Select.values()[selection.ordinal()] 640 .elementIndentedString(element, indent + " "); 641 } 642 } 643 644 public String toIndentedString(String indent) { 645 return "BatchRepConditions = " + elementIndentedString(indent) + indent + ";\n"; 646 } 647 } 648