List of utility methods to do Collection Random Element
T | chooseElement(Collection choose Element return chooseElement((T[]) (elements.toArray()), alternative);
|
Object | chooseRandomThing(Collection> possibleroutes) Function chooseRandomPath -------------------------- This function takes in a set of possible routes and simply chooses a random element from the list. if (possibleroutes == null) { return null; int size = possibleroutes.size(); int item = new Random().nextInt(size); int i = 0; for (Object p : possibleroutes) { if (i == item) ... |
T | chooseWithoutCheck(Collection extends T> collection, long seed) choose Without Check int index = new Random(seed).nextInt(collection.size()); Optional<? extends T> result = collection.stream().skip(index).findFirst(); assert result.isPresent(); return result.get(); |
List | generateMetricsDataWithAllWrongTypes(String metricPostfix, boolean generateRandomTenant, long collectionTime) generate Metrics Data With All Wrong Types List<Map<String, Object>> metricsList = new ArrayList<Map<String, Object>>(); Map<String, Object> testMetric = new TreeMap<String, Object>(); if (generateRandomTenant) { testMetric.put("tenantId", random.nextInt()); testMetric.put("metricName", "mzord.string.metric" + metricPostfix); testMetric.put("ttlInSeconds", 1234566); testMetric.put("unit", "milliseconds"); ... |
List | generateMetricsDataWithPartialWrongTypes(String metricPostfix, boolean generateRandomTenant, long collectionTime) generate Metrics Data With Partial Wrong Types List<Map<String, Object>> metricsList = generateMetricsDataWithAllWrongTypes(metricPostfix, generateRandomTenant, collectionTime); Map<String, Object> testMetric = new TreeMap<String, Object>(); if (generateRandomTenant) { testMetric.put("tenantId", random.nextInt()); testMetric.put("metricName", "mzord.small.numeric.metric" + metricPostfix); testMetric.put("ttlInSeconds", 1234566); ... |
V | getRandom(Collection get Random if (collection.isEmpty()) { return null; int randIdx = (int) Math.round(Math.random() * (collection.size() - 1)); int count = 0; Iterator<V> iterator = collection.iterator(); while (iterator.hasNext()) { V current = iterator.next(); ... |
Set | getRandomNumber(Collection Returns at random a specific number of elements from a collection. List<T> list = new ArrayList<T>(collection); Collections.shuffle(list); return new HashSet<T>(list.subList(0, number)); |
T | nextItem(Collection next Item int randomIndex = random.nextInt(items.size()); int count = 0; for (T item : items) { if (count == randomIndex) return item; count++; return null; ... |
T | oneOf(Collection one Of List<T> list = new ArrayList<T>(array); return list.get(cInt(0, array.size() - 1)); |
K | peekRandom(Collection peek Random int size = collection.size(); if (size == 0) { return null; int index = rnd.nextInt(size); List<K> values = new ArrayList<K>(collection); return values.get(index); |