JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / unused / com / stevesoft / pat / Bracket.java
1 //
2 // This software is now distributed according to
3 // the Lesser Gnu Public License.  Please see
4 // http://www.gnu.org/copyleft/lesser.txt for
5 // the details.
6 //    -- Happy Computing!
7 //
8 package com.stevesoft.pat;
9
10 import java.util.*;
11
12 /**
13  * The Bracket is a form of the Or class, implements the pattern element [ ].
14  */
15 class Bracket extends Or
16 {
17   boolean neg;
18
19   Bracket(boolean n)
20   {
21     neg = n;
22   }
23
24   String leftForm()
25   {
26     if (neg)
27     {
28       return "[^";
29     }
30     else
31     {
32       return "[";
33     }
34   }
35
36   String rightForm()
37   {
38     return "]";
39   }
40
41   String sepForm()
42   {
43     return "";
44   }
45
46   public int matchInternal(int pos, Pthings pt)
47   {
48     if (pos >= pt.src.length())
49     {
50       return -1;
51     }
52     int r = super.matchInternal(pos, pt);
53     if ((neg && r < 0) || (!neg && r >= 0))
54     {
55       return nextMatch(pos + 1, pt);
56     }
57     return -1;
58   }
59
60   public patInt minChars()
61   {
62     return new patInt(1);
63   }
64
65   public patInt maxChars()
66   {
67     return new patInt(1);
68   }
69
70   public Or addOr(Pattern p)
71   {
72     pv = null;
73     v.addElement(p);
74     p.setParent(null);
75     return this;
76   }
77
78   public Pattern clone1(Hashtable h)
79   {
80     Bracket b = new Bracket(neg);
81     b.v = new Vector();
82     for (int i = 0; i < v.size(); i++)
83     {
84       b.v.addElement(((Pattern) v.elementAt(i)).clone1(h));
85     }
86     return b;
87   }
88 };