Converts this WeightedRandom to a String which can be deserialized later @param converter A function to convert the outcomes of this WeightedRandom to strings which can be deserialized later @return The string representing this WeightedRandom
(Function<T, String> converter)
| 206 | * @return The string representing this WeightedRandom |
| 207 | */ |
| 208 | public String toString(Function<T, String> converter) { |
| 209 | JSONList list = new JSONList(); |
| 210 | weights.forEach((k, v) -> { |
| 211 | JSONMap map = new JSONMap(); |
| 212 | map.put("weight", v); |
| 213 | map.put("outcome", converter.apply(k)); |
| 214 | list.add(map); |
| 215 | }); |
| 216 | return list.toString(); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Deserializes a string to create a WeightedRandom |