Example usage for com.google.common.collect TreeMultiset create

List of usage examples for com.google.common.collect TreeMultiset create

Introduction

In this page you can find the example usage for com.google.common.collect TreeMultiset create.

Prototype

public static <E extends Comparable> TreeMultiset<E> create() 

Source Link

Document

Creates a new, empty multiset, sorted according to the elements' natural order.

Usage

From source file:eu.thebluemountain.customers.dctm.brownbag.badcontentslister.Main.java

public static void main(String[] args) {
    try {/*from  w w  w .  java  2s .  c  om*/
        Map<Command, Optional<String>> cmds = Command.parse(args);
        if ((cmds.containsKey(Command.HELP)) || (!cmds.containsKey(Command.CONFIG))) {
            usage();
            return;
        }
        final JDBCConfig config = config(cmds.get(Command.CONFIG).get());

        String pwd = config.password.orNull();
        if (null == pwd) {
            Optional<String> opt = passwordOf("database", config.user);
            if (!opt.isPresent()) {
                throw new ExitException(RetCode.ERR_CANCELLED);
            }
            pwd = opt.get();
        }
        try (JDBCConnection from = create(config, pwd); CSVWriter writer = makeLog(config.user)) {
            Stopwatch watch = Stopwatch.createStarted();
            Stores stores = StoresReader.STORESREADER.apply(from);
            System.out.println("spent " + watch.stop() + " to load stores");
            final Function<DecoratedContent, Checks.Result> checker = Checks.checker(stores);
            final Multiset<Checks.Code> codes = TreeMultiset.create();
            watch.reset().start();
            ResponseUI rui = ResponseUI.create(1024, 64);
            try (CloseableIterator<DecoratedContent> it = DCReader.reader(from, stores)) {
                long count = 0L;
                while (it.hasNext()) {
                    DecoratedContent dc = it.next();
                    count++;
                    final Checks.Result result = checker.apply(dc);
                    assert null != result;
                    rui.onResponse(result);
                    final Checks.Code code = result.code;
                    codes.add(code);
                    if (code != Checks.Code.OK) {
                        // we've got an error then ....
                        writer.writeError(dc, result);
                    }
                }
                rui.finish();
                System.out.println("spent " + watch.stop() + " to read " + count + " d.c.");
                System.out.println("stats: " + codes);
                System.out.println("bye");
            }
        }
    } catch (SQLException e) {
        e.printStackTrace(System.err);
        System.err.flush();
        System.out.println();
        usage();
        System.exit(RetCode.ERR_SQL.ordinal());
    } catch (ExitException e) {
        e.exit();
    } catch (RuntimeException | IOException e) {
        e.printStackTrace(System.err);
        System.err.flush();
        System.out.println();
        usage();
        System.exit(RetCode.ERR_OTHER.ordinal());
    }
}

From source file:com.totsp.tom.util.Statistics.java

public Statistics() {
    inner = TreeMultiset.create();
}

From source file:RAI.State.java

public State(Hypothesis<T> h, T d, int id) {
    this.id = id;
    hypothesis = h;// ww  w. ja v a2  s .co m
    outgoing = TreeMultiset.create();
    ingoing = TreeMultiset.create();
    mu = null;
    data = d;
    color = Color.WHITE;
    pairs = new HashSet<>();
}

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  .java 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:org.softinica.maven.jmeter.report.analyser.ThroughputAnalyzer.java

@Override
protected JFreeChart createChart(PageDefinition definition, Input input) {
    Map<String, Multiset<Long>> allSeries = new HashMap<String, Multiset<Long>>();
    for (Sample sample : input.getSamples()) {
        Multiset<Long> rps = allSeries.get(sample.getLabel());
        if (rps == null) {
            rps = TreeMultiset.create();
            allSeries.put(sample.getLabel(), rps);
        }/*  www. j  a v  a2s  .  c o  m*/
        rps.add(((sample.getTimestamp() + (long) sample.getValue()) / 1000) * 1000);
    }
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    for (String label : allSeries.keySet()) {
        Multiset<Long> rps = allSeries.get(label);
        TimeSeries series = new TimeSeries(label);
        for (Long key : rps) {
            series.addOrUpdate(new Second(new Date(key)), rps.count(key));
        }
        dataset.addSeries(series);
    }

    return ChartFactory.createTimeSeriesChart(definition.getTitle(), "Time", "Requests/second", dataset);
}

From source file:com.github.nmorel.gwtjackson.guava.client.deser.TreeMultisetJsonDeserializer.java

@Override
protected TreeMultiset<T> newCollection() {
    return TreeMultiset.create();
}

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;//  ww  w . j  a v a2s.  c  o 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;
}

From source file:com.github.nmorel.gwtjackson.guava.client.deser.SortedMultisetJsonDeserializer.java

@Override
protected SortedMultiset<T> newCollection() {
    return TreeMultiset.create();
}

From source file:gmjonker.util.BoundedTreeMultiset.java

public static <E1 extends Comparable> TreeMultiset<E1> create() {
    return TreeMultiset.create();
}

From source file:com.cloudera.oryx.rdf.common.rule.NumericDecision.java

static List<Decision> numericDecisionsFromExamples(int featureNumber, Iterable<Example> examples,
        int suggestedMaxSplitCandidates) {
    Multiset<Float> sortedFeatureValueCounts = TreeMultiset.create();
    StorelessUnivariateStatistic mean = new Mean();
    int numExamples = 0;
    for (Example example : examples) {
        NumericFeature feature = (NumericFeature) example.getFeature(featureNumber);
        if (feature == null) {
            continue;
        }//  w  ww  . j av a  2s .  c  om
        numExamples++;
        float value = feature.getValue();
        sortedFeatureValueCounts.add(value, 1);
        mean.increment(value);
    }

    // Make decisions from split points that divide up input into roughly equal amounts of examples
    List<Decision> decisions = Lists.newArrayListWithExpectedSize(suggestedMaxSplitCandidates);
    int approxExamplesPerSplit = FastMath.max(1, numExamples / suggestedMaxSplitCandidates);
    int examplesInSplit = 0;
    float lastValue = Float.NaN;
    // This will iterate in order of value by nature of TreeMap
    for (Multiset.Entry<Float> entry : sortedFeatureValueCounts.entrySet()) {
        float value = entry.getElement();
        if (examplesInSplit >= approxExamplesPerSplit) {
            decisions.add(
                    new NumericDecision(featureNumber, (value + lastValue) / 2.0f, (float) mean.getResult()));
            examplesInSplit = 0;
        }
        examplesInSplit += entry.getCount();
        lastValue = value;
    }

    // The vital condition here is that if decision n decides an example is positive, then all subsequent
    // decisions in the list will also find it positive. So we need to order from highest threshold to lowest
    Collections.reverse(decisions);
    return decisions;
}