List of usage examples for com.google.common.collect Maps newTreeMap
public static <K extends Comparable, V> TreeMap<K, V> newTreeMap()
From source file:org.apache.pulsar.client.impl.MessageImpl.java
MessageImpl(MessageIdData messageId, MessageMetadata msgMetadata, ByteBuf payload, int partitionIndex, ClientCnx cnx) {/*from w w w . j a va2 s . com*/ this.msgMetadataBuilder = MessageMetadata.newBuilder(msgMetadata); this.messageId = new MessageIdImpl(messageId.getLedgerId(), messageId.getEntryId(), partitionIndex); this.cnx = cnx; // Need to make a copy since the passed payload is using a ref-count buffer that we don't know when could // release, since the Message is passed to the user. Also, the passed ByteBuf is coming from network and is // backed by a direct buffer which we could not expose as a byte[] this.payload = Unpooled.copiedBuffer(payload); if (msgMetadata.getPropertiesCount() > 0) { Map<String, String> properties = Maps.newTreeMap(); for (KeyValue entry : msgMetadata.getPropertiesList()) { properties.put(entry.getKey(), entry.getValue()); } this.properties = Collections.unmodifiableMap(properties); } else { properties = Collections.emptyMap(); } }
From source file:io.mapzone.arena.refine.RefinePanel.java
@Override public void createContents(final Composite parent) { parent.setLayout(FormLayoutFactory.defaults().create()); final TreeMap<String, RefineFunction> functions = Maps.newTreeMap(); for (Class<RefineFunction> cl : availableFunctions) { try {/*from w w w.j av a 2s.c o m*/ RefineFunction function = cl.newInstance(); function.init(map); functions.put(function.title(), function); } catch (Exception e) { throw new RuntimeException(e); } } Combo combo = new Combo(parent, SWT.SINGLE | SWT.BORDER | SWT.DROP_DOWN); @SuppressWarnings("hiding") final Composite functionContainer = tk().createComposite(parent, SWT.NONE); final List<String> content = Lists.newArrayList(functions.keySet()); combo.setItems(content.stream().toArray(String[]::new)); combo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String functionTitle = content.get(combo.getSelectionIndex()); RefineFunction function = functions.get(functionTitle); UIUtils.disposeChildren(functionContainer); // create panel IPanelSection section = tk().createPanelSection(functionContainer, function.description(), SWT.BORDER); section.setExpanded(true); section.getBody().setLayout(FormLayoutFactory.defaults().create()); function.createContents(tk(), section.getBody()); FormDataFactory.on(section.getBody()).fill(); functionContainer.layout(); } }); // layout final Label selectLabel = tk().createLabel(parent, i18n.get("selectFunction"), SWT.NONE); FormDataFactory.on(selectLabel).top(1).left(1); FormDataFactory.on(combo).top(selectLabel, 3).left(1).noBottom(); FormDataFactory.on(functionContainer).fill().top(combo, 5); }
From source file:org.sonar.duplications.algorithm.filter.IntervalTree.java
/** * Constructs a new, empty interval tree. *///from w w w . j ava 2 s . c om public IntervalTree() { SortedMap<Interval<T>, List<Interval<T>>> left = Maps.newTreeMap(); SortedMap<Interval<T>, List<Interval<T>>> right = Maps.newTreeMap(); this.head = new IntervalNode<T>().setStartIntervals(left).setEndIntervals(right); this.intervalList = Lists.newArrayList(); this.inSync = true; }
From source file:org.geogit.api.RevTreeBuilder.java
/** * Copy constructor// w ww . ja v a 2 s . c o m */ private RevTreeBuilder(final ObjectDatabase db, @Nullable final RevTree copy, final int depth, final Map<ObjectId, RevTree> pendingWritesCache) { checkNotNull(db); checkNotNull(pendingWritesCache); this.db = db; this.depth = depth; this.pendingWritesCache = pendingWritesCache; this.deletes = Sets.newHashSet(); this.treeChanges = Maps.newHashMap(); this.featureChanges = Maps.newHashMap(); this.bucketTreesByBucket = Maps.newTreeMap(); if (copy != null) { this.initialSize = copy.size(); this.initialNumTrees = copy.numTrees(); if (copy.trees().isPresent()) { checkArgument(!copy.buckets().isPresent()); for (Node node : copy.trees().get()) { putInternal(node); } } if (copy.features().isPresent()) { checkArgument(!copy.buckets().isPresent()); for (Node node : copy.features().get()) { putInternal(node); } } if (copy.buckets().isPresent()) { checkArgument(!copy.features().isPresent()); bucketTreesByBucket.putAll(copy.buckets().get()); } } }
From source file:org.activityinfo.core.shared.importing.match.ColumnMappingGuesser.java
public Map<SourceColumn, ImportTarget> getMapping() { // lower distance between maps Map<SourceColumn, TreeMap<Integer, ImportTarget>> distanceWithinTargetMaps = Maps.newHashMap(); for (SourceColumn sourceColumn : importModel.getSource().getColumns()) { final String sourceColumnHeader = sourceColumn.getHeader(); final TreeMap<Integer, ImportTarget> distanceMap = getDistanceMap(sourceColumnHeader); if (!distanceMap.isEmpty()) { final Map.Entry<Integer, ImportTarget> lowerDistanceEntry = distanceMap.entrySet().iterator() .next();/* w w w .ja v a 2s. c om*/ // if number of transformation operations are higher then label length then ignore such mapping final Integer transformationOperations = lowerDistanceEntry.getKey(); // if (transformationOperations < sourceColumnHeader.length() && transformationOperations < lowerDistanceEntry.getValue().getLabel().length()) { TreeMap<Integer, ImportTarget> valueMap = distanceWithinTargetMaps.get(sourceColumn); if (valueMap == null) { valueMap = Maps.newTreeMap(); distanceWithinTargetMaps.put(sourceColumn, valueMap); } valueMap.put(transformationOperations, lowerDistanceEntry.getValue()); // } } } // now re-iterate for target (different source columns may get the same target column as best match (lower distance)) Map<ImportTarget, TreeMap<Integer, SourceColumn>> targetToSource = Maps.newHashMap(); for (Map.Entry<SourceColumn, TreeMap<Integer, ImportTarget>> entry : distanceWithinTargetMaps.entrySet()) { final TreeMap<Integer, ImportTarget> value = entry.getValue(); if (!value.isEmpty()) { final Map.Entry<Integer, ImportTarget> bestEntry = value.entrySet().iterator().next(); // entry with lowest distance TreeMap<Integer, SourceColumn> distanceForSourceMap = targetToSource.get(bestEntry.getValue()); if (distanceForSourceMap == null) { distanceForSourceMap = Maps.newTreeMap(); targetToSource.put(bestEntry.getValue(), distanceForSourceMap); } distanceForSourceMap.put(bestEntry.getKey(), entry.getKey()); } } // finally build mapping Map<SourceColumn, ImportTarget> mapping = Maps.newHashMap(); for (Map.Entry<ImportTarget, TreeMap<Integer, SourceColumn>> entry : targetToSource.entrySet()) { final TreeMap<Integer, SourceColumn> map = entry.getValue(); if (!map.isEmpty()) { mapping.put(map.entrySet().iterator().next().getValue(), entry.getKey()); } } return mapping; }
From source file:org.kiji.schema.util.Debug.java
/** * Formats a collection of key-value pairs, for logging purposes. * * @param entries Key-value pairs to format. * @return the formatted list of key-value pairs. * @param <K> Type of the keys./*from ww w.j a v a2 s . c o m*/ * @param <V> Type of the values. */ public static <K, V> String toLogString(Iterable<Map.Entry<K, V>> entries) { final Map<String, V> map = Maps.newTreeMap(); for (Map.Entry<K, V> entry : entries) { map.put(entry.getKey().toString(), entry.getValue()); } final StringBuilder sb = new StringBuilder(); for (Map.Entry<String, V> entry : map.entrySet()) { sb.append(String.format("%s: \"%s\"%n", entry.getKey(), StringEscapeUtils.escapeJava(entry.getValue().toString()))); } return sb.toString(); }
From source file:org.eclipse.wb.internal.core.model.generic.ContainerObjectValidators.java
public static ContainerObjectValidator forComponentExpression(final String expression) { return new ContainerObjectValidator() { public boolean validate(Object container, Object component) { ILayoutRequestValidatorHelper validatorHelper = GlobalState.getValidatorHelper(); if (validatorHelper.isComponent(container) && validatorHelper.isComponent(component)) { Map<String, Object> variables = Maps.newTreeMap(); variables.put("container", container); variables.put("component", component); return evaluate(expression, variables); }/* w ww .ja v a2 s . c om*/ return false; } @Override public String toString() { return expression; } }; }
From source file:com.metamx.druid.BaseQuery.java
protected Map<String, String> computeOverridenContext(Map<String, String> overrides) { Map<String, String> overridden = Maps.newTreeMap(); final Map<String, String> context = getContext(); if (context != null) { overridden.putAll(context);/*from w w w.ja v a 2s . c o m*/ } overridden.putAll(overrides); return overridden; }
From source file:org.locationtech.geogig.api.RevTreeBuilder.java
/** * Only useful to {@link #build() build} the named {@link #empty() empty} tree *///from w w w.j av a2s . c o m private RevTreeBuilder() { db = null; treeChanges = Maps.newTreeMap(); featureChanges = Maps.newTreeMap(); deletes = Sets.newTreeSet(); bucketTreesByBucket = Maps.newTreeMap(); pendingWritesCache = Maps.newTreeMap(); }
From source file:com.netflix.ice.processor.BillingFileProcessor.java
@Override protected void poll() throws Exception { TreeMap<DateTime, List<BillingFile>> filesToProcess = Maps.newTreeMap(); Map<DateTime, List<BillingFile>> monitorFilesToProcess = Maps.newTreeMap(); // list the tar.gz file in billing file folder for (int i = 0; i < config.billingS3BucketNames.length; i++) { String billingS3BucketName = config.billingS3BucketNames[i]; String billingS3BucketPrefix = config.billingS3BucketPrefixes.length > i ? config.billingS3BucketPrefixes[i] : ""; String accountId = config.billingAccountIds.length > i ? config.billingAccountIds[i] : ""; String billingAccessRoleName = config.billingAccessRoleNames.length > i ? config.billingAccessRoleNames[i] : ""; String billingAccessExternalId = config.billingAccessExternalIds.length > i ? config.billingAccessExternalIds[i] : ""; logger.info("trying to list objects in billing bucket " + billingS3BucketName + " using assume role, and external id " + billingAccessRoleName + " " + billingAccessExternalId); List<S3ObjectSummary> objectSummaries = AwsUtils.listAllObjects(billingS3BucketName, billingS3BucketPrefix, accountId, billingAccessRoleName, billingAccessExternalId); logger.info("found " + objectSummaries.size() + " in billing bucket " + billingS3BucketName); TreeMap<DateTime, S3ObjectSummary> filesToProcessInOneBucket = Maps.newTreeMap(); Map<DateTime, S3ObjectSummary> monitorFilesToProcessInOneBucket = Maps.newTreeMap(); // for each file, download&process if not needed for (S3ObjectSummary objectSummary : objectSummaries) { String fileKey = objectSummary.getKey(); DateTime dataTime = AwsUtils.getDateTimeFromFileNameWithTags(fileKey); boolean withTags = true; if (dataTime == null) { dataTime = AwsUtils.getDateTimeFromFileName(fileKey); withTags = false;/*www. jav a 2 s . com*/ } if (dataTime != null && !dataTime.isBefore(config.startDate)) { if (!filesToProcessInOneBucket.containsKey(dataTime) || withTags && config.resourceService != null || !withTags && config.resourceService == null) filesToProcessInOneBucket.put(dataTime, objectSummary); else logger.info("ignoring file " + objectSummary.getKey()); } else { logger.info("ignoring file " + objectSummary.getKey()); } } for (S3ObjectSummary objectSummary : objectSummaries) { String fileKey = objectSummary.getKey(); DateTime dataTime = AwsUtils.getDateTimeFromFileNameWithMonitoring(fileKey); if (dataTime != null && !dataTime.isBefore(config.startDate)) { monitorFilesToProcessInOneBucket.put(dataTime, objectSummary); } } for (DateTime key : filesToProcessInOneBucket.keySet()) { List<BillingFile> list = filesToProcess.get(key); if (list == null) { list = Lists.newArrayList(); filesToProcess.put(key, list); } list.add(new BillingFile(filesToProcessInOneBucket.get(key), accountId, billingAccessRoleName, billingAccessExternalId, billingS3BucketPrefix)); } for (DateTime key : monitorFilesToProcessInOneBucket.keySet()) { List<BillingFile> list = monitorFilesToProcess.get(key); if (list == null) { list = Lists.newArrayList(); monitorFilesToProcess.put(key, list); } list.add(new BillingFile(monitorFilesToProcessInOneBucket.get(key), accountId, billingAccessRoleName, billingAccessExternalId, billingS3BucketPrefix)); } } for (DateTime dataTime : filesToProcess.keySet()) { startMilli = endMilli = dataTime.getMillis(); init(); boolean hasNewFiles = false; boolean hasTags = false; long lastProcessed = lastProcessTime(AwsUtils.monthDateFormat.print(dataTime)); for (BillingFile billingFile : filesToProcess.get(dataTime)) { S3ObjectSummary objectSummary = billingFile.s3ObjectSummary; if (objectSummary.getLastModified().getTime() < lastProcessed) { logger.info("data has been processed. ignoring " + objectSummary.getKey() + "..."); continue; } hasNewFiles = true; } if (!hasNewFiles) { logger.info("data has been processed. ignoring all files at " + AwsUtils.monthDateFormat.print(dataTime)); continue; } long processTime = new DateTime(DateTimeZone.UTC).getMillis(); for (BillingFile billingFile : filesToProcess.get(dataTime)) { S3ObjectSummary objectSummary = billingFile.s3ObjectSummary; String fileKey = objectSummary.getKey(); File file = new File(config.localDir, fileKey.substring(billingFile.prefix.length())); logger.info("trying to download " + fileKey + "..."); boolean downloaded = AwsUtils.downloadFileIfChangedSince(objectSummary.getBucketName(), billingFile.prefix, file, lastProcessed, billingFile.accountId, billingFile.accessRoleName, billingFile.externalId); if (downloaded) logger.info("downloaded " + fileKey); else { logger.info("file already downloaded " + fileKey + "..."); } logger.info("processing " + fileKey + "..."); boolean withTags = fileKey.contains("with-resources-and-tags"); hasTags = hasTags || withTags; processingMonitor = false; processBillingZipFile(file, withTags); logger.info("done processing " + fileKey); } if (monitorFilesToProcess.get(dataTime) != null) { for (BillingFile monitorBillingFile : monitorFilesToProcess.get(dataTime)) { S3ObjectSummary monitorObjectSummary = monitorBillingFile.s3ObjectSummary; if (monitorObjectSummary != null) { String monitorFileKey = monitorObjectSummary.getKey(); logger.info("processing " + monitorFileKey + "..."); File monitorFile = new File(config.localDir, monitorFileKey.substring(monitorFileKey.lastIndexOf("/") + 1)); logger.info("trying to download " + monitorFileKey + "..."); boolean downloaded = AwsUtils.downloadFileIfChangedSince( monitorObjectSummary.getBucketName(), monitorBillingFile.prefix, monitorFile, lastProcessed, monitorBillingFile.accountId, monitorBillingFile.accessRoleName, monitorBillingFile.externalId); if (downloaded) logger.info("downloaded " + monitorFile); else logger.warn(monitorFile + "already downloaded..."); FileInputStream in = new FileInputStream(monitorFile); try { processingMonitor = true; processBillingFile(monitorFile.getName(), in, true); } catch (Exception e) { logger.error("Error processing " + monitorFile, e); } finally { in.close(); } } } } if (dataTime.equals(filesToProcess.lastKey())) { int hours = (int) ((endMilli - startMilli) / 3600000L); logger.info("cut hours to " + hours); cutData(hours); } // now get reservation capacity to calculate upfront and un-used cost for (Ec2InstanceReservationPrice.ReservationUtilization utilization : Ec2InstanceReservationPrice.ReservationUtilization .values()) processReservations(utilization); if (hasTags && config.resourceService != null) config.resourceService.commit(); logger.info("archiving results for " + dataTime + "..."); archive(); logger.info("done archiving " + dataTime); updateProcessTime(AwsUtils.monthDateFormat.print(dataTime), processTime); if (dataTime.equals(filesToProcess.lastKey())) { sendOndemandCostAlert(); } } logger.info("AWS usage processed."); }