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