T
- The weighted object typepublic class WeightedCollection<T extends WeightedObject<?>> extends Object implements Collection<T>
Constructor and Description |
---|
WeightedCollection()
Creates a new
WeightedCollection . |
Modifier and Type | Method and Description |
---|---|
boolean |
add(T object)
Adds the given weighted object to the collection.
|
boolean |
addAll(Collection<? extends T> collection) |
void |
clear() |
boolean |
contains(Object object) |
boolean |
containsAll(Collection<?> collection) |
boolean |
equals(Object obj) |
T |
get(Random rand)
Selects a random value from this list based on their weight.
|
int |
hashCode() |
boolean |
isEmpty() |
Iterator<T> |
iterator() |
boolean |
remove(Object object) |
boolean |
removeAll(Collection<?> collection) |
boolean |
retainAll(Collection<?> collection) |
int |
size() |
Object[] |
toArray() |
<E> E[] |
toArray(E[] array) |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
parallelStream, removeIf, spliterator, stream
public WeightedCollection()
WeightedCollection
.public T get(Random rand)
If the list is empty then null will be returned.
rand
- The random object to use for selectionpublic boolean add(T object)
add
in interface Collection<T extends WeightedObject<?>>
object
- The weighted objectNullPointerException
- If the object is nullpublic boolean addAll(Collection<? extends T> collection)
addAll
in interface Collection<T extends WeightedObject<?>>
public void clear()
clear
in interface Collection<T extends WeightedObject<?>>
public boolean contains(Object object)
contains
in interface Collection<T extends WeightedObject<?>>
public boolean containsAll(Collection<?> collection)
containsAll
in interface Collection<T extends WeightedObject<?>>
public boolean isEmpty()
isEmpty
in interface Collection<T extends WeightedObject<?>>
public Iterator<T> iterator()
iterator
in interface Iterable<T extends WeightedObject<?>>
iterator
in interface Collection<T extends WeightedObject<?>>
public boolean remove(Object object)
remove
in interface Collection<T extends WeightedObject<?>>
public boolean removeAll(Collection<?> collection)
removeAll
in interface Collection<T extends WeightedObject<?>>
public boolean retainAll(Collection<?> collection)
retainAll
in interface Collection<T extends WeightedObject<?>>
public int size()
size
in interface Collection<T extends WeightedObject<?>>
public Object[] toArray()
toArray
in interface Collection<T extends WeightedObject<?>>
public <E> E[] toArray(E[] array)
toArray
in interface Collection<T extends WeightedObject<?>>
public int hashCode()
hashCode
in interface Collection<T extends WeightedObject<?>>
hashCode
in class Object
public boolean equals(Object obj)
equals
in interface Collection<T extends WeightedObject<?>>
equals
in class Object