Example usage for java.util HashMap HashMap

List of usage examples for java.util HashMap HashMap

Introduction

In this page you can find the example usage for java.util HashMap HashMap.

Prototype

public HashMap(Map<? extends K, ? extends V> m) 

Source Link

Document

Constructs a new HashMap with the same mappings as the specified Map .

Usage

From source file:com.heliosapm.tsdblite.metric.Trace.java

@SuppressWarnings("javadoc")
public static void main(String[] args) {
    log("Trace Test");
    Map<String, String> tags = new HashMap<String, String>(4);
    tags.put("host", "localhost");
    tags.put("app", "test");
    tags.put("cpu", "" + 1);
    tags.put("type", "combined");
    final Trace trace = new Trace("sys.cpu", tags, false, 34, -1, System.currentTimeMillis());
    log("toString: " + trace);
    String json = JSON.serializeToString(trace);
    log("JSON: " + json);
    final Trace t = JSON.parseToObject(json, Trace.class);
    log("fromJson: " + t);
    log("=====================================");
    final Trace[] traces = new Trace[Constants.CORES];
    final Random r = new Random(System.currentTimeMillis());
    for (int i = 0; i < Constants.CORES; i++) {
        tags = new HashMap<String, String>(4);
        tags.put("host", "localhost");
        tags.put("app", "test");
        tags.put("cpu", "" + i);
        tags.put("type", "combined");
        traces[i] = new Trace("sys.cpu", tags, false, Math.abs(r.nextInt(100)), -1, System.currentTimeMillis());
        log("toString:" + traces[i]);
    }/*  w w w. j  ava  2s . c om*/
    json = JSON.serializeToString(traces);
    log("JSON: " + json);
    Trace[] ts = JSON.parseToObject(json, Trace[].class);
    for (Trace x : ts) {
        log("fromJson: " + x);
    }
}