Interface Location
- All Known Subinterfaces:
RichLocation
- All Known Implementing Classes:
AbstractLocation
,AbstractLocationDecorator
,AbstractRangeLocation
,BetweenLocation
,CircularLocation
,CompoundRichLocation
,EmptyRichLocation
,FuzzyLocation
,FuzzyPointLocation
,MergeLocation
,MultiSourceCompoundRichLocation
,PointLocation
,RangeLocation
,SimpleRichLocation
The location will contain some indices between getMin and getMax inclusive.
It is not required to contain all indices within this range. It is meant
to contain the indices returned by the getMin or getMax. In the event that
an operation would produce an
invalid or nonsensical range, Location.empty
should be returned.
Location objects are always immutable.
Working with locations
Locations can be constructed in a number of ways:
Location l1 = LocationTools.makeLocation(10, 20); // Makes a RangeLocation Location l2 = LocationTools.makeLocation(25, 25); // Makes a PointLocation Location l3 = LocationTools.union(l1, l2); // Construct a non-contiguous // location containing the // points from l1 and l2
- Author:
- Matthew Pocock, Thomas Down
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionReturn an Iterator over the set of maximal contiguous sub-locations.boolean
contains
(int p) Checks if this location contains a point.boolean
Checks if this location contains the other.boolean
Checks if this location is equivalent to the other.getDecorator
(Class decoratorClass) Checks the decorator chain for an instance ofdecoratorClass and return it if found.int
getMax()
The maximum position contained.int
getMin()
The minimum position contained.Returns a Location that contains all points common to both ranges.boolean
Determine if a Location is contiguous.newInstance
(Location loc) Create a new instance of Location with all of the same decorators as this instance but with the data stored inloc
.boolean
Checks if these two locations overlap, using this location's concept of overlapping.symbols
(SymbolList seq) Return the symbols in a sequence that fall within this range.translate
(int dist) Create a location that is a translation of this location.Return a Location containing all points in either ranges.
-
Field Details
-
empty
TheLocation
which contains no points.This object contains nothing. Its minimum value is Integer.MAX_VALUE. Its maximum value is Integer.MIN_VALUE. It overlaps nothing. It is equal to nothing. Intersection results in the empty range. Union results in the argument range. Symbols returns an empty array.
Every day, in every way, empty becomes more and more boring.
-
full
TheLocation
which contains all points.This object contains every point. It's minimum value is Integer.MIN_VALUE, and it's maximum value is Integer.MAX_VALUE. It overlaps and contains everything.
-
naturalOrder
Comparator which orders Locations naturally. Locations are sorted primarily on the basis of theirgetMin()
value. In cases where that is equal, they are secondarily sorted bygetMax()
value.
-
-
Method Details
-
newInstance
Create a new instance of Location with all of the same decorators as this instance but with the data stored inloc
.The default behavior is to return
loc unchanged. If the class is a location decorator then it should instantiate an instance of the same type that decoratesloc
.- Parameters:
loc
- the Location to use as template- Returns:
- a Location instance based on loc with the same decorators as the current instance
-
getDecorator
Checks the decorator chain for an instance ofdecoratorClass and return it if found.The default behavior is to return null. If the current object is a decorator and is an instance of
decoratorClass it should return itself. Otherwise, the decorator should chain this method onto the instance it wraps.- Parameters:
decoratorClass
- the Class to check- Returns:
- a Location if an instance of this class is present in the decorator chain and null otherwise.
-
getMin
int getMin()The minimum position contained.WARNING: The location will not contain every point between
getMin()
andgetMax()
ifisContiguous()
is false. IfisContiguous()
does return false you should use theIterator
returned byblockIterator()
to iterate over the minimum set of contiguous blocks that make up thisLocation
- Returns:
- the minimum position contained
-
getMax
int getMax()The maximum position contained.WARNING: The location will not contain every point between
getMin()
andgetMax()
ifisContiguous()
is false. IfisContiguous()
does return false you should use theIterator
returned byblockIterator()
to iterate over the minimum set of contiguous blocks that make up thisLocation
- Returns:
- the maximum position contained
-
overlaps
Checks if these two locations overlap, using this location's concept of overlapping.Abstractly, two locations overlap if they both contain any point.
- Parameters:
l
- the Location to check- Returns:
- true if they overlap, otherwise false
-
contains
Checks if this location contains the other.Abstractly, a location contains another if every point in the other location is contained within this one.
- Parameters:
l
- the Location to check- Returns:
- true if this contains l, otherwise false
-
contains
Checks if this location contains a point.- Parameters:
p
- the point to check- Returns:
- true if this contains p, otherwise false
-
equals
Checks if this location is equivalent to the other.Abstractly, a location is equal to another if for every point in one it is also in the other. This is equivalent to a.contains(b) invalid input: '&'invalid input: '&' b.contains(a). You should call LocationTools.areEqual after casting l to Location.
-
intersection
Returns a Location that contains all points common to both ranges.- Parameters:
l
- the Location to intersect with- Returns:
- a Location containing all points common to both, or the empty range if there are no such points
-
union
Return a Location containing all points in either ranges.- Parameters:
l
- the Location to union with- Returns:
- a Location representing the union
-
symbols
Return the symbols in a sequence that fall within this range.- Parameters:
seq
- the SymbolList to process- Returns:
- the SymbolList containing the symbols in seq in this range
-
translate
Create a location that is a translation of this location.- Parameters:
dist
- the distance to translate (to the right)
-
isContiguous
boolean isContiguous()Determine if a Location is contiguous.- Returns:
true
if and only if this Location contains every point frommin
tomax
inclusive.
-
blockIterator
Return an Iterator over the set of maximal contiguous sub-locations.Given any location, it can be considered to contain zero or more maximal contiguous blocks of width 1 or greater. The empty location is composed from nothing. A contiguous location is composed from itself. A non-contiguous location is composed from contiguous blocks seperated by gaps.
This method should return an Iterator over these maximally contiguous blocks starting with the left-most block, and finishing at the right-most block.
- Returns:
- an Iterator over Location objects that are the maximally contiguous set of locations contained within this location
-