Package org.jcsp.util.filter
Class FilterHolder
java.lang.Object
org.jcsp.util.filter.FilterHolder
Storage scheme for a set of filters that is dynamically sized and supports insert and remove
operations to keep the filters in a contiguous block.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newFilterHolder
with an intial capacity of 2.FilterHolder
(int initialSize) Constructs a newFilterHolder
with the given initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a filter to the end of the array, possibly enlarging it if it is full.void
Adds a filter at the given index.private void
compact()
Shrinks the array to save space if it is 75% empty.getFilter
(int index) Returns a filter at the given array index.int
Returns the number of filters current installed.private void
Enlarges the size of the array to make room for more filters.void
removeFilter
(int index) Removes a filter at a given index.void
removeFilter
(Filter filter) Removes a filter from the set.
-
Field Details
-
filters
The array of filters. The installed filters are in a block at the start of the array. -
count
private int countNumber of filters currently installed.
-
-
Constructor Details
-
FilterHolder
FilterHolder()Constructs a newFilterHolder
with an intial capacity of 2. -
FilterHolder
FilterHolder(int initialSize) Constructs a newFilterHolder
with the given initial capacity.- Parameters:
initialSize
- the initial size for the array.
-
-
Method Details
-
addFilter
Adds a filter to the end of the array, possibly enlarging it if it is full.- Parameters:
filter
- the filter to add.
-
addFilter
Adds a filter at the given index. If the index is past the end of the array, the filter is placed at the end of the array. If the index is in use, filter is inserted, shifting the existing ones. If necessary, the array may be enlarged.- Parameters:
filter
- the filter to add.index
- the position to add the filter.
-
removeFilter
Removes a filter from the set. The first filter,f
, satisfying the conditionf.equals (filter)
is removed and the remaining filters shifted to close the gap.- Parameters:
filter
- the filter to remove.
-
removeFilter
public void removeFilter(int index) Removes a filter at a given index. The remaining filters are shifted to close the gap.- Parameters:
index
- the array index to remove the filter.
-
getFilter
Returns a filter at the given array index. -
getFilterCount
public int getFilterCount()Returns the number of filters current installed. -
makeSpace
private void makeSpace()Enlarges the size of the array to make room for more filters. Currently the array is doubled in size. -
compact
private void compact()Shrinks the array to save space if it is 75% empty.
-