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.ver2_ulp_components; 18 19 /* 20 */ 21 22 23 // 24 // 25 import android.location.cts.asn1.base.Asn1Choice; 26 import android.location.cts.asn1.base.Asn1Null; 27 import android.location.cts.asn1.base.Asn1Object; 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.ChoiceComponent; 32 import com.google.common.collect.ImmutableList; 33 import java.nio.ByteBuffer; 34 import java.util.Collection; 35 import java.util.HashMap; 36 import java.util.Map; 37 import javax.annotation.Nullable; 38 39 40 /** 41 */ 42 public class Ver2_CellInfo_extension extends Asn1Choice { 43 // 44 45 private static final Asn1Tag TAG_Ver2_CellInfo_extension 46 = Asn1Tag.fromClassAndNumber(-1, -1); 47 48 private static final Map<Asn1Tag, Select> tagToSelection = new HashMap<>(); 49 50 private boolean extension; 51 private ChoiceComponent selection; 52 private Asn1Object element; 53 54 static { 55 for (Select select : Select.values()) { 56 for (Asn1Tag tag : select.getPossibleFirstTags()) { 57 Select select0; 58 if ((select0 = tagToSelection.put(tag, select)) != null) { 59 throw new IllegalStateException( 60 "Ver2_CellInfo_extension: " + tag + " maps to both " + select0 + " and " + select); 61 } 62 } 63 } 64 } 65 Ver2_CellInfo_extension()66 public Ver2_CellInfo_extension() { 67 super(); 68 } 69 70 @Override 71 @Nullable getTag()72 protected Asn1Tag getTag() { 73 return TAG_Ver2_CellInfo_extension; 74 } 75 76 @Override isTagImplicit()77 protected boolean isTagImplicit() { 78 return true; 79 } 80 getPossibleFirstTags()81 public static Collection<Asn1Tag> getPossibleFirstTags() { 82 if (TAG_Ver2_CellInfo_extension != null) { 83 return ImmutableList.of(TAG_Ver2_CellInfo_extension); 84 } else { 85 return tagToSelection.keySet(); 86 } 87 } 88 89 /** 90 * Creates a new Ver2_CellInfo_extension from encoded stream. 91 */ fromPerUnaligned(byte[] encodedBytes)92 public static Ver2_CellInfo_extension fromPerUnaligned(byte[] encodedBytes) { 93 Ver2_CellInfo_extension result = new Ver2_CellInfo_extension(); 94 result.decodePerUnaligned(new BitStreamReader(encodedBytes)); 95 return result; 96 } 97 98 /** 99 * Creates a new Ver2_CellInfo_extension from encoded stream. 100 */ fromPerAligned(byte[] encodedBytes)101 public static Ver2_CellInfo_extension fromPerAligned(byte[] encodedBytes) { 102 Ver2_CellInfo_extension result = new Ver2_CellInfo_extension(); 103 result.decodePerAligned(new BitStreamReader(encodedBytes)); 104 return result; 105 } 106 107 108 hasExtensionValue()109 @Override protected boolean hasExtensionValue() { 110 return extension; 111 } 112 getSelectionOrdinal()113 @Override protected Integer getSelectionOrdinal() { 114 return selection.ordinal(); 115 } 116 117 @Nullable 118 @Override getSelectedComponent()119 protected ChoiceComponent getSelectedComponent() { 120 return selection; 121 } 122 getOptionCount()123 @Override protected int getOptionCount() { 124 if (hasExtensionValue()) { 125 return Extend.values().length; 126 } 127 return Select.values().length; 128 } 129 createAndSetValue(boolean isExtensionValue, int ordinal)130 protected Asn1Object createAndSetValue(boolean isExtensionValue, 131 int ordinal) { 132 extension = isExtensionValue; 133 if (isExtensionValue) { 134 selection = Extend.values()[ordinal]; 135 } else { 136 selection = Select.values()[ordinal]; 137 } 138 element = selection.createElement(); 139 return element; 140 } 141 createAndSetValue(Asn1Tag tag)142 @Override protected ChoiceComponent createAndSetValue(Asn1Tag tag) { 143 Select select = tagToSelection.get(tag); 144 if (select == null) { 145 throw new IllegalArgumentException("Unknown selection tag: " + tag); 146 } 147 element = select.createElement(); 148 selection = select; 149 extension = false; 150 return select; 151 } 152 isExtensible()153 @Override protected boolean isExtensible() { 154 return true; 155 } 156 getValue()157 @Override protected Asn1Object getValue() { 158 return element; 159 } 160 161 162 private static enum Select implements ChoiceComponent { 163 164 $HrpdCell(Asn1Tag.fromClassAndNumber(2, 0), 165 true) { 166 @Override createElement()167 public Asn1Object createElement() { 168 return new HrpdCellInformation(); 169 } 170 171 @Override getPossibleFirstTags()172 Collection<Asn1Tag> getPossibleFirstTags() { 173 return tag == null ? HrpdCellInformation.getPossibleFirstTags() : ImmutableList.of(tag); 174 } 175 176 @Override elementIndentedString(Asn1Object element, String indent)177 String elementIndentedString(Asn1Object element, String indent) { 178 return toString() + " : " + element.toIndentedString(indent); 179 } 180 }, 181 182 $UmbCell(Asn1Tag.fromClassAndNumber(2, 1), 183 true) { 184 @Override createElement()185 public Asn1Object createElement() { 186 return new UmbCellInformation(); 187 } 188 189 @Override getPossibleFirstTags()190 Collection<Asn1Tag> getPossibleFirstTags() { 191 return tag == null ? UmbCellInformation.getPossibleFirstTags() : ImmutableList.of(tag); 192 } 193 194 @Override elementIndentedString(Asn1Object element, String indent)195 String elementIndentedString(Asn1Object element, String indent) { 196 return toString() + " : " + element.toIndentedString(indent); 197 } 198 }, 199 200 $LteCell(Asn1Tag.fromClassAndNumber(2, 2), 201 true) { 202 @Override createElement()203 public Asn1Object createElement() { 204 return new LteCellInformation(); 205 } 206 207 @Override getPossibleFirstTags()208 Collection<Asn1Tag> getPossibleFirstTags() { 209 return tag == null ? LteCellInformation.getPossibleFirstTags() : ImmutableList.of(tag); 210 } 211 212 @Override elementIndentedString(Asn1Object element, String indent)213 String elementIndentedString(Asn1Object element, String indent) { 214 return toString() + " : " + element.toIndentedString(indent); 215 } 216 }, 217 218 $WlanAP(Asn1Tag.fromClassAndNumber(2, 3), 219 true) { 220 @Override createElement()221 public Asn1Object createElement() { 222 return new WlanAPInformation(); 223 } 224 225 @Override getPossibleFirstTags()226 Collection<Asn1Tag> getPossibleFirstTags() { 227 return tag == null ? WlanAPInformation.getPossibleFirstTags() : ImmutableList.of(tag); 228 } 229 230 @Override elementIndentedString(Asn1Object element, String indent)231 String elementIndentedString(Asn1Object element, String indent) { 232 return toString() + " : " + element.toIndentedString(indent); 233 } 234 }, 235 236 $WimaxBS(Asn1Tag.fromClassAndNumber(2, 4), 237 true) { 238 @Override createElement()239 public Asn1Object createElement() { 240 return new WimaxBSInformation(); 241 } 242 243 @Override getPossibleFirstTags()244 Collection<Asn1Tag> getPossibleFirstTags() { 245 return tag == null ? WimaxBSInformation.getPossibleFirstTags() : ImmutableList.of(tag); 246 } 247 248 @Override elementIndentedString(Asn1Object element, String indent)249 String elementIndentedString(Asn1Object element, String indent) { 250 return toString() + " : " + element.toIndentedString(indent); 251 } 252 }, 253 254 ; 255 256 @Nullable final Asn1Tag tag; 257 final boolean isImplicitTagging; 258 Select(@ullable Asn1Tag tag, boolean isImplicitTagging)259 Select(@Nullable Asn1Tag tag, boolean isImplicitTagging) { 260 this.tag = tag; 261 this.isImplicitTagging = isImplicitTagging; 262 } 263 264 @Override createElement()265 public Asn1Object createElement() { 266 throw new IllegalStateException("Select template error"); 267 } 268 269 @Override 270 @Nullable getTag()271 public Asn1Tag getTag() { 272 return tag; 273 } 274 275 @Override isImplicitTagging()276 public boolean isImplicitTagging() { 277 return isImplicitTagging; 278 } 279 getPossibleFirstTags()280 abstract Collection<Asn1Tag> getPossibleFirstTags(); 281 elementIndentedString(Asn1Object element, String indent)282 abstract String elementIndentedString(Asn1Object element, String indent); 283 } 284 285 286 isHrpdCell()287 public boolean isHrpdCell() { 288 return !hasExtensionValue() && Select.$HrpdCell == selection; 289 } 290 291 /** 292 * @throws {@code IllegalStateException} if {@code !isHrpdCell}. 293 */ 294 @SuppressWarnings("unchecked") getHrpdCell()295 public HrpdCellInformation getHrpdCell() { 296 if (!isHrpdCell()) { 297 throw new IllegalStateException("Ver2_CellInfo_extension value not a HrpdCell"); 298 } 299 return (HrpdCellInformation) element; 300 } 301 setHrpdCell(HrpdCellInformation selected)302 public void setHrpdCell(HrpdCellInformation selected) { 303 selection = Select.$HrpdCell; 304 extension = false; 305 element = selected; 306 } 307 setHrpdCellToNewInstance()308 public HrpdCellInformation setHrpdCellToNewInstance() { 309 HrpdCellInformation element = new HrpdCellInformation(); 310 setHrpdCell(element); 311 return element; 312 } 313 314 315 isUmbCell()316 public boolean isUmbCell() { 317 return !hasExtensionValue() && Select.$UmbCell == selection; 318 } 319 320 /** 321 * @throws {@code IllegalStateException} if {@code !isUmbCell}. 322 */ 323 @SuppressWarnings("unchecked") getUmbCell()324 public UmbCellInformation getUmbCell() { 325 if (!isUmbCell()) { 326 throw new IllegalStateException("Ver2_CellInfo_extension value not a UmbCell"); 327 } 328 return (UmbCellInformation) element; 329 } 330 setUmbCell(UmbCellInformation selected)331 public void setUmbCell(UmbCellInformation selected) { 332 selection = Select.$UmbCell; 333 extension = false; 334 element = selected; 335 } 336 setUmbCellToNewInstance()337 public UmbCellInformation setUmbCellToNewInstance() { 338 UmbCellInformation element = new UmbCellInformation(); 339 setUmbCell(element); 340 return element; 341 } 342 343 344 isLteCell()345 public boolean isLteCell() { 346 return !hasExtensionValue() && Select.$LteCell == selection; 347 } 348 349 /** 350 * @throws {@code IllegalStateException} if {@code !isLteCell}. 351 */ 352 @SuppressWarnings("unchecked") getLteCell()353 public LteCellInformation getLteCell() { 354 if (!isLteCell()) { 355 throw new IllegalStateException("Ver2_CellInfo_extension value not a LteCell"); 356 } 357 return (LteCellInformation) element; 358 } 359 setLteCell(LteCellInformation selected)360 public void setLteCell(LteCellInformation selected) { 361 selection = Select.$LteCell; 362 extension = false; 363 element = selected; 364 } 365 setLteCellToNewInstance()366 public LteCellInformation setLteCellToNewInstance() { 367 LteCellInformation element = new LteCellInformation(); 368 setLteCell(element); 369 return element; 370 } 371 372 373 isWlanAP()374 public boolean isWlanAP() { 375 return !hasExtensionValue() && Select.$WlanAP == selection; 376 } 377 378 /** 379 * @throws {@code IllegalStateException} if {@code !isWlanAP}. 380 */ 381 @SuppressWarnings("unchecked") getWlanAP()382 public WlanAPInformation getWlanAP() { 383 if (!isWlanAP()) { 384 throw new IllegalStateException("Ver2_CellInfo_extension value not a WlanAP"); 385 } 386 return (WlanAPInformation) element; 387 } 388 setWlanAP(WlanAPInformation selected)389 public void setWlanAP(WlanAPInformation selected) { 390 selection = Select.$WlanAP; 391 extension = false; 392 element = selected; 393 } 394 setWlanAPToNewInstance()395 public WlanAPInformation setWlanAPToNewInstance() { 396 WlanAPInformation element = new WlanAPInformation(); 397 setWlanAP(element); 398 return element; 399 } 400 401 402 isWimaxBS()403 public boolean isWimaxBS() { 404 return !hasExtensionValue() && Select.$WimaxBS == selection; 405 } 406 407 /** 408 * @throws {@code IllegalStateException} if {@code !isWimaxBS}. 409 */ 410 @SuppressWarnings("unchecked") getWimaxBS()411 public WimaxBSInformation getWimaxBS() { 412 if (!isWimaxBS()) { 413 throw new IllegalStateException("Ver2_CellInfo_extension value not a WimaxBS"); 414 } 415 return (WimaxBSInformation) element; 416 } 417 setWimaxBS(WimaxBSInformation selected)418 public void setWimaxBS(WimaxBSInformation selected) { 419 selection = Select.$WimaxBS; 420 extension = false; 421 element = selected; 422 } 423 setWimaxBSToNewInstance()424 public WimaxBSInformation setWimaxBSToNewInstance() { 425 WimaxBSInformation element = new WimaxBSInformation(); 426 setWimaxBS(element); 427 return element; 428 } 429 430 431 private static enum Extend implements ChoiceComponent { 432 433 ; 434 @Nullable private final Asn1Tag tag; 435 private final boolean isImplicitTagging; 436 Extend(@ullable Asn1Tag tag, boolean isImplicitTagging)437 Extend(@Nullable Asn1Tag tag, boolean isImplicitTagging) { 438 this.tag = tag; 439 this.isImplicitTagging = isImplicitTagging; 440 } 441 createElement()442 public Asn1Object createElement() { 443 throw new IllegalStateException("Extend template error"); 444 } 445 446 @Override 447 @Nullable getTag()448 public Asn1Tag getTag() { 449 return tag; 450 } 451 452 @Override isImplicitTagging()453 public boolean isImplicitTagging() { 454 return isImplicitTagging; 455 } 456 elementIndentedString(Asn1Object element, String indent)457 String elementIndentedString(Asn1Object element, String indent) { 458 throw new IllegalStateException("Extend template error"); 459 } 460 } 461 462 encodePerUnaligned()463 @Override public Iterable<BitStream> encodePerUnaligned() { 464 return super.encodePerUnaligned(); 465 } 466 encodePerAligned()467 @Override public Iterable<BitStream> encodePerAligned() { 468 return super.encodePerAligned(); 469 } 470 decodePerUnaligned(BitStreamReader reader)471 @Override public void decodePerUnaligned(BitStreamReader reader) { 472 super.decodePerUnaligned(reader); 473 } 474 decodePerAligned(BitStreamReader reader)475 @Override public void decodePerAligned(BitStreamReader reader) { 476 super.decodePerAligned(reader); 477 } 478 toString()479 @Override public String toString() { 480 return toIndentedString(""); 481 } 482 elementIndentedString(String indent)483 private String elementIndentedString(String indent) { 484 if (element == null) { 485 return "null;\n"; 486 } 487 if (extension) { 488 return Extend.values()[selection.ordinal()] 489 .elementIndentedString(element, indent + " "); 490 } else { 491 return Select.values()[selection.ordinal()] 492 .elementIndentedString(element, indent + " "); 493 } 494 } 495 toIndentedString(String indent)496 public String toIndentedString(String indent) { 497 return "Ver2_CellInfo_extension = " + elementIndentedString(indent) + indent + ";\n"; 498 } 499 } 500