Home | History | Annotate | Download | only in rrlp_components
      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.rrlp_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 GANSSAuxiliaryInformation extends Asn1Choice {
     43   //
     44 
     45   private static final Asn1Tag TAG_GANSSAuxiliaryInformation
     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             "GANSSAuxiliaryInformation: " + tag + " maps to both " + select0 + " and " + select);
     61         }
     62       }
     63     }
     64   }
     65 
     66   public GANSSAuxiliaryInformation() {
     67     super();
     68   }
     69 
     70   @Override
     71   @Nullable
     72   protected Asn1Tag getTag() {
     73     return TAG_GANSSAuxiliaryInformation;
     74   }
     75 
     76   @Override
     77   protected boolean isTagImplicit() {
     78     return true;
     79   }
     80 
     81   public static Collection<Asn1Tag> getPossibleFirstTags() {
     82     if (TAG_GANSSAuxiliaryInformation != null) {
     83       return ImmutableList.of(TAG_GANSSAuxiliaryInformation);
     84     } else {
     85       return tagToSelection.keySet();
     86     }
     87   }
     88 
     89   /**
     90    * Creates a new GANSSAuxiliaryInformation from encoded stream.
     91    */
     92   public static GANSSAuxiliaryInformation fromPerUnaligned(byte[] encodedBytes) {
     93     GANSSAuxiliaryInformation result = new GANSSAuxiliaryInformation();
     94     result.decodePerUnaligned(new BitStreamReader(encodedBytes));
     95     return result;
     96   }
     97 
     98   /**
     99    * Creates a new GANSSAuxiliaryInformation from encoded stream.
    100    */
    101   public static GANSSAuxiliaryInformation fromPerAligned(byte[] encodedBytes) {
    102     GANSSAuxiliaryInformation result = new GANSSAuxiliaryInformation();
    103     result.decodePerAligned(new BitStreamReader(encodedBytes));
    104     return result;
    105   }
    106 
    107 
    108 
    109   @Override protected boolean hasExtensionValue() {
    110     return extension;
    111   }
    112 
    113   @Override protected Integer getSelectionOrdinal() {
    114     return selection.ordinal();
    115   }
    116 
    117   @Nullable
    118   @Override
    119   protected ChoiceComponent getSelectedComponent() {
    120     return selection;
    121   }
    122 
    123   @Override protected int getOptionCount() {
    124     if (hasExtensionValue()) {
    125       return Extend.values().length;
    126     }
    127     return Select.values().length;
    128   }
    129 
    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 
    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 
    153   @Override protected boolean isExtensible() {
    154     return true;
    155   }
    156 
    157   @Override protected Asn1Object getValue() {
    158     return element;
    159   }
    160 
    161 
    162   private static enum Select implements ChoiceComponent {
    163 
    164     $GanssID1(Asn1Tag.fromClassAndNumber(2, 0),
    165         true) {
    166       @Override
    167       public Asn1Object createElement() {
    168         return new GANSS_ID1();
    169       }
    170 
    171       @Override
    172       Collection<Asn1Tag> getPossibleFirstTags() {
    173         return tag == null ? GANSS_ID1.getPossibleFirstTags() : ImmutableList.of(tag);
    174       }
    175 
    176       @Override
    177       String elementIndentedString(Asn1Object element, String indent) {
    178         return toString() + " : " + element.toIndentedString(indent);
    179       }
    180     },
    181 
    182     $GanssID3(Asn1Tag.fromClassAndNumber(2, 1),
    183         true) {
    184       @Override
    185       public Asn1Object createElement() {
    186         return new GANSS_ID3();
    187       }
    188 
    189       @Override
    190       Collection<Asn1Tag> getPossibleFirstTags() {
    191         return tag == null ? GANSS_ID3.getPossibleFirstTags() : ImmutableList.of(tag);
    192       }
    193 
    194       @Override
    195       String elementIndentedString(Asn1Object element, String indent) {
    196         return toString() + " : " + element.toIndentedString(indent);
    197       }
    198     },
    199 
    200     ;
    201 
    202     @Nullable final Asn1Tag tag;
    203     final boolean isImplicitTagging;
    204 
    205     Select(@Nullable Asn1Tag tag, boolean isImplicitTagging) {
    206       this.tag = tag;
    207       this.isImplicitTagging = isImplicitTagging;
    208     }
    209 
    210     @Override
    211     public Asn1Object createElement() {
    212       throw new IllegalStateException("Select template error");
    213     }
    214 
    215     @Override
    216     @Nullable
    217     public Asn1Tag getTag() {
    218       return tag;
    219     }
    220 
    221     @Override
    222     public boolean isImplicitTagging() {
    223       return isImplicitTagging;
    224     }
    225 
    226     abstract Collection<Asn1Tag> getPossibleFirstTags();
    227 
    228     abstract String elementIndentedString(Asn1Object element, String indent);
    229   }
    230 
    231 
    232 
    233   public boolean isGanssID1() {
    234     return !hasExtensionValue() && Select.$GanssID1 == selection;
    235   }
    236 
    237   /**
    238    * @throws {@code IllegalStateException} if {@code !isGanssID1}.
    239    */
    240   @SuppressWarnings("unchecked")
    241   public GANSS_ID1 getGanssID1() {
    242     if (!isGanssID1()) {
    243       throw new IllegalStateException("GANSSAuxiliaryInformation value not a GanssID1");
    244     }
    245     return (GANSS_ID1) element;
    246   }
    247 
    248   public void setGanssID1(GANSS_ID1 selected) {
    249     selection = Select.$GanssID1;
    250     extension = false;
    251     element = selected;
    252   }
    253 
    254   public GANSS_ID1 setGanssID1ToNewInstance() {
    255       GANSS_ID1 element = new GANSS_ID1();
    256       setGanssID1(element);
    257       return element;
    258   }
    259 
    260 
    261 
    262   public boolean isGanssID3() {
    263     return !hasExtensionValue() && Select.$GanssID3 == selection;
    264   }
    265 
    266   /**
    267    * @throws {@code IllegalStateException} if {@code !isGanssID3}.
    268    */
    269   @SuppressWarnings("unchecked")
    270   public GANSS_ID3 getGanssID3() {
    271     if (!isGanssID3()) {
    272       throw new IllegalStateException("GANSSAuxiliaryInformation value not a GanssID3");
    273     }
    274     return (GANSS_ID3) element;
    275   }
    276 
    277   public void setGanssID3(GANSS_ID3 selected) {
    278     selection = Select.$GanssID3;
    279     extension = false;
    280     element = selected;
    281   }
    282 
    283   public GANSS_ID3 setGanssID3ToNewInstance() {
    284       GANSS_ID3 element = new GANSS_ID3();
    285       setGanssID3(element);
    286       return element;
    287   }
    288 
    289 
    290   private static enum Extend implements ChoiceComponent {
    291 
    292     ;
    293     @Nullable private final Asn1Tag tag;
    294     private final boolean isImplicitTagging;
    295 
    296     Extend(@Nullable Asn1Tag tag, boolean isImplicitTagging) {
    297       this.tag = tag;
    298       this.isImplicitTagging = isImplicitTagging;
    299     }
    300 
    301     public Asn1Object createElement() {
    302       throw new IllegalStateException("Extend template error");
    303     }
    304 
    305     @Override
    306     @Nullable
    307     public Asn1Tag getTag() {
    308       return tag;
    309     }
    310 
    311     @Override
    312     public boolean isImplicitTagging() {
    313       return isImplicitTagging;
    314     }
    315 
    316     String elementIndentedString(Asn1Object element, String indent) {
    317       throw new IllegalStateException("Extend template error");
    318     }
    319   }
    320 
    321 
    322   @Override public Iterable<BitStream> encodePerUnaligned() {
    323     return super.encodePerUnaligned();
    324   }
    325 
    326   @Override public Iterable<BitStream> encodePerAligned() {
    327     return super.encodePerAligned();
    328   }
    329 
    330   @Override public void decodePerUnaligned(BitStreamReader reader) {
    331     super.decodePerUnaligned(reader);
    332   }
    333 
    334   @Override public void decodePerAligned(BitStreamReader reader) {
    335     super.decodePerAligned(reader);
    336   }
    337 
    338   @Override public String toString() {
    339     return toIndentedString("");
    340   }
    341 
    342   private String elementIndentedString(String indent) {
    343     if (element == null) {
    344       return "null;\n";
    345     }
    346     if (extension) {
    347       return Extend.values()[selection.ordinal()]
    348           .elementIndentedString(element, indent + "  ");
    349     } else {
    350       return Select.values()[selection.ordinal()]
    351           .elementIndentedString(element, indent + "  ");
    352     }
    353   }
    354 
    355   public String toIndentedString(String indent) {
    356     return "GANSSAuxiliaryInformation = " + elementIndentedString(indent) + indent + ";\n";
    357   }
    358 }
    359