KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > relaxng > impl > DuplicateAttributeDetector


1 package com.thaiopensource.relaxng.impl;
2
3 import java.util.Vector JavaDoc;
4
5 class DuplicateAttributeDetector {
6   private final Vector JavaDoc nameClasses = new Vector JavaDoc();
7   private Alternative alternatives = null;
8
9   private static class Alternative {
10     private final int startIndex;
11     private int endIndex;
12     private final Alternative parent;
13
14     private Alternative(int startIndex, Alternative parent) {
15       this.startIndex = startIndex;
16       this.endIndex = startIndex;
17       this.parent = parent;
18     }
19   }
20
21   boolean addAttribute(NameClass nc) {
22     int lim = nameClasses.size();
23     for (Alternative a = alternatives; a != null; a = a.parent) {
24       for (int i = a.endIndex; i < lim; i++)
25     if (OverlapDetector.overlap(nc, (NameClass)nameClasses.elementAt(i)))
26       return false;
27       lim = a.startIndex;
28     }
29     for (int i = 0; i < lim; i++)
30       if (OverlapDetector.overlap(nc, (NameClass)nameClasses.elementAt(i)))
31     return false;
32     nameClasses.addElement(nc);
33     return true;
34   }
35
36   void startChoice() {
37     alternatives = new Alternative(nameClasses.size(), alternatives);
38   }
39
40   void alternative() {
41     alternatives.endIndex = nameClasses.size();
42   }
43
44   void endChoice() {
45     alternatives = alternatives.parent;
46   }
47
48 }
49
Popular Tags