1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package sk.uniba.euromath.document.schema;
18 import java.util.ArrayList;
19 import java.util.List;
20 import sk.baka.ikslibs.ptr.DOMPoint;
21 import sk.uniba.euromath.document.schema.plug.IElementSequenceRuleP;
22 import sk.uniba.euromath.document.schema.plug.IInsertListP;
23 /***
24 * Represents rule generating sequence of elements.
25 * @author Martin Vysny
26 */
27 public class ElementSequenceRule {
28 /***
29 * Original rule.
30 */
31 private final IElementSequenceRuleP seqRule;
32 /***
33 * Constructs the wrapper.
34 * @param seqRule original rule.
35 */
36 ElementSequenceRule(IElementSequenceRuleP seqRule) {
37 super();
38 this.seqRule = seqRule;
39 }
40 /***
41 * <p>
42 * Computes all possibilities of sequences, that can be generated by this
43 * rule. There must be only such insertlists, that doesn't contain optional
44 * elements. There must be no duplicite insertlists. If no elements are
45 * required to be created then an empty list shall be returned.
46 * </p>
47 * <p>
48 * All insertpoints in each returned insertlist must be equal to
49 * <code>start</code>. All one-item-length insertlists must be grouped
50 * together into one insert list.
51 * </p>
52 * @param start insertpoint, from which the numbering must start. It is
53 * guaranteed that <code>start.pos == 0</code> is true.
54 * @return array of Insertlists, that can generate sequence of element,
55 * never <code>null</code>.
56 */
57 public List<InsertList> getSequences(DOMPoint start) {
58 if (seqRule == null)
59 return new ArrayList<InsertList>(0);
60 List<? extends IInsertListP> seqs = seqRule.getSequences(start);
61 List<InsertList> result = new ArrayList<InsertList>(seqs.size());
62 for (IInsertListP ilP:seqs) {
63 result.add(new InsertList(ilP));
64 }
65 return result;
66 }
67 }