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.Asn1Integer;
26 import android.location.cts.asn1.base.Asn1Null;
27 import android.location.cts.asn1.base.Asn1Object;
28 import android.location.cts.asn1.base.Asn1Sequence;
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.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 SetSessionID extends Asn1Sequence {
41   //
42 
43   private static final Asn1Tag TAG_SetSessionID
44       = Asn1Tag.fromClassAndNumber(-1, -1);
45 
SetSessionID()46   public SetSessionID() {
47     super();
48   }
49 
50   @Override
51   @Nullable
getTag()52   protected Asn1Tag getTag() {
53     return TAG_SetSessionID;
54   }
55 
56   @Override
isTagImplicit()57   protected boolean isTagImplicit() {
58     return true;
59   }
60 
getPossibleFirstTags()61   public static Collection<Asn1Tag> getPossibleFirstTags() {
62     if (TAG_SetSessionID != null) {
63       return ImmutableList.of(TAG_SetSessionID);
64     } else {
65       return Asn1Sequence.getPossibleFirstTags();
66     }
67   }
68 
69   /**
70    * Creates a new SetSessionID from encoded stream.
71    */
fromPerUnaligned(byte[] encodedBytes)72   public static SetSessionID fromPerUnaligned(byte[] encodedBytes) {
73     SetSessionID result = new SetSessionID();
74     result.decodePerUnaligned(new BitStreamReader(encodedBytes));
75     return result;
76   }
77 
78   /**
79    * Creates a new SetSessionID from encoded stream.
80    */
fromPerAligned(byte[] encodedBytes)81   public static SetSessionID fromPerAligned(byte[] encodedBytes) {
82     SetSessionID result = new SetSessionID();
83     result.decodePerAligned(new BitStreamReader(encodedBytes));
84     return result;
85   }
86 
87 
88 
isExtensible()89   @Override protected boolean isExtensible() {
90     return false;
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 SetSessionID.sessionIdType sessionId_;
getSessionId()102   public SetSessionID.sessionIdType getSessionId() {
103     return sessionId_;
104   }
105   /**
106    * @throws ClassCastException if value is not a SetSessionID.sessionIdType
107    */
setSessionId(Asn1Object value)108   public void setSessionId(Asn1Object value) {
109     this.sessionId_ = (SetSessionID.sessionIdType) value;
110   }
setSessionIdToNewInstance()111   public SetSessionID.sessionIdType setSessionIdToNewInstance() {
112     sessionId_ = new SetSessionID.sessionIdType();
113     return sessionId_;
114   }
115 
116   private SETId setId_;
getSetId()117   public SETId getSetId() {
118     return setId_;
119   }
120   /**
121    * @throws ClassCastException if value is not a SETId
122    */
setSetId(Asn1Object value)123   public void setSetId(Asn1Object value) {
124     this.setId_ = (SETId) value;
125   }
setSetIdToNewInstance()126   public SETId setSetIdToNewInstance() {
127     setId_ = new SETId();
128     return setId_;
129   }
130 
131 
132 
133 
134 
135 
getComponents()136   @Override public Iterable<? extends SequenceComponent> getComponents() {
137     ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder();
138 
139     builder.add(new SequenceComponent() {
140           Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 0);
141 
142           @Override public boolean isExplicitlySet() {
143             return getSessionId() != null;
144           }
145 
146           @Override public boolean hasDefaultValue() {
147             return false;
148           }
149 
150           @Override public boolean isOptional() {
151             return false;
152           }
153 
154           @Override public Asn1Object getComponentValue() {
155             return getSessionId();
156           }
157 
158           @Override public void setToNewInstance() {
159             setSessionIdToNewInstance();
160           }
161 
162           @Override public Collection<Asn1Tag> getPossibleFirstTags() {
163             return tag == null ? SetSessionID.sessionIdType.getPossibleFirstTags() : ImmutableList.of(tag);
164           }
165 
166           @Override
167           public Asn1Tag getTag() {
168             return tag;
169           }
170 
171           @Override
172           public boolean isImplicitTagging() {
173             return true;
174           }
175 
176           @Override public String toIndentedString(String indent) {
177                 return "sessionId : "
178                     + getSessionId().toIndentedString(indent);
179               }
180         });
181 
182     builder.add(new SequenceComponent() {
183           Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 1);
184 
185           @Override public boolean isExplicitlySet() {
186             return getSetId() != null;
187           }
188 
189           @Override public boolean hasDefaultValue() {
190             return false;
191           }
192 
193           @Override public boolean isOptional() {
194             return false;
195           }
196 
197           @Override public Asn1Object getComponentValue() {
198             return getSetId();
199           }
200 
201           @Override public void setToNewInstance() {
202             setSetIdToNewInstance();
203           }
204 
205           @Override public Collection<Asn1Tag> getPossibleFirstTags() {
206             return tag == null ? SETId.getPossibleFirstTags() : ImmutableList.of(tag);
207           }
208 
209           @Override
210           public Asn1Tag getTag() {
211             return tag;
212           }
213 
214           @Override
215           public boolean isImplicitTagging() {
216             return true;
217           }
218 
219           @Override public String toIndentedString(String indent) {
220                 return "setId : "
221                     + getSetId().toIndentedString(indent);
222               }
223         });
224 
225     return builder.build();
226   }
227 
228   @Override public Iterable<? extends SequenceComponent>
getExtensionComponents()229                                                     getExtensionComponents() {
230     ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder();
231 
232       return builder.build();
233     }
234 
235 
236 /*
237  */
238 
239 
240 //
241 
242 /**
243  */
244 public static class sessionIdType extends Asn1Integer {
245   //
246 
247   private static final Asn1Tag TAG_sessionIdType
248       = Asn1Tag.fromClassAndNumber(-1, -1);
249 
sessionIdType()250   public sessionIdType() {
251     super();
252     setValueRange("0", "65535");
253 
254   }
255 
256   @Override
257   @Nullable
getTag()258   protected Asn1Tag getTag() {
259     return TAG_sessionIdType;
260   }
261 
262   @Override
isTagImplicit()263   protected boolean isTagImplicit() {
264     return true;
265   }
266 
getPossibleFirstTags()267   public static Collection<Asn1Tag> getPossibleFirstTags() {
268     if (TAG_sessionIdType != null) {
269       return ImmutableList.of(TAG_sessionIdType);
270     } else {
271       return Asn1Integer.getPossibleFirstTags();
272     }
273   }
274 
275   /**
276    * Creates a new sessionIdType from encoded stream.
277    */
fromPerUnaligned(byte[] encodedBytes)278   public static sessionIdType fromPerUnaligned(byte[] encodedBytes) {
279     sessionIdType result = new sessionIdType();
280     result.decodePerUnaligned(new BitStreamReader(encodedBytes));
281     return result;
282   }
283 
284   /**
285    * Creates a new sessionIdType from encoded stream.
286    */
fromPerAligned(byte[] encodedBytes)287   public static sessionIdType fromPerAligned(byte[] encodedBytes) {
288     sessionIdType result = new sessionIdType();
289     result.decodePerAligned(new BitStreamReader(encodedBytes));
290     return result;
291   }
292 
encodePerUnaligned()293   @Override public Iterable<BitStream> encodePerUnaligned() {
294     return super.encodePerUnaligned();
295   }
296 
encodePerAligned()297   @Override public Iterable<BitStream> encodePerAligned() {
298     return super.encodePerAligned();
299   }
300 
decodePerUnaligned(BitStreamReader reader)301   @Override public void decodePerUnaligned(BitStreamReader reader) {
302     super.decodePerUnaligned(reader);
303   }
304 
decodePerAligned(BitStreamReader reader)305   @Override public void decodePerAligned(BitStreamReader reader) {
306     super.decodePerAligned(reader);
307   }
308 
toString()309   @Override public String toString() {
310     return toIndentedString("");
311   }
312 
toIndentedString(String indent)313   public String toIndentedString(String indent) {
314     return "sessionIdType = " + getInteger() + ";\n";
315   }
316 }
317 
318 
319 
320 
321 
322 
323 
encodePerUnaligned()324   @Override public Iterable<BitStream> encodePerUnaligned() {
325     return super.encodePerUnaligned();
326   }
327 
encodePerAligned()328   @Override public Iterable<BitStream> encodePerAligned() {
329     return super.encodePerAligned();
330   }
331 
decodePerUnaligned(BitStreamReader reader)332   @Override public void decodePerUnaligned(BitStreamReader reader) {
333     super.decodePerUnaligned(reader);
334   }
335 
decodePerAligned(BitStreamReader reader)336   @Override public void decodePerAligned(BitStreamReader reader) {
337     super.decodePerAligned(reader);
338   }
339 
toString()340   @Override public String toString() {
341     return toIndentedString("");
342   }
343 
toIndentedString(String indent)344   public String toIndentedString(String indent) {
345     StringBuilder builder = new StringBuilder();
346     builder.append("SetSessionID = {\n");
347     final String internalIndent = indent + "  ";
348     for (SequenceComponent component : getComponents()) {
349       if (component.isExplicitlySet()) {
350         builder.append(internalIndent)
351             .append(component.toIndentedString(internalIndent));
352       }
353     }
354     if (isExtensible()) {
355       builder.append(internalIndent).append("...\n");
356       for (SequenceComponent component : getExtensionComponents()) {
357         if (component.isExplicitlySet()) {
358           builder.append(internalIndent)
359               .append(component.toIndentedString(internalIndent));
360         }
361       }
362     }
363     builder.append(indent).append("};\n");
364     return builder.toString();
365   }
366 }
367