|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpslib.WeightedList<T>
public class WeightedList<T>
WeightedList Class
The WeightedArray class allows a list of objects to be stored alongside
an integer weight. Calls to the get()
function will return a random
object from the list, the probability of which is determined by its weight value.
This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library. If not, see http://www.gnu.org/licenses/.
Constructor Summary | |
---|---|
WeightedList(T[] e)
Create a new object instance with the specified list elements and equal weighting |
|
WeightedList(T[] a,
int[] w)
Create a new object instance with the specified list elements and weighting |
Method Summary | |
---|---|
T |
get()
Return a random list element |
java.util.Iterator |
iterator()
Return an iterator for the list |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public WeightedList(T[] e)
e
- list elementspublic WeightedList(T[] a, int[] w)
Negative, zero or absent weight values will set to the default value of 1.
a
- w
- Method Detail |
---|
public final T get()
The probability of each list element being returned is defined by its weight value.
public final java.util.Iterator iterator()
iterator
in interface java.lang.Iterable<T>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |