| 1 |
package com.thaiopensource.relaxng.output.xsd.basic; |
| 2 |
|
| 3 |
public class Occurs { |
| 4 |
private final int min; |
| 5 |
private final int max; |
| 6 |
static public final int UNBOUNDED = Integer.MAX_VALUE; |
| 7 |
static public final Occurs EXACTLY_ONE = new Occurs(1, 1); |
| 8 |
static public final Occurs ONE_OR_MORE = new Occurs(1, UNBOUNDED); |
| 9 |
static public final Occurs ZERO_OR_MORE = new Occurs(0, UNBOUNDED); |
| 10 |
static public final Occurs OPTIONAL = new Occurs(0, 1); |
| 11 |
|
| 12 |
public Occurs(int min, int max) { |
| 13 |
this.min = min; |
| 14 |
this.max = max; |
| 15 |
} |
| 16 |
|
| 17 |
public int getMin() { |
| 18 |
return min; |
| 19 |
} |
| 20 |
|
| 21 |
public int getMax() { |
| 22 |
return max; |
| 23 |
} |
| 24 |
|
| 25 |
public boolean equals(Object obj) { |
| 26 |
if (!(obj instanceof Occurs)) |
| 27 |
return false; |
| 28 |
return this.min == ((Occurs)obj).min && max == ((Occurs)obj).max; |
| 29 |
} |
| 30 |
|
| 31 |
public int hashCode() { |
| 32 |
return min ^ max; |
| 33 |
} |
| 34 |
|
| 35 |
static public Occurs add(Occurs occ1, Occurs occ2) { |
| 36 |
return new Occurs(occ1.min + occ2.min, |
| 37 |
occ1.max == UNBOUNDED || occ2.max == UNBOUNDED |
| 38 |
? UNBOUNDED |
| 39 |
: occ1.max + occ2.max); |
| 40 |
} |
| 41 |
|
| 42 |
static public Occurs multiply(Occurs occ1, Occurs occ2) { |
| 43 |
return new Occurs(occ1.min * occ2.min, |
| 44 |
occ1.max == UNBOUNDED || occ2.max == UNBOUNDED |
| 45 |
? UNBOUNDED |
| 46 |
: occ1.max * occ2.max); |
| 47 |
} |
| 48 |
|
| 49 |
} |