MCPcopy Create free account
hub / github.com/boxbeam/RedLib / toString

Method toString

src/redempt/redlib/misc/WeightedRandom.java:208–217  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

toStringMethod · 0.95
forEachMethod · 0.80
applyMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected