public class TopIntBooleanCollection extends Object
This container allows you to hold the top n value-object-pairs. If the
sortAscending flag is set, the best values are the lowest of the
collection. If the flag is set to false, the highest values are used as best.
Note that all value-object-pairs with a value worse than the nth best element are discarded.
Note that the values array is sorted ascending or descending
relying on the value of the sortAscending flag. The elements of the
objects array are sorted associated to their values in the
values array.
Note that this class has been generated using the class
TopCollectionClassGenerator. If changes to this class are necessary,
they should be made inside the generator class.
| Modifier and Type | Field and Description |
|---|---|
boolean[] |
objects
An array containing the objects associated to the n best values seen by
this container.
|
private int |
size
current size of this container.
|
private boolean |
sortAscending
Flag defining the order of the value elements in this container.
|
int[] |
values
An array containing the n best values seen by this container.
|
| Constructor and Description |
|---|
TopIntBooleanCollection(int n,
boolean sortAscending)
Creates a container which holds the n best int values and the objects
associated with them.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(int value,
boolean object)
Adds the given value and the object associated with to the container if
the given value is inside the top n values.
|
void |
clear()
Clears the container.
|
private int |
findPosition(int value)
Searches for the position of the given value inside the
values
array. |
private int |
findPosition(int value,
int startPosition,
int endPosition)
Searches for the position of the given value inside a sub array of the
values array. |
boolean[] |
getObjects()
Returns the array of objects associated to the best values.
|
int[] |
getValues()
Returns the array of the n best values.
|
boolean |
pop()
Pops the first object (the one with the best value) from the Container.
|
void |
remove(int index)
Removes the value with the given index and its associated object from the
container.
|
int |
size()
Returns the size of this container.
|
boolean[] |
toArray()
Returns the array of objects associated to the values.
|
public int[] values
An array containing the n best values seen by this container.
Note that the array has the size with which this container has
been constructed. If you want to iterate through the best values known by
this container you should iterate from 0 to the size() of the
container and not to the end of this array.
public boolean[] objects
An array containing the objects associated to the n best values seen by this container.
Note that the array has the size with which this container has
been constructed. If you want to iterate through the objects associated
to the best values known by this container you should iterate from 0 to
the size() of the container and not to the end of this array.
private int size
current size of this container.
private boolean sortAscending
Flag defining the order of the value elements in this container. If it is true the values are ordered ascending and the container will keep only the lowest values. If it is false the values are order descending and the container will keep only the highest values.
public TopIntBooleanCollection(int n,
boolean sortAscending)
Creates a container which holds the n best int values and the objects associated with them. Which int values are interpreted as the best is defined by the given flag.
n - The maximum number of elements which shall be stored by this
container.sortAscending - If this flag is true the lowest int value will be
interpreted as the best value. If it is false the highest
int value is interpreted as the best value.public boolean add(int value,
boolean object)
Adds the given value and the object associated with to the container if the given value is inside the top n values.
value - The value which defines if the given element is inside the top
n.object - The object associated to the given value.private int findPosition(int value)
Searches for the position of the given value inside the values
array.
value - The value for which the position inside the array should be
found.values array if the
given value is not inside the top n values.private int findPosition(int value,
int startPosition,
int endPosition)
Searches for the position of the given value inside a sub array of the
values array.
This method implements a recursive binary search.
value - The value for which the position inside the array should be
found.startPosition - The index of the first element of the sub array.endPosition - The index of the last element of the sub array.public boolean[] toArray()
Returns the array of objects associated to the values.
public int[] getValues()
Returns the array of the n best values.
Note that this is the original array and not a copy.
public boolean[] getObjects()
Returns the array of objects associated to the best values.
Note that this is the original array and not a copy.
public int size()
Returns the size of this container.
public void clear()
Clears the container.
public void remove(int index)
Removes the value with the given index and its associated object from the container.
index - public boolean pop()
Pops the first object (the one with the best value) from the Container. In other words, removes and returns the first object of this container.
NoSuchElementException - - If this container is empty.Copyright © 2015–2020. All rights reserved.