package edu.stanford.rt.datatype;
/**
* @author Ninghui Li, Sandra Qiu
*
* Implementation of Inteval
element.
*
* An IntervalValueSet represents an Interval value. It has a min value and
* a max value. When min is null, it means that the lower side is
* unbounded. When max is null, the upper side is unbounded. When min
* is not null, includeMin can be true. Similarly, when max is not null,
* includeMax can be true.
*/
public class IntervalValueSet extends ValueSet
{
private DataValue min;
private DataValue max;
private boolean includeMin;
private boolean includeMax;
/**
* Constructor of IntervalValueSet.
*/
public IntervalValueSet(
OrderedType type,
DataValue min,
DataValue max)
{
super(type);
if(! (type instanceof OrderedType))
throw new IllegalArgumentException("Wrong data type");
if (min != null && !type.isValidValue(min))
throw new IllegalArgumentException("Illegal min value");
if (max != null && !type.isValidValue(max))
throw new IllegalArgumentException("Illegal max value");
this.min = min;
this.max = max;
if (this.min != null)
this.includeMin = true;
if (this.max != null)
this.includeMax = true;
}
/**
* Method getMin.
* @return DataValue
*/
public DataValue getMin()
{
return min;
}
/**
* Method getMax.
* @return DataValue
*/
public DataValue getMax()
{
return max;
}
/**
* Method isMinIncluded.
* @return boolean
*/
public boolean isMinIncluded()
{
return includeMin;
}
/**
* Method isMaxIncluded.
* @return boolean
*/
public boolean isMaxIncluded()
{
return includeMax;
}
/* (non-Javadoc)
* @see edu.stanford.rt.datatype.ValueSet#toString(String)
*/
public String toString(String indent)
{
String thisIndent = indent + " ";
StringBuffer sb = new StringBuffer();
sb.append(thisIndent).append("IntervalValueSet: \n");
sb.append(thisIndent + " ").append(
getType().toString()).append(
"\n");
sb.append(thisIndent + " ");
if (includeMin)
sb.append(" [");
else
sb.append(" (");
sb.append(min.toString());
sb.append(", ");
sb.append(max.toString());
if (includeMax)
sb.append("]");
else
sb.append(") ");
sb.append("\n");
return sb.toString();
}
}