Example usage for com.google.common.collect SortedMultiset add

List of usage examples for com.google.common.collect SortedMultiset add

Introduction

In this page you can find the example usage for com.google.common.collect SortedMultiset add.

Prototype

@Override
boolean add(E element);

Source Link

Document

Adds a single occurrence of the specified element to this multiset.

Usage

From source file:org.apache.kylin.job.streaming.StreamingTableDataGenerator.java

public static List<String> generate(int recordCount, long startTime, long endTime, String tableName) {
    Preconditions.checkArgument(startTime < endTime);
    Preconditions.checkArgument(recordCount > 0);

    KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
    TableDesc tableDesc = MetadataManager.getInstance(kylinConfig).getTableDesc(tableName);

    SortedMultiset<Long> times = TreeMultiset.create();
    Random r = new Random();
    for (int i = 0; i < recordCount; i++) {
        long t = startTime + (long) ((endTime - startTime) * r.nextDouble());
        times.add(t);
    }//from w  w  w . j  a  va 2 s . c  o m

    List<String> ret = Lists.newArrayList();
    HashMap<String, String> kvs = Maps.newHashMap();
    for (long time : times) {
        kvs.clear();
        kvs.put("timestamp", String.valueOf(time));
        for (ColumnDesc columnDesc : tableDesc.getColumns()) {
            String lowerCaseColumnName = columnDesc.getName().toLowerCase();
            DataType dataType = columnDesc.getType();
            if (dataType.isDateTimeFamily()) {
                //TimedJsonStreamParser will derived minute_start,hour_start,day_start from timestamp
                continue;
            } else if (dataType.isStringFamily()) {
                char c = (char) ('A' + (int) (26 * r.nextDouble()));
                kvs.put(lowerCaseColumnName, String.valueOf(c));
            } else if (dataType.isIntegerFamily()) {
                int v = r.nextInt(10000);
                kvs.put(lowerCaseColumnName, String.valueOf(v));
            } else if (dataType.isNumberFamily()) {
                String v = String.format("%.4f", r.nextDouble() * 100);
                kvs.put(lowerCaseColumnName, v);
            }
        }
        try {
            ret.add(mapper.writeValueAsString(kvs));
        } catch (JsonProcessingException e) {
            logger.error("error!", e);
        }
    }

    return ret;
}

From source file:cc.kave.commons.model.groum.comparator.ExasVectorBuilder.java

private SortedMultiset<PQNode> buildPQNodes(IGroum groum, Node node) {
    SortedMultiset<PQNode> pqNodes = TreeMultiset.create();
    Set<Node> successors = groum.getSuccessors(node);
    int numberOfPredecessors = groum.getPredecessors(node).size();
    pqNodes.add(new PQNode(node, numberOfPredecessors, successors.size()));
    for (Node successor : successors) {
        pqNodes.addAll(buildPQNodes(groum, successor));
    }/*from   w  w w  .  j  av  a  2s .c o m*/
    return pqNodes;
}

From source file:cc.kave.commons.model.groum.comparator.ExasVectorBuilder.java

private SortedMultiset<Path> buildNPaths(IGroum groum, Path base, Node newNode) {
    SortedMultiset<Path> paths = TreeMultiset.create();
    Path extension = base.getExtension(newNode);
    Set<Node> successors = groum.getSuccessors(newNode);

    if (ComputeSubPaths) {
        Path tail = extension;//from   w  w w . java  2s . co m
        do {
            paths.add(tail);
            tail = tail.getTail();
        } while (!tail.isEmpty());
    } else if (successors.isEmpty()) {
        paths.add(extension);
    }

    for (Node suc : successors) {
        paths.addAll(buildNPaths(groum, extension, suc));
    }
    return paths;
}