Fixes #1703 properly this time. addendum to #1718

This commit is contained in:
parrt 2017-03-02 14:13:27 -08:00
parent 8dee8c774b
commit 6572b08095
2 changed files with 6 additions and 30 deletions

View File

@ -128,16 +128,6 @@ public interface IntSet {
@Override @Override
boolean equals(Object obj); boolean equals(Object obj);
/**
* Returns the single value contained in the set, if {@link #size} is 1;
* otherwise, result is undefined. Check {@link #isNil()} before using
* this function.
*
* @return the single value contained in the set, if {@link #size} is 1;
* otherwise, result is undefined.
*/
int getSingleElement();
/** /**
* Returns {@code true} if the set contains the specified element. * Returns {@code true} if the set contains the specified element.
* *

View File

@ -416,28 +416,15 @@ public class IntervalSet implements IntSet {
return intervals==null || intervals.isEmpty(); return intervals==null || intervals.isEmpty();
} }
/** {@inheritDoc} */
@Override
public int getSingleElement() {
if ( intervals!=null && intervals.size()==1 ) {
Interval I = intervals.get(0);
if ( I.a == I.b ) {
return I.a;
}
}
return Token.INVALID_TYPE;
}
/** /**
* Returns the maximum value contained in the set if not isNil(). * Returns the maximum value contained in the set if not isNil().
* Otherwise, result is undefined.
* *
* @return the maximum value contained in the set. If the set is empty, * @return the maximum value contained in the set.
* result is undefined. * @throws RuntimeException if set is empty
*/ */
public int getMaxElement() { public int getMaxElement() {
if ( isNil() ) { if ( isNil() ) {
return Token.INVALID_TYPE; throw new RuntimeException("set is empty");
} }
Interval last = intervals.get(intervals.size()-1); Interval last = intervals.get(intervals.size()-1);
return last.b; return last.b;
@ -445,14 +432,13 @@ public class IntervalSet implements IntSet {
/** /**
* Returns the minimum value contained in the set if not isNil(). * Returns the minimum value contained in the set if not isNil().
* Otherwise, result is undefined.
* *
* @return the minimum value contained in the set. If the set is empty, * @return the minimum value contained in the set.
* result is undefined. * @throws RuntimeException if set is empty
*/ */
public int getMinElement() { public int getMinElement() {
if ( isNil() ) { if ( isNil() ) {
return Token.INVALID_TYPE; throw new RuntimeException("set is empty");
} }
return intervals.get(0).a; return intervals.get(0).a;