blob: 4924b5014f893acd6f9d152e5c6d30c341d45135 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package org.uic.barcode.asn1.datatypes;
import java.lang.reflect.ParameterizedType;
import java.util.*;
import org.uic.barcode.logger.Logger;
import org.uic.barcode.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);
}
}
|