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_report; 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 android.location.cts.asn1.supl2.ver2_ulp_components.MultipleLocationIds; 33 import com.google.common.collect.ImmutableList; 34 import java.util.Collection; 35 import javax.annotation.Nullable; 36 37 38 /** 39 */ 40 public class ReportData extends Asn1Sequence { 41 // 42 43 private static final Asn1Tag TAG_ReportData 44 = Asn1Tag.fromClassAndNumber(-1, -1); 45 46 public ReportData() { 47 super(); 48 } 49 50 @Override 51 @Nullable 52 protected Asn1Tag getTag() { 53 return TAG_ReportData; 54 } 55 56 @Override 57 protected boolean isTagImplicit() { 58 return true; 59 } 60 61 public static Collection<Asn1Tag> getPossibleFirstTags() { 62 if (TAG_ReportData != null) { 63 return ImmutableList.of(TAG_ReportData); 64 } else { 65 return Asn1Sequence.getPossibleFirstTags(); 66 } 67 } 68 69 /** 70 * Creates a new ReportData from encoded stream. 71 */ 72 public static ReportData fromPerUnaligned(byte[] encodedBytes) { 73 ReportData result = new ReportData(); 74 result.decodePerUnaligned(new BitStreamReader(encodedBytes)); 75 return result; 76 } 77 78 /** 79 * Creates a new ReportData from encoded stream. 80 */ 81 public static ReportData fromPerAligned(byte[] encodedBytes) { 82 ReportData result = new ReportData(); 83 result.decodePerAligned(new BitStreamReader(encodedBytes)); 84 return result; 85 } 86 87 88 89 @Override protected boolean isExtensible() { 90 return true; 91 } 92 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 PositionData positionData_; 102 public PositionData getPositionData() { 103 return positionData_; 104 } 105 /** 106 * @throws ClassCastException if value is not a PositionData 107 */ 108 public void setPositionData(Asn1Object value) { 109 this.positionData_ = (PositionData) value; 110 } 111 public PositionData setPositionDataToNewInstance() { 112 positionData_ = new PositionData(); 113 return positionData_; 114 } 115 116 private MultipleLocationIds multipleLocationIds_; 117 public MultipleLocationIds getMultipleLocationIds() { 118 return multipleLocationIds_; 119 } 120 /** 121 * @throws ClassCastException if value is not a MultipleLocationIds 122 */ 123 public void setMultipleLocationIds(Asn1Object value) { 124 this.multipleLocationIds_ = (MultipleLocationIds) value; 125 } 126 public MultipleLocationIds setMultipleLocationIdsToNewInstance() { 127 multipleLocationIds_ = new MultipleLocationIds(); 128 return multipleLocationIds_; 129 } 130 131 private ResultCode resultCode_; 132 public ResultCode getResultCode() { 133 return resultCode_; 134 } 135 /** 136 * @throws ClassCastException if value is not a ResultCode 137 */ 138 public void setResultCode(Asn1Object value) { 139 this.resultCode_ = (ResultCode) value; 140 } 141 public ResultCode setResultCodeToNewInstance() { 142 resultCode_ = new ResultCode(); 143 return resultCode_; 144 } 145 146 private TimeStamp timestamp_; 147 public TimeStamp getTimestamp() { 148 return timestamp_; 149 } 150 /** 151 * @throws ClassCastException if value is not a TimeStamp 152 */ 153 public void setTimestamp(Asn1Object value) { 154 this.timestamp_ = (TimeStamp) value; 155 } 156 public TimeStamp setTimestampToNewInstance() { 157 timestamp_ = new TimeStamp(); 158 return timestamp_; 159 } 160 161 162 163 164 165 166 @Override public Iterable<? extends SequenceComponent> getComponents() { 167 ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder(); 168 169 builder.add(new SequenceComponent() { 170 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 0); 171 172 @Override public boolean isExplicitlySet() { 173 return getPositionData() != null; 174 } 175 176 @Override public boolean hasDefaultValue() { 177 return false; 178 } 179 180 @Override public boolean isOptional() { 181 return true; 182 } 183 184 @Override public Asn1Object getComponentValue() { 185 return getPositionData(); 186 } 187 188 @Override public void setToNewInstance() { 189 setPositionDataToNewInstance(); 190 } 191 192 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 193 return tag == null ? PositionData.getPossibleFirstTags() : ImmutableList.of(tag); 194 } 195 196 @Override 197 public Asn1Tag getTag() { 198 return tag; 199 } 200 201 @Override 202 public boolean isImplicitTagging() { 203 return true; 204 } 205 206 @Override public String toIndentedString(String indent) { 207 return "positionData : " 208 + getPositionData().toIndentedString(indent); 209 } 210 }); 211 212 builder.add(new SequenceComponent() { 213 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 1); 214 215 @Override public boolean isExplicitlySet() { 216 return getMultipleLocationIds() != null; 217 } 218 219 @Override public boolean hasDefaultValue() { 220 return false; 221 } 222 223 @Override public boolean isOptional() { 224 return true; 225 } 226 227 @Override public Asn1Object getComponentValue() { 228 return getMultipleLocationIds(); 229 } 230 231 @Override public void setToNewInstance() { 232 setMultipleLocationIdsToNewInstance(); 233 } 234 235 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 236 return tag == null ? MultipleLocationIds.getPossibleFirstTags() : ImmutableList.of(tag); 237 } 238 239 @Override 240 public Asn1Tag getTag() { 241 return tag; 242 } 243 244 @Override 245 public boolean isImplicitTagging() { 246 return true; 247 } 248 249 @Override public String toIndentedString(String indent) { 250 return "multipleLocationIds : " 251 + getMultipleLocationIds().toIndentedString(indent); 252 } 253 }); 254 255 builder.add(new SequenceComponent() { 256 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 2); 257 258 @Override public boolean isExplicitlySet() { 259 return getResultCode() != null; 260 } 261 262 @Override public boolean hasDefaultValue() { 263 return false; 264 } 265 266 @Override public boolean isOptional() { 267 return true; 268 } 269 270 @Override public Asn1Object getComponentValue() { 271 return getResultCode(); 272 } 273 274 @Override public void setToNewInstance() { 275 setResultCodeToNewInstance(); 276 } 277 278 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 279 return tag == null ? ResultCode.getPossibleFirstTags() : ImmutableList.of(tag); 280 } 281 282 @Override 283 public Asn1Tag getTag() { 284 return tag; 285 } 286 287 @Override 288 public boolean isImplicitTagging() { 289 return true; 290 } 291 292 @Override public String toIndentedString(String indent) { 293 return "resultCode : " 294 + getResultCode().toIndentedString(indent); 295 } 296 }); 297 298 builder.add(new SequenceComponent() { 299 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 3); 300 301 @Override public boolean isExplicitlySet() { 302 return getTimestamp() != null; 303 } 304 305 @Override public boolean hasDefaultValue() { 306 return false; 307 } 308 309 @Override public boolean isOptional() { 310 return true; 311 } 312 313 @Override public Asn1Object getComponentValue() { 314 return getTimestamp(); 315 } 316 317 @Override public void setToNewInstance() { 318 setTimestampToNewInstance(); 319 } 320 321 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 322 return tag == null ? TimeStamp.getPossibleFirstTags() : ImmutableList.of(tag); 323 } 324 325 @Override 326 public Asn1Tag getTag() { 327 return tag; 328 } 329 330 @Override 331 public boolean isImplicitTagging() { 332 return true; 333 } 334 335 @Override public String toIndentedString(String indent) { 336 return "timestamp : " 337 + getTimestamp().toIndentedString(indent); 338 } 339 }); 340 341 return builder.build(); 342 } 343 344 @Override public Iterable<? extends SequenceComponent> 345 getExtensionComponents() { 346 ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder(); 347 348 return builder.build(); 349 } 350 351 352 353 354 355 356 357 358 359 360 361 362 363 @Override public Iterable<BitStream> encodePerUnaligned() { 364 return super.encodePerUnaligned(); 365 } 366 367 @Override public Iterable<BitStream> encodePerAligned() { 368 return super.encodePerAligned(); 369 } 370 371 @Override public void decodePerUnaligned(BitStreamReader reader) { 372 super.decodePerUnaligned(reader); 373 } 374 375 @Override public void decodePerAligned(BitStreamReader reader) { 376 super.decodePerAligned(reader); 377 } 378 379 @Override public String toString() { 380 return toIndentedString(""); 381 } 382 383 public String toIndentedString(String indent) { 384 StringBuilder builder = new StringBuilder(); 385 builder.append("ReportData = {\n"); 386 final String internalIndent = indent + " "; 387 for (SequenceComponent component : getComponents()) { 388 if (component.isExplicitlySet()) { 389 builder.append(internalIndent) 390 .append(component.toIndentedString(internalIndent)); 391 } 392 } 393 if (isExtensible()) { 394 builder.append(internalIndent).append("...\n"); 395 for (SequenceComponent component : getExtensionComponents()) { 396 if (component.isExplicitlySet()) { 397 builder.append(internalIndent) 398 .append(component.toIndentedString(internalIndent)); 399 } 400 } 401 } 402 builder.append(indent).append("};\n"); 403 return builder.toString(); 404 } 405 } 406