package org.uic.barcode.asn1.datatypes; import java.lang.reflect.ParameterizedType; import java.util.*; import org.uic.barcode.asn1.uper.UperEncoder; /** * Class to represent ASN.1 construct "SEQUENCE OF". *

* Extending classes should specify concrete types for T, generic collections can't be decoded (yet?). *

* Usage example: *

 * 
 * {@literal @}Sequence
 * public class Person {
 *     {@literal @}IntRange(minValue=0, maxValue=100, hasExtensionMarker=true)
 *     int age;
 *     Children children;
 * }
 * public class Children extends {@code Asn1SequenceOf } {
 *     public Children() { super(); }
 *     public Children({@code Collection} coll) { super(coll); }
 * }
 * 
 * 
* *

* Actually, UPER decoder and encoder consider anything that extends {@code List} as a SEQUENCE OF. * * * @param type of elements contained. */ public abstract class Asn1SequenceOf extends AbstractList { private final List bakingList; @Override public T get(int index) { return bakingList.get(index); } @Override public int size() { return bakingList.size(); } @Override public boolean add (T e){ return bakingList.add(e);} public Asn1SequenceOf() { this(new ArrayList()); } public Asn1SequenceOf(Collection coll) { UperEncoder.logger.debug(String.format("Instantiating Sequence Of %s with %s", ((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0], coll)); bakingList = new ArrayList<>(coll); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; Asn1SequenceOf that = (Asn1SequenceOf) o; return Objects.equals(bakingList, that.bakingList); } @Override public int hashCode() { return Objects.hash(super.hashCode(), bakingList); } }