summaryrefslogtreecommitdiffstats
path: root/src/net/gcdc/asn1/datatypes/Asn1SequenceOf.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/gcdc/asn1/datatypes/Asn1SequenceOf.java')
-rw-r--r--src/net/gcdc/asn1/datatypes/Asn1SequenceOf.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/net/gcdc/asn1/datatypes/Asn1SequenceOf.java b/src/net/gcdc/asn1/datatypes/Asn1SequenceOf.java
new file mode 100644
index 0000000..2985c96
--- /dev/null
+++ b/src/net/gcdc/asn1/datatypes/Asn1SequenceOf.java
@@ -0,0 +1,70 @@
+package net.gcdc.asn1.datatypes;
+
+import java.lang.reflect.ParameterizedType;
+import java.util.*;
+
+import logger.Logger;
+import logger.LoggerFactory;
+
+
+/**
+ * Class to represent ASN.1 construct "SEQUENCE OF".
+ * <p/>
+ * Extending classes should specify concrete types for T, generic collections can't be decoded (yet?).
+ * <p/>
+ * Usage example:
+ * <PRE>
+ * <code>
+ * {@literal @}Sequence
+ * public class Person {
+ * {@literal @}IntRange(minValue=0, maxValue=100, hasExtensionMarker=true)
+ * int age;
+ * Children children;
+ * }
+ * public class Children extends {@code Asn1SequenceOf<ChildInformation> } {
+ * public Children() { super(); }
+ * public Children({@code Collection<ChildInformation>} coll) { super(coll); }
+ * }
+ * </code>
+ * </PRE>
+ *
+ * <p/>
+ * Actually, UPER decoder and encoder consider anything that extends {@code List<T>} as a SEQUENCE OF.
+ *
+ *
+ * @param <T> type of elements contained.
+ */
+public abstract class Asn1SequenceOf<T> extends AbstractList<T> {
+ private final static Logger logger = LoggerFactory.getLogger("asnLogger");
+
+ private final List<T> 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<T>()); }
+ public Asn1SequenceOf(Collection<T> coll) {
+ 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);
+ }
+}