~ubuntu-branches/ubuntu/jaunty/weka/jaunty

« back to all changes in this revision

Viewing changes to weka/core/parser/java_cup/terminal_set.java

  • Committer: Bazaar Package Importer
  • Author(s): Soeren Sonnenburg, Torsten Werner, Soeren Sonnenburg
  • Date: 2008-10-30 06:42:46 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081030064246-648zj038l155host
Tags: 3.5.8+cup1-1
[ Torsten Werner ]
* Update Section field in doc-base file.
* Add Class-Path attribute to jar file.

[ Soeren Sonnenburg ]
* Update my email address to sonne@debian.org.
* Update copyright.
* Remove build, java cup and jflex from orig.tar.gz.
* Add cup and jflex as build dependency.
* Patch weka source to use cup from debian.
* Patch weka shell wrapper to use java-6-sun or openjdk.
* Obtain documentation from svn.
* Build depend on texlive-latex-extra (required to generate documentation).
* Add javadoc as build target.
* Use java-wrappers to start weka.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * STANDARD ML OF NEW JERSEY COPYRIGHT NOTICE, LICENSE AND DISCLAIMER.
3
 
 * 
4
 
 * Copyright (c) 1989-1998 by Lucent Technologies
5
 
 * 
6
 
 * Permission to use, copy, modify, and distribute this software and its
7
 
 * documentation for any purpose and without fee is hereby granted, provided
8
 
 * that the above copyright notice appear in all copies and that both the
9
 
 * copyright notice and this permission notice and warranty disclaimer appear
10
 
 * in supporting documentation, and that the name of Lucent Technologies, Bell
11
 
 * Labs or any Lucent entity not be used in advertising or publicity pertaining
12
 
 * to distribution of the software without specific, written prior permission.
13
 
 *
14
 
 * Lucent disclaims all warranties with regard to this software, including all
15
 
 * implied warranties of merchantability and fitness. In no event shall Lucent
16
 
 * be liable for any special, indirect or consequential damages or any damages
17
 
 * whatsoever resulting from loss of use, data or profits, whether in an action
18
 
 * of contract, negligence or other tortious action, arising out of or in
19
 
 * connection with the use or performance of this software. 
20
 
 *
21
 
 * Taken from this URL:
22
 
 * http://www.smlnj.org/license.html
23
 
 * 
24
 
 * This license is compatible with the GNU GPL (see section "Standard ML of New
25
 
 * Jersey Copyright License"):
26
 
 * http://www.gnu.org/licenses/license-list.html#StandardMLofNJ
27
 
 */
28
 
 
29
 
/*
30
 
 * Copyright 1996-1999 by Scott Hudson, Frank Flannery, C. Scott Ananian
31
 
 */
32
 
 
33
 
package weka.core.parser.java_cup;
34
 
 
35
 
import java.util.BitSet;
36
 
 
37
 
/** A set of terminals implemented as a bitset. 
38
 
 * @version last updated: 11/25/95
39
 
 * @author  Scott Hudson
40
 
 */
41
 
public class terminal_set {
42
 
 
43
 
  /*-----------------------------------------------------------*/
44
 
  /*--- Constructor(s) ----------------------------------------*/
45
 
  /*-----------------------------------------------------------*/
46
 
 
47
 
  /** Constructor for an empty set. */
48
 
  public terminal_set() 
49
 
    { 
50
 
      /* allocate the bitset at what is probably the right size */
51
 
      _elements = new BitSet(terminal.number());
52
 
    }
53
 
 
54
 
  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
55
 
 
56
 
  /** Constructor for cloning from another set. 
57
 
   * @param other the set we are cloning from.
58
 
   */
59
 
  public terminal_set(terminal_set other) 
60
 
    throws internal_error
61
 
    {
62
 
      not_null(other);
63
 
      _elements = (BitSet)other._elements.clone();
64
 
    }
65
 
 
66
 
  /*-----------------------------------------------------------*/
67
 
  /*--- (Access to) Static (Class) Variables ------------------*/
68
 
  /*-----------------------------------------------------------*/
69
 
 
70
 
  /** Constant for the empty set. */
71
 
  public static final terminal_set EMPTY = new terminal_set();
72
 
 
73
 
  /*-----------------------------------------------------------*/
74
 
  /*--- (Access to) Instance Variables ------------------------*/
75
 
  /*-----------------------------------------------------------*/
76
 
 
77
 
  /** Bitset to implement the actual set. */
78
 
  protected BitSet _elements;
79
 
 
80
 
  /*-----------------------------------------------------------*/
81
 
  /*--- General Methods ----------------------------------------*/
82
 
  /*-----------------------------------------------------------*/
83
 
 
84
 
  /** Helper function to test for a null object and throw an exception if
85
 
   *  one is found. 
86
 
   * @param obj the object we are testing.
87
 
   */
88
 
  protected void not_null(Object obj) throws internal_error
89
 
    {
90
 
      if (obj == null) 
91
 
        throw new internal_error("Null object used in set operation");
92
 
    }
93
 
 
94
 
  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
95
 
 
96
 
  /** Determine if the set is empty. */
97
 
  public boolean empty()
98
 
    {
99
 
      return equals(EMPTY);
100
 
    }
101
 
 
102
 
  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
103
 
 
104
 
  /** Determine if the set contains a particular terminal. 
105
 
   * @param sym the terminal symbol we are looking for.
106
 
   */
107
 
  public boolean contains(terminal sym) 
108
 
    throws internal_error
109
 
    {
110
 
      not_null(sym); 
111
 
      return _elements.get(sym.index());
112
 
    }
113
 
 
114
 
  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
115
 
 
116
 
  /** Given its index determine if the set contains a particular terminal. 
117
 
   * @param indx the index of the terminal in question.
118
 
   */
119
 
  public boolean contains(int indx) 
120
 
    {
121
 
      return _elements.get(indx);
122
 
    }
123
 
 
124
 
  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
125
 
 
126
 
  /** Determine if this set is an (improper) subset of another.
127
 
   * @param other the set we are testing against.
128
 
   */
129
 
  public boolean is_subset_of(terminal_set other)
130
 
    throws internal_error
131
 
    {
132
 
      not_null(other);
133
 
 
134
 
      /* make a copy of the other set */
135
 
      BitSet copy_other = (BitSet)other._elements.clone();
136
 
 
137
 
      /* and or in */
138
 
      copy_other.or(_elements);
139
 
 
140
 
      /* if it hasn't changed, we were a subset */
141
 
      return copy_other.equals(other._elements);
142
 
    }
143
 
 
144
 
  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
145
 
 
146
 
  /** Determine if this set is an (improper) superset of another.
147
 
   * @param other the set we are testing against.
148
 
   */
149
 
  public boolean is_superset_of(terminal_set other)
150
 
    throws internal_error
151
 
    {
152
 
      not_null(other);
153
 
      return other.is_subset_of(this);
154
 
    }
155
 
 
156
 
  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
157
 
 
158
 
  /** Add a single terminal to the set.  
159
 
   * @param sym the terminal being added.
160
 
   * @return true if this changes the set.
161
 
   */
162
 
  public boolean add(terminal sym) 
163
 
    throws internal_error
164
 
    {
165
 
      boolean result;
166
 
 
167
 
      not_null(sym); 
168
 
 
169
 
      /* see if we already have this */ 
170
 
      result = _elements.get(sym.index());
171
 
 
172
 
      /* if not we add it */
173
 
      if (!result)
174
 
        _elements.set(sym.index());
175
 
 
176
 
      return result;
177
 
    }
178
 
 
179
 
  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
180
 
 
181
 
  /** Remove a terminal if it is in the set.
182
 
   * @param sym the terminal being removed.
183
 
   */
184
 
  public void remove(terminal sym) 
185
 
    throws internal_error
186
 
    {
187
 
      not_null(sym); 
188
 
      _elements.clear(sym.index());
189
 
    }
190
 
 
191
 
  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
192
 
 
193
 
  /** Add (union) in a complete set.  
194
 
   * @param other the set being added.
195
 
   * @return true if this changes the set.
196
 
   */
197
 
  public boolean add(terminal_set other)
198
 
    throws internal_error
199
 
    {
200
 
      not_null(other);
201
 
 
202
 
      /* make a copy */
203
 
      BitSet copy = (BitSet)_elements.clone();
204
 
 
205
 
      /* or in the other set */
206
 
      _elements.or(other._elements);
207
 
 
208
 
      /* changed if we are not the same as the copy */
209
 
      return !_elements.equals(copy);
210
 
    }
211
 
 
212
 
  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
213
 
 
214
 
  /** Determine if this set intersects another.
215
 
   * @param other the other set in question.
216
 
   */
217
 
   public boolean intersects(terminal_set other)
218
 
     throws internal_error
219
 
     {
220
 
       not_null(other);
221
 
 
222
 
       /* make a copy of the other set */
223
 
       BitSet copy = (BitSet)other._elements.clone();
224
 
 
225
 
       /* xor out our values */
226
 
       copy.xor(this._elements);
227
 
 
228
 
       /* see if its different */
229
 
       return !copy.equals(other._elements);
230
 
     }
231
 
 
232
 
  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
233
 
 
234
 
  /** Equality comparison. */
235
 
  public boolean equals(terminal_set other)
236
 
    {
237
 
      if (other == null) 
238
 
        return false;
239
 
      else
240
 
        return _elements.equals(other._elements);
241
 
    }
242
 
 
243
 
  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
244
 
 
245
 
  /** Generic equality comparison. */
246
 
  public boolean equals(Object other)
247
 
    {
248
 
      if (!(other instanceof terminal_set))
249
 
        return false;
250
 
      else
251
 
        return equals((terminal_set)other);
252
 
    }
253
 
 
254
 
  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
255
 
 
256
 
  /** Convert to string. */
257
 
  public String toString()
258
 
    {
259
 
      String result;
260
 
      boolean comma_flag;
261
 
      
262
 
      result = "{";
263
 
      comma_flag = false;
264
 
      for (int t = 0; t < terminal.number(); t++)
265
 
        {
266
 
          if (_elements.get(t))
267
 
            {
268
 
              if (comma_flag)
269
 
                result += ", ";
270
 
              else
271
 
                comma_flag = true;
272
 
 
273
 
              result += terminal.find(t).name();
274
 
            }
275
 
        }
276
 
      result += "}";
277
 
 
278
 
      return result;
279
 
    }
280
 
 
281
 
  /*-----------------------------------------------------------*/
282
 
 
283
 
}
284