public class FrequencyEncoder<T> extends Object
null
is added, it is always the first element.
Either object identity
or object
equality
can be used to build the array and count the frequency.Modifier and Type | Class and Description |
---|---|
(package private) static class |
FrequencyEncoder.Entry<T> |
Modifier and Type | Field and Description |
---|---|
protected boolean |
containsNull |
protected Map<T,FrequencyEncoder.Entry<T>> |
map |
Modifier | Constructor and Description |
---|---|
protected |
FrequencyEncoder(Map<T,FrequencyEncoder.Entry<T>> map) |
Modifier and Type | Method and Description |
---|---|
void |
addObject(T object)
Adds an object to the array.
|
static <T> FrequencyEncoder<T> |
createEqualityEncoder()
Creates an encoder that uses
object equality . |
static <T> FrequencyEncoder<T> |
createIdentityEncoder()
Creates an encoder that uses object identity.
|
T[] |
encodeAll(T[] allObjects)
Fills the provided array with the added objects.
|
int |
getIndex(Object object)
Returns the index of an object in the array.
|
int |
getLength()
Returns the number of distinct objects that have been added, i.e., the length of the array.
|
protected final Map<T,FrequencyEncoder.Entry<T>> map
protected boolean containsNull
protected FrequencyEncoder(Map<T,FrequencyEncoder.Entry<T>> map)
public static <T> FrequencyEncoder<T> createIdentityEncoder()
public static <T> FrequencyEncoder<T> createEqualityEncoder()
object equality
.public int getIndex(Object object)
added
before.public int getLength()
public T[] encodeAll(T[] allObjects)
correct length
.