Example usage for com.google.common.collect Maps newTreeMap

List of usage examples for com.google.common.collect Maps newTreeMap

Introduction

In this page you can find the example usage for com.google.common.collect Maps newTreeMap.

Prototype

public static <K extends Comparable, V> TreeMap<K, V> newTreeMap() 

Source Link

Document

Creates a mutable, empty TreeMap instance using the natural ordering of its elements.

Usage

From source file:org.apache.druid.java.util.common.io.smoosh.SmooshedFileMapper.java

public static SmooshedFileMapper load(File baseDir) throws IOException {
    File metaFile = FileSmoosher.metaFile(baseDir);

    BufferedReader in = null;// w w  w.j  a va  2 s .  c o m
    try {
        in = new BufferedReader(new InputStreamReader(new FileInputStream(metaFile), StandardCharsets.UTF_8));

        String line = in.readLine();
        if (line == null) {
            throw new ISE("First line should be version,maxChunkSize,numChunks, got null.");
        }

        String[] splits = line.split(",");
        if (!"v1".equals(splits[0])) {
            throw new ISE("Unknown version[%s], v1 is all I know.", splits[0]);
        }
        if (splits.length != 3) {
            throw new ISE("Wrong number of splits[%d] in line[%s]", splits.length, line);
        }
        final Integer numFiles = Integer.valueOf(splits[2]);
        List<File> outFiles = Lists.newArrayListWithExpectedSize(numFiles);

        for (int i = 0; i < numFiles; ++i) {
            outFiles.add(FileSmoosher.makeChunkFile(baseDir, i));
        }

        Map<String, Metadata> internalFiles = Maps.newTreeMap();
        while ((line = in.readLine()) != null) {
            splits = line.split(",");

            if (splits.length != 4) {
                throw new ISE("Wrong number of splits[%d] in line[%s]", splits.length, line);
            }
            internalFiles.put(splits[0], new Metadata(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]),
                    Integer.parseInt(splits[3])));
        }

        return new SmooshedFileMapper(outFiles, internalFiles);
    } finally {
        Closeables.close(in, false);
    }
}

From source file:org.artifactory.info.HostPropInfo.java

/**
 * Sets the map with all the host property names and values
 *///  w ww . j  a  v  a 2s . co m
private void setPropertyMap() {
    propertyMap = Maps.newTreeMap();
    propertyMap.put("os.arch", systemBean.getArch());
    propertyMap.put("os.name", systemBean.getName());
    propertyMap.put("os.version", systemBean.getVersion());
    propertyMap.put("Available Processors", Integer.toString(systemBean.getAvailableProcessors()));
    MemoryUsage heapMemoryUsage = memoryBean.getHeapMemoryUsage();
    propertyMap.put("Heap Memory Usage-Commited", Long.toString(heapMemoryUsage.getCommitted()));
    propertyMap.put("Heap Memory Usage-Init", Long.toString(heapMemoryUsage.getInit()));
    propertyMap.put("Heap Memory Usage-Max", Long.toString(heapMemoryUsage.getMax()));
    propertyMap.put("Heap Memory Usage-Used", Long.toString(heapMemoryUsage.getUsed()));
    MemoryUsage nonHeapMemoryUsage = memoryBean.getNonHeapMemoryUsage();
    propertyMap.put("Non-Heap Memory Usage-Commited", Long.toString(nonHeapMemoryUsage.getCommitted()));
    propertyMap.put("Non-Heap Memory Usage-Init", Long.toString(nonHeapMemoryUsage.getInit()));
    propertyMap.put("Non-Heap Memory Usage-Max", Long.toString(nonHeapMemoryUsage.getMax()));
    propertyMap.put("Non-Heap Memory Usage-Used", Long.toString(nonHeapMemoryUsage.getUsed()));
}

From source file:com.netflix.ice.processor.TagGroupWriter.java

TagGroupWriter(String name) throws Exception {

    dbName = DB_PREFIX + name;//from   w ww  .j ava2s . c om
    file = new File(config.localDir, dbName);
    logger.info("creating TagGroupWriter for " + file);
    AwsUtils.downloadFileIfNotExist(config.workS3BucketName, config.workS3BucketPrefix, file);

    if (file.exists()) {
        DataInputStream in = new DataInputStream(new FileInputStream(file));
        try {
            tagGroups = TagGroup.Serializer.deserializeTagGroups(config, in);
        } finally {
            if (in != null)
                in.close();
        }
    } else {
        tagGroups = Maps.newTreeMap();
    }
}

From source file:reconcile.hbase.query.MeasureQualifierSizeDistribution.java

/**
 * Just a generic print function given an iterator. Not necessarily just for printing a single row
 *
 * @param scanner//from  w  w  w  .  j  a va  2 s.  c o m
 * @throws IOException
 */
public static void printRow(ResultScanner scanner, int tick) throws IOException {
    // iterates through and prints
    int rows = 0;
    Map<Integer, Integer> mbMap = Maps.newTreeMap();
    Map<Integer, Integer> kbMap = Maps.newTreeMap();

    Timer t = new Timer(tick);
    for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
        t.increment();
        rows++;
        String s = DocSchema.getColumn(rr, family, qual);
        int kb = MeasureRowSizeDistribution.getKB(s.length());
        int mb = MeasureRowSizeDistribution.getMB(s.length());
        MapUtil.addCount(kbMap, kb);
        MapUtil.addCount(mbMap, mb);
        // print out the row we found and the columns we were looking for
    }

    System.out.println("mb size:");
    for (int k : mbMap.keySet()) {
        System.out.println(k + ": " + mbMap.get(k));
    }

    System.out.println("kb size:");
    for (int k : kbMap.keySet()) {
        System.out.println(k + ": " + kbMap.get(k));
    }
    System.out.println("total rows: " + rows);
    t.end();

}

From source file:org.apache.gobblin.data.management.dataset.SimpleDatasetHierarchicalPrioritizer.java

public static Comparator<Requestor<SimpleDatasetRequest>> createRequestorComparator(State state)
        throws IOException {
    TreeMap<Integer, Pattern> tiers = Maps.newTreeMap();

    Matcher matcher;//w w w  .j av  a2  s .c  o  m
    for (Map.Entry<Object, Object> entry : state.getProperties().entrySet()) {
        if (entry.getKey() instanceof String && entry.getValue() instanceof String
                && (matcher = TIER_PATTERN.matcher((String) entry.getKey())).matches()) {
            int tier = Integer.parseInt(matcher.group(1));
            String regex = (String) entry.getValue();
            tiers.put(tier, Pattern.compile(regex));
        }
    }

    return new SimpleDatasetHierarchicalPrioritizer.TierComparator(tiers);
}

From source file:org.graylog2.indexer.results.TermsHistogramResult.java

public TermsHistogramResult(@Nullable DateHistogramAggregation result, String originalQuery, String builtQuery,
        long size, long tookMs, Searches.DateHistogramInterval interval, List<String> fields) {
    super(originalQuery, builtQuery, tookMs);
    this.size = size;
    this.interval = interval;
    this.result = Maps.newTreeMap();
    this.terms = new HashSet<>();

    if (result != null) {
        for (DateHistogramAggregation.DateHistogram histogram : result.getBuckets()) {
            final DateTime keyAsDate = new DateTime(histogram.getKey());
            final TermsAggregation termsAggregation = histogram.getFilterAggregation(Searches.AGG_FILTER)
                    .getTermsAggregation(Searches.AGG_TERMS);
            final MissingAggregation missingAgregation = histogram.getMissingAggregation("missing");
            final TermsResult termsResult = new TermsResult(termsAggregation, missingAgregation.getMissing(),
                    histogram.getCount(), "", "", tookMs, fields);

            this.terms.addAll(termsResult.getTerms().keySet());
            this.result.put(keyAsDate.getMillis() / 1000L, termsResult);
        }// w ww. j av a  2s  .  co  m
    }
}

From source file:org.smartdeveloperhub.vocabulary.language.util.LocalizedProperties.java

public LocalizedProperties() {
    this.properties = Maps.newTreeMap();
}

From source file:com.palantir.atlasdb.keyvalue.impl.AssertLockedKeyValueService.java

@Override
public void put(String tableName, Map<Cell, byte[]> values, long timestamp) {

    if (tableName.equals(TransactionConstants.TRANSACTION_TABLE)) {
        SortedMap<LockDescriptor, LockMode> mapToAssertLockHeld = Maps.newTreeMap();
        SortedMap<LockDescriptor, LockMode> mapToAssertLockNotHeld = Maps.newTreeMap();
        for (Map.Entry<Cell, byte[]> e : values.entrySet()) {
            if (Arrays.equals(e.getValue(),
                    TransactionConstants.getValueForTimestamp(TransactionConstants.FAILED_COMMIT_TS))) {
                mapToAssertLockNotHeld.put(AtlasRowLockDescriptor.of(tableName, e.getKey().getRowName()),
                        LockMode.READ);// w w  w .  ja v a2s  .c  o  m
            } else {
                mapToAssertLockHeld.put(AtlasRowLockDescriptor.of(tableName, e.getKey().getRowName()),
                        LockMode.READ);
            }
        }

        try {
            if (!mapToAssertLockHeld.isEmpty()) {
                LockRequest request = LockRequest.builder(mapToAssertLockHeld).doNotBlock()
                        .lockAsManyAsPossible().build();
                LockRefreshToken lock = lockService.lockAnonymously(request);
                Validate.isTrue(lock == null, "these should already be held");
            }

            if (!mapToAssertLockNotHeld.isEmpty()) {
                LockRequest request = LockRequest.builder(mapToAssertLockNotHeld).doNotBlock().build();
                LockRefreshToken lock = lockService.lockAnonymously(request);
                Validate.isTrue(lock != null, "these should already be waited for");
            }
        } catch (InterruptedException e) {
            throw Throwables.throwUncheckedException(e);
        }
    }

    super.put(tableName, values, timestamp);
}

From source file:org.sonatype.nexus.yum.internal.capabilities.GenerateMetadataCapabilityConfiguration.java

public GenerateMetadataCapabilityConfiguration(final String repository, final Map<String, String> aliases,
        final boolean processDeletes, final long deleteProcessingDelay, final String yumGroupsDefinitionFile) {
    super(repository);
    this.aliases = Maps.newTreeMap();
    this.aliases.putAll(checkNotNull(aliases));
    this.processDeletes = processDeletes;
    this.deleteProcessingDelay = deleteProcessingDelay;
    this.yumGroupsDefinitionFile = yumGroupsDefinitionFile;
}

From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.draftv3.DraftV3PropertiesSyntaxChecker.java

@Override
protected void extraChecks(final ProcessingReport report, final MessageBundle bundle, final SchemaTree tree)
        throws ProcessingException {
    final SortedMap<String, JsonNode> map = Maps.newTreeMap();
    map.putAll(JacksonUtils.asMap(tree.getNode().get(keyword)));

    String member;/*from  w w w .j  av a 2s.c o m*/
    JsonNode required;
    NodeType type;

    for (final Map.Entry<String, JsonNode> entry : map.entrySet()) {
        member = entry.getKey();
        required = entry.getValue().get("required");
        if (required == null)
            continue;
        type = NodeType.getNodeType(required);
        if (type != NodeType.BOOLEAN) {
            report.error(newMsg(tree, bundle, "draftv3.properties.required.incorrectType")
                    .putArgument("property", member).putArgument("found", type)
                    .put("expected", NodeType.BOOLEAN));
        }
    }
}