01: package org.kohsuke.rngom.binary;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05:
06: import org.kohsuke.rngom.nc.NameClass;
07:
08: class DuplicateAttributeDetector {
09: private List nameClasses = new ArrayList();
10: private Alternative alternatives = null;
11:
12: private static class Alternative {
13: private int startIndex;
14: private int endIndex;
15: private Alternative parent;
16:
17: private Alternative(int startIndex, Alternative parent) {
18: this .startIndex = startIndex;
19: this .endIndex = startIndex;
20: this .parent = parent;
21: }
22: }
23:
24: boolean addAttribute(NameClass nc) {
25: int lim = nameClasses.size();
26: for (Alternative a = alternatives; a != null; a = a.parent) {
27: for (int i = a.endIndex; i < lim; i++)
28: if (nc.hasOverlapWith((NameClass) nameClasses.get(i)))
29: return false;
30: lim = a.startIndex;
31: }
32: for (int i = 0; i < lim; i++)
33: if (nc.hasOverlapWith((NameClass) nameClasses.get(i)))
34: return false;
35: nameClasses.add(nc);
36: return true;
37: }
38:
39: void startChoice() {
40: alternatives = new Alternative(nameClasses.size(), alternatives);
41: }
42:
43: void alternative() {
44: alternatives.endIndex = nameClasses.size();
45: }
46:
47: void endChoice() {
48: alternatives = alternatives.parent;
49: }
50:
51: }
|