1 package jsdsi;
2
3 import java.util.Iterator;
4
5 import jsdsi.sexp.Sexp;
6 import jsdsi.sexp.SexpList;
7 import jsdsi.sexp.SexpParseException;
8 import jsdsi.sexp.SexpUtil;
9
10 /***
11 * A sequence of SPKI/SDSI objects, typically used to present certs and
12 * validators that prove a particular statement.
13 *
14 * @see Proof
15 *
16 * @author Sameer Ajmani
17 * @author Sean Radford
18 * @version $Revision: 1.3.2.1 $ $Date: 2005/11/08 03:12:52 $
19 */
20 public class Sequence extends Obj {
21
22 private static final long serialVersionUID = 7379198170031908180L;
23
24 /***
25 * Elements of this <code>Sequence</code>.
26 */
27 private transient final Element[] elements;
28
29 /***
30 * Creates a new <code>Sequence</code> from a given array of elements.
31 *
32 * @param e array of elements to create the <code>Sequence</code> from.
33 */
34 public Sequence(Element[] e) {
35 assert(e != null) : "null elements";
36 elements = e;
37 }
38
39 /***
40 * Returns the elements of this <code>Sequence</code>.
41 *
42 * @return the elements of this <code>Sequence</code>.
43 */
44 public Element[] getElements() {
45 return elements;
46 }
47
48 /***
49 * Concatenates this <code>Sequence</code> with a given one.
50 *
51 * @param s sequence to concat this sequence with.
52 * @return the sequence containing the elements of this sequence
53 * and the elements of <code>s</code>.
54 */
55 public Sequence concat(Sequence s) {
56 Element[] els = new Element[elements.length + s.elements.length];
57 System.arraycopy(elements, 0, els, 0, elements.length);
58 System.arraycopy(
59 s.elements,
60 0,
61 els,
62 elements.length,
63 s.elements.length);
64 return new Sequence(els);
65 }
66
67 /***
68 * @see java.lang.Object#equals(Object)
69 */
70 public boolean equals(Object o) {
71 return (o instanceof Sequence)
72 && Util.equals(elements, ((Sequence) o).elements);
73 }
74
75 /***
76 * @see java.lang.Object#hashCode()
77 */
78 public int hashCode() {
79 return Util.hashCode(elements);
80 }
81
82 public SexpList toSexp() {
83 Sexp[] ss = new Sexp[elements.length];
84 for (int i = 0; i < elements.length; i++) {
85 ss[i] = elements[i].toSexp();
86 }
87 return SexpUtil.toSexp("sequence", ss);
88 }
89
90 static Sequence parseSequence(SexpList l) throws SexpParseException {
91 Iterator sbody = SexpUtil.getBody(l);
92 Element[] elems = new Element[l.size() - 1];
93 for (int i = 0; i < elems.length; i++) {
94 elems[i] = Element.Default.parseElement(
95 SexpUtil.getNextList(sbody, "sequence element"));
96 }
97 SexpUtil.checkDone(sbody, "sequence"); // sanity check
98 return new Sequence(elems);
99 }
100 }
This page was automatically generated by Maven