Java Collection Random Element generateMetricsDataWithAllWrongTypes(String metricPostfix, boolean generateRandomTenant, long collectionTime)

Here you can find the source of generateMetricsDataWithAllWrongTypes(String metricPostfix, boolean generateRandomTenant, long collectionTime)

Description

generate Metrics Data With All Wrong Types

License

Apache License

Declaration

public static List<Map<String, Object>> generateMetricsDataWithAllWrongTypes(String metricPostfix,
            boolean generateRandomTenant, long collectionTime) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;

public class Main {
    private static final Random random = new Random();

    public static List<Map<String, Object>> generateMetricsDataWithAllWrongTypes(String metricPostfix,
            boolean generateRandomTenant, long collectionTime) {

        List<Map<String, Object>> metricsList = new ArrayList<Map<String, Object>>();

        // String metric value
        Map<String, Object> testMetric = new TreeMap<String, Object>();
        if (generateRandomTenant) {
            testMetric.put("tenantId", random.nextInt());
        }/*from  w w  w  .j  a  v  a2 s  . c o  m*/
        testMetric.put("metricName", "mzord.string.metric" + metricPostfix);
        testMetric.put("ttlInSeconds", 1234566);
        testMetric.put("unit", "milliseconds");
        testMetric.put("metricValue", "random_string");
        testMetric.put("collectionTime", collectionTime);
        metricsList.add(testMetric);

        // String numeric metric value
        testMetric = new TreeMap<String, Object>();
        if (generateRandomTenant) {
            testMetric.put("tenantId", random.nextInt());
        }
        testMetric.put("metricName", "mzord.string.numeric.metric" + metricPostfix);
        testMetric.put("ttlInSeconds", 1234566);
        testMetric.put("unit", "milliseconds");
        testMetric.put("metricValue", "666");
        testMetric.put("collectionTime", collectionTime);
        metricsList.add(testMetric);

        // boolean metric value
        testMetric = new TreeMap<String, Object>();
        if (generateRandomTenant) {
            testMetric.put("tenantId", random.nextInt());
        }
        testMetric.put("metricName", "mzord.boolean.metric" + metricPostfix);
        testMetric.put("ttlInSeconds", 1234566);
        testMetric.put("unit", "milliseconds");
        testMetric.put("metricValue", true);
        testMetric.put("collectionTime", collectionTime);
        metricsList.add(testMetric);

        return metricsList;
    }
}

Related

  1. chooseElement(Collection elements, T alternative)
  2. chooseRandomThing(Collection possibleroutes)
  3. chooseWithoutCheck(Collection collection, long seed)
  4. generateMetricsDataWithPartialWrongTypes(String metricPostfix, boolean generateRandomTenant, long collectionTime)
  5. getRandom(Collection collection)
  6. getRandomNumber(Collection collection, int number)
  7. nextItem(Collection items, Random random)