T - 权重随机获取的对象类型public class WeightRandom<T> extends Object implements Serializable
description
| 限定符和类型 | 类和说明 |
|---|---|
static class |
WeightRandom.WeightObj<T>
带有权重的对象包装
|
| 限定符和类型 | 字段和说明 |
|---|---|
private Random |
random |
private static long |
serialVersionUID |
private TreeMap<Double,T> |
weightMap |
| 构造器和说明 |
|---|
WeightRandom()
构造
|
WeightRandom(Iterable<WeightRandom.WeightObj<T>> weightObjs)
构造
|
WeightRandom(WeightRandom.WeightObj<T> weightObj)
构造
|
WeightRandom(WeightRandom.WeightObj<T>[] weightObjs)
构造
|
| 限定符和类型 | 方法和说明 |
|---|---|
WeightRandom<T> |
add(T obj,
double weight)
增加对象
|
WeightRandom<T> |
add(WeightRandom.WeightObj<T> weightObj)
增加对象权重
|
WeightRandom<T> |
clear()
清空权重表
|
static <T> WeightRandom<T> |
create()
创建权重随机获取器
|
T |
next()
下一个随机对象
|
private static final long serialVersionUID
private final Random random
public WeightRandom()
public WeightRandom(WeightRandom.WeightObj<T> weightObj)
weightObj - 带有权重的对象public WeightRandom(Iterable<WeightRandom.WeightObj<T>> weightObjs)
weightObjs - 带有权重的对象public WeightRandom(WeightRandom.WeightObj<T>[] weightObjs)
weightObjs - 带有权重的对象public static <T> WeightRandom<T> create()
T - 权重随机获取的对象类型WeightRandompublic WeightRandom<T> add(T obj, double weight)
obj - 对象weight - 权重public WeightRandom<T> add(WeightRandom.WeightObj<T> weightObj)
weightObj - 权重对象public WeightRandom<T> clear()
public T next()
Copyright © 2020. All rights reserved.