Package net.sf.saxon.z
Class IntRangeToIntMap
- java.lang.Object
-
- net.sf.saxon.z.IntRangeToIntMap
-
- All Implemented Interfaces:
IntToIntMap
public class IntRangeToIntMap extends java.lang.Object implements IntToIntMap
Set of int values. This implementation of IntSet uses a sorted array of integer ranges.
-
-
Constructor Summary
Constructors Constructor Description IntRangeToIntMap(int capacity)
Create an empty map, with given initial capacityIntRangeToIntMap(int[] startPoints, int[] endPoints)
Create an IntRangeSet given the start points and end points of the integer ranges.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEntry(int start, int end, int value)
Add an entry to the map.void
clear()
Clear the map.boolean
contains(int value)
Finds whether a key is present in the map.int
get(int value)
Gets the value for this key.int
getDefaultValue()
Get the default value used to indicate an unused entryint[]
getEndPoints()
Get the end points of the rangesint
getNumberOfRanges()
Get the number of ranges actually in useint[]
getStartPoints()
Get the start points of the rangesboolean
isEmpty()
IntIterator
keyIterator()
Get an iterator over the integer key values held in the hash mapvoid
put(int key, int value)
Adds a key-value pair to the map.boolean
remove(int value)
Removes a key from the map.void
setDefaultValue(int defaultValue)
Set the value to be returned to indicate an unused entryint
size()
Gets the size of the map.java.lang.String
toString()
-
-
-
Constructor Detail
-
IntRangeToIntMap
public IntRangeToIntMap(int capacity)
Create an empty map, with given initial capacity- Parameters:
capacity
- the initial capacity
-
IntRangeToIntMap
public IntRangeToIntMap(int[] startPoints, int[] endPoints)
Create an IntRangeSet given the start points and end points of the integer ranges. The two arrays must be the same length; each must be in ascending order; and the n'th end point must be greater than the n'th start point, and less than the n+1'th start point, for all n.- Parameters:
startPoints
- the start points of the integer rangesendPoints
- the end points of the integer ranges- Throws:
java.lang.IllegalArgumentException
- if the two arrays are different lengths. Other error conditions in the input are not currently detected.
-
-
Method Detail
-
setDefaultValue
public void setDefaultValue(int defaultValue)
Set the value to be returned to indicate an unused entry- Specified by:
setDefaultValue
in interfaceIntToIntMap
- Parameters:
defaultValue
- the value to be returned byget(int)
if no entry exists for the supplied key
-
getDefaultValue
public int getDefaultValue()
Get the default value used to indicate an unused entry- Specified by:
getDefaultValue
in interfaceIntToIntMap
- Returns:
- the value to be returned by
get(int)
if no entry exists for the supplied key
-
clear
public void clear()
Description copied from interface:IntToIntMap
Clear the map.- Specified by:
clear
in interfaceIntToIntMap
-
size
public int size()
Description copied from interface:IntToIntMap
Gets the size of the map.- Specified by:
size
in interfaceIntToIntMap
- Returns:
- the size
-
isEmpty
public boolean isEmpty()
-
contains
public boolean contains(int value)
Description copied from interface:IntToIntMap
Finds whether a key is present in the map.- Specified by:
contains
in interfaceIntToIntMap
- Parameters:
value
- Key- Returns:
- true if the key is mapped
-
get
public int get(int value)
Description copied from interface:IntToIntMap
Gets the value for this key.- Specified by:
get
in interfaceIntToIntMap
- Parameters:
value
- Key- Returns:
- the value, or the default value if not found.
-
remove
public boolean remove(int value)
Description copied from interface:IntToIntMap
Removes a key from the map.- Specified by:
remove
in interfaceIntToIntMap
- Parameters:
value
- Key to remove- Returns:
- true if the value was removed
-
addEntry
public void addEntry(int start, int end, int value)
Add an entry to the map. Ranges of entries must be added in ascending numerical order- Parameters:
start
- the start of the range to be addedend
- the end of the range to be addedvalue
- the value corresponding to this range of integer keys
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getStartPoints
public int[] getStartPoints()
Get the start points of the ranges- Returns:
- the start points
-
getEndPoints
public int[] getEndPoints()
Get the end points of the ranges- Returns:
- the end points
-
getNumberOfRanges
public int getNumberOfRanges()
Get the number of ranges actually in use- Returns:
- the number of ranges
-
put
public void put(int key, int value)
Adds a key-value pair to the map.- Specified by:
put
in interfaceIntToIntMap
- Parameters:
key
- Keyvalue
- Value
-
keyIterator
public IntIterator keyIterator()
Get an iterator over the integer key values held in the hash map- Specified by:
keyIterator
in interfaceIntToIntMap
- Returns:
- an iterator whose next() call returns the key values (in arbitrary order)
-
-