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.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.BitStream;
30 import android.location.cts.asn1.base.BitStreamReader;
31 import android.location.cts.asn1.base.SequenceComponent;
32 import com.google.common.collect.ImmutableList;
33 import java.util.Collection;
34 import javax.annotation.Nullable;
35 
36 
37 /**
38 */
39 public  class AccuracyOpt extends Asn1Sequence {
40   //
41 
42   private static final Asn1Tag TAG_AccuracyOpt
43       = Asn1Tag.fromClassAndNumber(-1, -1);
44 
AccuracyOpt()45   public AccuracyOpt() {
46     super();
47   }
48 
49   @Override
50   @Nullable
getTag()51   protected Asn1Tag getTag() {
52     return TAG_AccuracyOpt;
53   }
54 
55   @Override
isTagImplicit()56   protected boolean isTagImplicit() {
57     return true;
58   }
59 
getPossibleFirstTags()60   public static Collection<Asn1Tag> getPossibleFirstTags() {
61     if (TAG_AccuracyOpt != null) {
62       return ImmutableList.of(TAG_AccuracyOpt);
63     } else {
64       return Asn1Sequence.getPossibleFirstTags();
65     }
66   }
67 
68   /**
69    * Creates a new AccuracyOpt from encoded stream.
70    */
fromPerUnaligned(byte[] encodedBytes)71   public static AccuracyOpt fromPerUnaligned(byte[] encodedBytes) {
72     AccuracyOpt result = new AccuracyOpt();
73     result.decodePerUnaligned(new BitStreamReader(encodedBytes));
74     return result;
75   }
76 
77   /**
78    * Creates a new AccuracyOpt from encoded stream.
79    */
fromPerAligned(byte[] encodedBytes)80   public static AccuracyOpt fromPerAligned(byte[] encodedBytes) {
81     AccuracyOpt result = new AccuracyOpt();
82     result.decodePerAligned(new BitStreamReader(encodedBytes));
83     return result;
84   }
85 
86 
87 
isExtensible()88   @Override protected boolean isExtensible() {
89     return false;
90   }
91 
containsExtensionValues()92   @Override public boolean containsExtensionValues() {
93     for (SequenceComponent extensionComponent : getExtensionComponents()) {
94       if (extensionComponent.isExplicitlySet()) return true;
95     }
96     return false;
97   }
98 
99 
100   private Accuracy accuracy_;
getAccuracy()101   public Accuracy getAccuracy() {
102     return accuracy_;
103   }
104   /**
105    * @throws ClassCastException if value is not a Accuracy
106    */
setAccuracy(Asn1Object value)107   public void setAccuracy(Asn1Object value) {
108     this.accuracy_ = (Accuracy) value;
109   }
setAccuracyToNewInstance()110   public Accuracy setAccuracyToNewInstance() {
111     accuracy_ = new Accuracy();
112     return accuracy_;
113   }
114 
115 
116 
117 
118 
119 
getComponents()120   @Override public Iterable<? extends SequenceComponent> getComponents() {
121     ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder();
122 
123     builder.add(new SequenceComponent() {
124           Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 0);
125 
126           @Override public boolean isExplicitlySet() {
127             return getAccuracy() != null;
128           }
129 
130           @Override public boolean hasDefaultValue() {
131             return false;
132           }
133 
134           @Override public boolean isOptional() {
135             return true;
136           }
137 
138           @Override public Asn1Object getComponentValue() {
139             return getAccuracy();
140           }
141 
142           @Override public void setToNewInstance() {
143             setAccuracyToNewInstance();
144           }
145 
146           @Override public Collection<Asn1Tag> getPossibleFirstTags() {
147             return tag == null ? Accuracy.getPossibleFirstTags() : ImmutableList.of(tag);
148           }
149 
150           @Override
151           public Asn1Tag getTag() {
152             return tag;
153           }
154 
155           @Override
156           public boolean isImplicitTagging() {
157             return true;
158           }
159 
160           @Override public String toIndentedString(String indent) {
161                 return "accuracy : "
162                     + getAccuracy().toIndentedString(indent);
163               }
164         });
165 
166     return builder.build();
167   }
168 
169   @Override public Iterable<? extends SequenceComponent>
getExtensionComponents()170                                                     getExtensionComponents() {
171     ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder();
172 
173       return builder.build();
174     }
175 
176 
177 
178 
179 
180 
181 
encodePerUnaligned()182   @Override public Iterable<BitStream> encodePerUnaligned() {
183     return super.encodePerUnaligned();
184   }
185 
encodePerAligned()186   @Override public Iterable<BitStream> encodePerAligned() {
187     return super.encodePerAligned();
188   }
189 
decodePerUnaligned(BitStreamReader reader)190   @Override public void decodePerUnaligned(BitStreamReader reader) {
191     super.decodePerUnaligned(reader);
192   }
193 
decodePerAligned(BitStreamReader reader)194   @Override public void decodePerAligned(BitStreamReader reader) {
195     super.decodePerAligned(reader);
196   }
197 
toString()198   @Override public String toString() {
199     return toIndentedString("");
200   }
201 
toIndentedString(String indent)202   public String toIndentedString(String indent) {
203     StringBuilder builder = new StringBuilder();
204     builder.append("AccuracyOpt = {\n");
205     final String internalIndent = indent + "  ";
206     for (SequenceComponent component : getComponents()) {
207       if (component.isExplicitlySet()) {
208         builder.append(internalIndent)
209             .append(component.toIndentedString(internalIndent));
210       }
211     }
212     if (isExtensible()) {
213       builder.append(internalIndent).append("...\n");
214       for (SequenceComponent component : getExtensionComponents()) {
215         if (component.isExplicitlySet()) {
216           builder.append(internalIndent)
217               .append(component.toIndentedString(internalIndent));
218         }
219       }
220     }
221     builder.append(indent).append("};\n");
222     return builder.toString();
223   }
224 }
225