1 /*
2 * File: IntervalIntegerSet.java
3 * Created: 13.10.2006 8:52:33
4 *
5 * Copyright 2006 Michal Burda.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21 package net.sf.webmancer.util.integerset;
22
23 import java.util.Vector;
24
25 /**
26 * TODO Add description of IntervalIntegerSet class.
27 *
28 * @author burdamic, TietoEnator Corporation Ltd Created on 21.7.2006
29 */
30 class IntervalIntegerSet implements IIntegerSet {
31 /**
32 *
33 */
34 int minimum;
35
36 /**
37 *
38 */
39 int maximum;
40
41 /**
42 *
43 */
44 private Vector<Interval> intervals;
45
46 /**
47 *
48 */
49 public IntervalIntegerSet() {
50 super();
51 this.intervals = new Vector<Interval>();
52 this.minimum = Integer.MAX_VALUE;
53 this.maximum = Integer.MIN_VALUE;
54 }
55
56 /**
57 * @see cz.vsb.cs.ruleminer.util.integerset.IIntegerSet#contains(int)
58 */
59 public boolean contains(final int integer) {
60 for (Interval interval : this.intervals) {
61 if (interval.contains(integer)) {
62 return true;
63 }
64 }
65 return false;
66 }
67
68 /**
69 * @param from
70 * @param to
71 */
72 public void addInterval(final int from, final int to) {
73 if (from > to) {
74 throw new IllegalArgumentException("'from' must not be greater than 'to'");
75 }
76 this.intervals.add(new Interval(from, to));
77 if (this.minimum > from) {
78 this.minimum = from;
79 }
80 if (this.maximum < to) {
81 this.maximum = to;
82 }
83 }
84
85 /**
86 * @see cz.vsb.cs.ruleminer.util.integerset.IIntegerSet#getMaximum()
87 */
88 public int getMaximum() {
89 return this.maximum;
90 }
91
92 /**
93 * @see cz.vsb.cs.ruleminer.util.integerset.IIntegerSet#getMinimum()
94 */
95 public int getMinimum() {
96 return this.minimum;
97 }
98
99 }