Holger's
Java API

com.antelmann.util
Class Range<T extends Comparable<? super T>>

java.lang.Object
  extended by com.antelmann.util.Range<T>
All Implemented Interfaces:
SQLConstraint, Filter<T>, Serializable

public class Range<T extends Comparable<? super T>>
extends Object
implements SQLConstraint, Filter<T>

provides a generic wrapper for lower- and upperbounds for a comparable object. Range objects are immutable. As a specialty, instances of this class can also be used in the com.antelmann.sql package to provide more sophisticated query support.

Author:
Holger Antelmann
See Also:
ConnectionHelper.addWhereClause(Appendable, java.util.List, java.util.Map), SQLMapFilter, Serialized Form

Field Summary
 
Fields inherited from interface com.antelmann.sql.SQLConstraint
IS_NULL, NOT_NULL
 
Fields inherited from interface com.antelmann.util.Filter
EXCLUDE_ALL_FILTER, INCLUDE_ALL_FILTER
 
Constructor Summary
Range()
          a range with effectively no restrictions; any given object would be within the range
Range(Comparable<? super T> lowerBound, Comparable<? super T> upperBound)
          both bounds are considered inclusive within the range.
Range(Comparable<? super T> lowerBound, Comparable<? super T> upperBound, boolean inclusive)
          if either or both (lower- and upperBound) are non-null, they represent a limit that is either inclusive or not depending on the given boolean.
 
Method Summary
 boolean accept(T entry)
          returns true only if the given entry is accepted by this filter
 Range<Date> asRange(LifeCycleObject lco)
           
<N extends Comparable<? super N>>
Range<N>
convert(Converter<T,N> c)
           
<N extends Comparable<? super N>>
Range<N>
convert(PatternExtractor<T,N> pe)
           
 boolean equals(Object obj)
           
 T getBegin()
           
 T getEnd()
           
 Comparable<? super T> getLowerBound()
           
 T getLowerEnd()
          provides an unsafe cast to the type at hand (assuming that the bounds represent the same)
 Comparable<? super T> getUpperBound()
           
 T getUpperEnd()
          provides an unsafe cast to the type at hand (assuming that the bounds represent the same)
 int hashCode()
           
 boolean includes(Range<T> range)
           
 Range<T> intersection(Range<T> range)
          a non-null value is returned only if the given ranges do overlap
 boolean isClosedRange()
          a range is 'closed' if both, begin and end, are non-null
 boolean isEmpty()
          a range is 'empty' if no bound is set
 boolean isInclusive()
           
 boolean isInRange(T obj)
           
 boolean isInRangeUnchecked(Object obj)
          convenience method for unchecked calls
 boolean isOpenRange()
          a range is 'open' if it is not closed
 boolean isReal()
          a range is 'real' if there is anything it could include, so it is either an open range or a range where the lowerBound is actually 'less' (or equal if the range is inclusive) than the upperBound
 boolean isTyped(Class<? super T> type)
          returns true only if the embedded comparators - if given - are indeed instances of the type, so that the methods that assume this wouldn't fail
 boolean overlapsWith(Range<T> range)
          requires that both ranges are real and that the bounds are instances of T
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Range

public Range()
a range with effectively no restrictions; any given object would be within the range


Range

public Range(Comparable<? super T> lowerBound,
             Comparable<? super T> upperBound)
both bounds are considered inclusive within the range.


Range

public Range(Comparable<? super T> lowerBound,
             Comparable<? super T> upperBound,
             boolean inclusive)
if either or both (lower- and upperBound) are non-null, they represent a limit that is either inclusive or not depending on the given boolean.

Method Detail

toString

public String toString()
Overrides:
toString in class Object

getLowerBound

public Comparable<? super T> getLowerBound()

getUpperBound

public Comparable<? super T> getUpperBound()

getLowerEnd

public T getLowerEnd()
provides an unsafe cast to the type at hand (assuming that the bounds represent the same)


getUpperEnd

public T getUpperEnd()
provides an unsafe cast to the type at hand (assuming that the bounds represent the same)


getBegin

public T getBegin()
See Also:
getLowerEnd()

getEnd

public T getEnd()
See Also:
getUpperEnd()

isOpenRange

public boolean isOpenRange()
a range is 'open' if it is not closed


isClosedRange

public boolean isClosedRange()
a range is 'closed' if both, begin and end, are non-null


isEmpty

public boolean isEmpty()
a range is 'empty' if no bound is set


isReal

public boolean isReal()
a range is 'real' if there is anything it could include, so it is either an open range or a range where the lowerBound is actually 'less' (or equal if the range is inclusive) than the upperBound


isInclusive

public boolean isInclusive()

isTyped

public boolean isTyped(Class<? super T> type)
returns true only if the embedded comparators - if given - are indeed instances of the type, so that the methods that assume this wouldn't fail

See Also:
getBegin(), getEnd(), getLowerEnd(), getUpperEnd()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

includes

public boolean includes(Range<T> range)

intersection

public Range<T> intersection(Range<T> range)
                                                    throws InconsistentContentException
a non-null value is returned only if the given ranges do overlap

Throws:
InconsistentContentException
See Also:
overlapsWith(Range)

overlapsWith

public boolean overlapsWith(Range<T> range)
                     throws InconsistentContentException
requires that both ranges are real and that the bounds are instances of T

Throws:
InconsistentContentException
See Also:
isTyped(Class)

isInRange

public boolean isInRange(T obj)

accept

public boolean accept(T entry)
Description copied from interface: Filter
returns true only if the given entry is accepted by this filter

Specified by:
accept in interface Filter<T extends Comparable<? super T>>

convert

public <N extends Comparable<? super N>> Range<N> convert(Converter<T,N> c)

convert

public <N extends Comparable<? super N>> Range<N> convert(PatternExtractor<T,N> pe)

isInRangeUnchecked

public boolean isInRangeUnchecked(Object obj)
                           throws ClassCastException
convenience method for unchecked calls

Throws:
ClassCastException

asRange

public Range<Date> asRange(LifeCycleObject lco)


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads