List of usage examples for com.google.common.collect Maps newTreeMap
public static <K extends Comparable, V> TreeMap<K, V> newTreeMap()
From source file:com.google.dart.tools.debug.core.coverage.CoverageManager.java
@VisibleForTesting public static TreeMap<Integer, Integer> parseHitMap(JSONObject coverageEntry) throws Exception { TreeMap<Integer, Integer> hitMap = Maps.newTreeMap(); JSONArray hitsArray = coverageEntry.getJSONArray("hits"); for (int j = 0; j < hitsArray.length() / 2; j++) { int line = hitsArray.getInt(2 * j + 0); int hits = hitsArray.getInt(2 * j + 1); Integer prevHits = hitMap.get(line); if (prevHits != null) { hits += prevHits.intValue(); }/*from w ww . j a v a 2 s. c o m*/ hitMap.put(line, hits); } return hitMap; }
From source file:org.apache.shindig.gadgets.http.CacheKeyBuilder.java
public CacheKeyBuilder() { this.paramMap = Maps.newTreeMap(); this.legacyParams = new Object[NUM_LEGACY_PARAMS]; }
From source file:org.apache.pulsar.common.stats.Metrics.java
protected Metrics(Map<String, String> unmodifiableDimensionMap) { this.metrics = Maps.newTreeMap(); this.dimensions = unmodifiableDimensionMap; }
From source file:com.astonish.dropwizard.routing.migrations.RoutingDbCommand.java
public RoutingDbCommand(RoutingDatabaseConfiguration<T> strategy, Class<T> configurationClass) { super("routingdb", "Run database migration tasks", strategy, configurationClass); this.subcommands = Maps.newTreeMap(); addSubcommand(new RoutingDbCalculateChecksumCommand<>(strategy, configurationClass)); addSubcommand(new RoutingDbClearChecksumsCommand<>(strategy, configurationClass)); addSubcommand(new RoutingDbDropAllCommand<>(strategy, configurationClass)); addSubcommand(new RoutingDbDumpCommand<>(strategy, configurationClass)); addSubcommand(new RoutingDbFastForwardCommand<>(strategy, configurationClass)); addSubcommand(new RoutingDbGenerateDocsCommand<>(strategy, configurationClass)); addSubcommand(new RoutingDbLocksCommand<>(strategy, configurationClass)); addSubcommand(new RoutingDbMigrateCommand<>(strategy, configurationClass)); addSubcommand(new RoutingDbPrepareRollbackCommand<>(strategy, configurationClass)); addSubcommand(new RoutingDbRollbackCommand<>(strategy, configurationClass)); addSubcommand(new RoutingDbStatusCommand<>(strategy, configurationClass)); addSubcommand(new RoutingDbTagCommand<>(strategy, configurationClass)); addSubcommand(new RoutingDbTestCommand<>(strategy, configurationClass)); }
From source file:com.metamx.common.io.smoosh.SmooshedFileMapper.java
public static SmooshedFileMapper load(File baseDir) throws IOException { File metaFile = FileSmoosher.metaFile(baseDir); BufferedReader in = null;/*from w w w . j a v a 2 s . co m*/ try { in = new BufferedReader(new InputStreamReader(new FileInputStream(metaFile), Charsets.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.graylog2.indexer.results.DateHistogramResult.java
@Override public Map<Long, Long> getResults() { Map<Long, Long> results = Maps.newTreeMap(); for (Histogram.Bucket bucket : result.getBuckets()) { final DateTime keyAsDate = (DateTime) bucket.getKey(); results.put(keyAsDate.getMillis() / 1000L, bucket.getDocCount()); }/*from ww w . j a v a 2 s. com*/ return results; }
From source file:org.apache.kylin.storage.cache.StreamSQLResult.java
public StreamSQLResult(List<ITuple> rows, Range<Long> timeCovered, TblColRef partitionCol) { sortedRows = Maps.newTreeMap(); for (ITuple row : rows) { if (partitionCol != null) { long t = Tuple.getTs(row, partitionCol); //will only cache rows that are within the time range if (timeCovered.contains(t)) { if (!this.sortedRows.containsKey(t)) { this.sortedRows.put(t, Lists.newArrayList(row)); } else { this.sortedRows.get(t).add(row); }// ww w . j a va2s . c o m } } else { if (!this.sortedRows.containsKey(0L)) { this.sortedRows.put(0L, Lists.<ITuple>newArrayList()); } this.sortedRows.get(0L).add(row); } } this.timeCovered = timeCovered; }
From source file:org.apache.bookkeeper.clients.impl.internal.ProtocolInternalUtils.java
public static HashStreamRanges createActiveRanges(GetActiveRangesResponse response) { TreeMap<Long, RangeProperties> ranges = Maps.newTreeMap(); long lastEndKey = Long.MIN_VALUE; for (RelatedRanges rr : response.getRangesList()) { RangeProperties range = rr.getProps(); long startKey = range.getStartHashKey(); long endKey = range.getEndHashKey(); checkState(lastEndKey == startKey, "Invalid range key found : expected = %s, actual = %s", lastEndKey, startKey);//from w w w .j a va 2s .c o m ranges.put(startKey, range); lastEndKey = endKey; } checkState(Long.MAX_VALUE == lastEndKey, "Missing key range [%s - %s)", lastEndKey, Long.MAX_VALUE); checkState(ranges.size() > 0, "No active range found"); return HashStreamRanges.ofHash(RangeKeyType.HASH, ranges); }
From source file:co.mitro.core.server.data.DBServerVisibleSecret.java
public static void fillRecentAuditActions(Manager manager, Collection<? extends Secret> secrets) throws SQLException { Map<Integer, Secret> secretIdToSecret = Maps.newTreeMap(); for (Secret s : secrets) { secretIdToSecret.put(s.secretId, s); }//from www . j a v a 2 s . c o m if (secretIdToSecret.isEmpty()) { return; } String getRecentActions = "SELECT target_sv_secret, MAX(\"timestampMs\"), action, identity.name " + "FROM audit " + "JOIN identity ON (uid = identity.id) " + "WHERE target_sv_secret IN (" + Joiner.on(',').join(secretIdToSecret.keySet()) + ") " + " AND action IN ('GET_SECRET_WITH_CRITICAL', 'ADD_SECRET') " + "GROUP BY target_sv_secret, action, identity.name " + "ORDER BY max(\"timestampMs\") DESC"; // A query that looks more like this should be faster and not return duplicates, but for some reason takes way longer: /* select t1.* from audit as t1 LEFT OUTER JOIN audit as t2 ON (t1.target_sv_secret = t2.target_sv_secret) and ((t1."timestampMs" < t2."timestampMs")) WHERE t2.target_sv_secret IS NULL AND t1.target_sv_secret in (188,338); */ // Alternatively we should use DISTINCT ON() but that is unsupported on H2. List<String[]> actionsResults = Lists.newArrayList(manager.identityDao.queryRaw(getRecentActions)); resultLoop: for (String[] cols : actionsResults) { int secretId = Integer.parseInt(cols[0], 10); final Secret secret = secretIdToSecret.get(secretId); final DBAudit.ACTION action = DBAudit.ACTION.valueOf(cols[2]); switch (action) { case GET_SECRET_WITH_CRITICAL: secret.lastAccessed = (null == secret.lastAccessed) ? newAuditAction(cols) : secret.lastAccessed; if (secret.lastModified != null) { // This currently doesn't do anything because add secret is always the oldest operation // but when we add EDIT_SECRET tracking this will be a pretty big optimization win. break resultLoop; } break; case ADD_SECRET: // TODO: we should really be using EDIT_SECRET here as well, but those // data are not properly set by the actions. secret.lastModified = (null == secret.lastModified) ? newAuditAction(cols) : secret.lastModified; if (secret.lastAccessed != null) { break resultLoop; } break; default: assert (false) : "invalid result from query"; } } }
From source file:com.moz.fiji.common.flags.parser.StringMapParser.java
/** {@inheritDoc} */ @Override/*from www.ja va2 s . co m*/ public Map<String, String> parse(FlagSpec flag, List<String> values) { final TreeMap<String, String> map = Maps.newTreeMap(); for (String keyValue : values) { if (keyValue == null) { throw new IllegalFlagValueException(flag, keyValue); } final String[] split = keyValue.split("=", 2); if (split.length != 2) { throw new IllegalFlagValueException(flag, keyValue); } map.put(split[0], split[1]); } return map; }