List of usage examples for com.google.common.collect Maps newTreeMap
public static <C, K extends C, V> TreeMap<K, V> newTreeMap(@Nullable Comparator<C> comparator)
From source file:com.google.wave.splash.web.stats.StatsRenderer.java
private String renderGlobalStats(Map<String, Measurement> measurements) { StringBuilder builder = new StringBuilder(); Map<String, Measurement> sortedMeasurements = Maps.newTreeMap(CASE_INSENSITIVE_COMPARATOR); sortedMeasurements.putAll(measurements); for (Map.Entry<String, Measurement> entry : sortedMeasurements.entrySet()) { builder.append("<span style=\"").append(getMeasurementStyle(entry.getValue())).append("\">") .append(entry.getKey()).append(" ").append(entry.getValue()).append("</span><br/>"); }//from w ww . j a v a 2 s .c om return builder.toString(); }
From source file:io.sarl.eclipse.wizards.elements.newskill.NewSarlSkillWizardPage.java
@Override protected void getTypeContent(Resource ecoreResource, String typeComment) throws CoreException { GeneratedCode code = this.sarlGenerator.createScript(ecoreResource, getPackageFragment().getElementName()); io.sarl.lang.sarl.Skill skill = this.sarlGenerator.createSkill(code, getTypeName(), getSuperClass(), getSuperInterfaces());//from w ww. jav a 2 s . co m this.sarlGenerator.attachComment(code, skill, typeComment); Map<ActionKey, IMethod> operationsToImplement; Map<SignatureKey, IMethod> constructors; String superClass = getSuperClass(); if (Strings.isNullOrEmpty(superClass) || !isCreateConstructors()) { constructors = null; } else { constructors = Maps.newTreeMap((Comparator<SignatureKey>) null); } if (isCreateInherited()) { operationsToImplement = Maps.newTreeMap((Comparator<ActionKey>) null); } else { operationsToImplement = null; } populateInheritanceContext(Jdt2Ecore.toTypeFinder(getJavaProject()), // Discarding final operation null, // Discarding overridable operation null, // Discarding inherited fields, null, operationsToImplement, constructors, code.getCodeGenerator().getActionSignatureProvider(), getSuperClass(), getSuperInterfaces()); if (constructors != null) { Jdt2Ecore.createStandardConstructors(code, constructors.values(), skill); } if (operationsToImplement != null) { Jdt2Ecore.createActions(code, operationsToImplement.values(), skill); } code.finalizeScript(); }
From source file:com.android.sdklib.repositoryv2.targets.AndroidTargetManager.java
@NonNull private Map<LocalPackage, IAndroidTarget> getTargetMap(@NonNull ProgressIndicator progress) { if (mTargets == null) { Map<String, String> newErrors = Maps.newHashMap(); TARGET_COMPARATOR = new Comparator<LocalPackage>() { @Override/* w w w. j a v a2 s . c om*/ public int compare(LocalPackage o1, LocalPackage o2) { DetailsTypes.ApiDetailsType details1 = (DetailsTypes.ApiDetailsType) o1.getTypeDetails(); DetailsTypes.ApiDetailsType details2 = (DetailsTypes.ApiDetailsType) o2.getTypeDetails(); AndroidVersion version1 = DetailsTypes.getAndroidVersion(details1); AndroidVersion version2 = DetailsTypes.getAndroidVersion(details2); return ComparisonChain.start().compare(version1, version2).compare(o1.getPath(), o2.getPath()) .compare(details1.getClass().getName(), details2.getClass().getName()).result(); } }; Map<LocalPackage, IAndroidTarget> result = Maps.newTreeMap(TARGET_COMPARATOR); RepoManager manager = mSdkHandler.getSdkManager(progress); Map<AndroidVersion, PlatformTarget> platformTargets = Maps.newHashMap(); for (LocalPackage p : manager.getPackages().getLocalPackages().values()) { TypeDetails details = p.getTypeDetails(); if (details instanceof DetailsTypes.PlatformDetailsType) { try { PlatformTarget target = new PlatformTarget(p, mSdkHandler, mFop, progress); result.put(p, target); platformTargets.put(target.getVersion(), target); } catch (IllegalArgumentException e) { newErrors.put(p.getPath(), e.getMessage()); } } } for (LocalPackage p : manager.getPackages().getLocalPackages().values()) { TypeDetails details = p.getTypeDetails(); if (details instanceof DetailsTypes.AddonDetailsType) { AndroidVersion addonVersion = DetailsTypes .getAndroidVersion((DetailsTypes.AddonDetailsType) details); PlatformTarget baseTarget = platformTargets.get(addonVersion); if (baseTarget != null) { result.put(p, new AddonTarget(p, baseTarget, mSdkHandler.getSystemImageManager(progress), progress, mFop)); } } } mTargets = result; mLoadErrors = newErrors; } return mTargets; }
From source file:com.arpnetworking.clusteraggregator.aggregation.AggMessageExtractor.java
/** * Sort and de-dupe the dimensions in a consistent manner. Will log an error if any duplicate keys are found and select the * lexicographically-smaller value./* ww w .j a v a2 s . co m*/ * * @param metricData The <code>StatisticSetRecord</code> from which to pull dimensions. * @return A sorted, de-duped TreeMap of the dimensions. */ private TreeMap<String, String> dimensionsToMap(final Messages.StatisticSetRecord metricData) { final TreeMap<String, String> sortedDimensionsMap = Maps.newTreeMap(Comparator.<String>naturalOrder()); for (final Messages.DimensionEntry dimensionEntry : metricData.getDimensionsList()) { sortedDimensionsMap.merge(dimensionEntry.getKey(), dimensionEntry.getValue(), (existing, incoming) -> { LOGGER.error().setMessage("Duplicate key found for dimension.") .addData("statisticSetRecord", metricData).addData("dimensionKey", dimensionEntry.getKey()) .addData("firstValue", existing).addData("secondValue", incoming).log(); if (existing.compareTo(incoming) < 0) { return existing; } return incoming; }); } return sortedDimensionsMap; }
From source file:io.sarl.eclipse.wizards.elements.aop.newskill.NewSarlSkillWizardPage.java
@Override protected void getTypeContent(Resource ecoreResource, String typeComment) throws CoreException { IScriptBuilder scriptBuilder = this.codeBuilderFactory.createScript(getPackageFragment().getElementName(), ecoreResource);/*from ww w . j av a 2 s . c om*/ ISkillBuilder skill = scriptBuilder.addSkill(getTypeName()); skill.setExtends(getSuperClass()); for (String implementedType : getSuperInterfaces()) { skill.addImplements(implementedType); } skill.setDocumentation(typeComment.trim()); Map<ActionPrototype, IMethod> operationsToImplement; Map<ActionParameterTypes, IMethod> constructors; String superClass = getSuperClass(); if (Strings.isNullOrEmpty(superClass) || !isCreateConstructors()) { constructors = null; } else { constructors = Maps.newTreeMap((Comparator<ActionParameterTypes>) null); } if (isCreateInherited()) { operationsToImplement = Maps.newTreeMap((Comparator<ActionPrototype>) null); } else { operationsToImplement = null; } this.jdt2sarl.populateInheritanceContext(this.jdt2sarl.toTypeFinder(getJavaProject()), // Discarding final operation null, // Discarding overridable operation null, // Discarding inherited fields, null, operationsToImplement, constructors, getSuperClass(), getSuperInterfaces()); if (constructors != null) { this.jdt2sarl.createStandardConstructors(skill, constructors.values(), skill.getSarlSkill()); } if (operationsToImplement != null) { this.jdt2sarl.createActions(skill, operationsToImplement.values()); } scriptBuilder.finalizeScript(); }
From source file:be.nbb.jackcess.JackcessStatement.java
private static SortedMap<Column, String> getFilter(Table table, Map<String, String> filterItems) { SortedMap<Column, String> result = Maps.newTreeMap(BY_COLUMN_INDEX); for (Map.Entry<String, String> o : filterItems.entrySet()) { result.put(table.getColumn(o.getKey()), o.getValue()); }//ww w .ja v a 2 s . co m return result; }
From source file:co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryOrderedTableService.java
@Deprecated public static synchronized Map<byte[], Long> increment(String tableName, byte[] row, Map<byte[], Long> increments) { Map<byte[], Long> resultMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); ConcurrentNavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, Update>>> table = tables .get(tableName);//from ww w.ja va 2 s . c om // get the correct row from the table, create it if it doesn't exist NavigableMap<byte[], NavigableMap<Long, Update>> rowMap = table.get(row); if (rowMap == null) { rowMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); table.put(row, rowMap); } // now increment each column, one by one long versionForWrite = System.currentTimeMillis(); for (Map.Entry<byte[], Long> inc : increments.entrySet()) { IncrementValue increment = new IncrementValue(inc.getValue()); // create the column in the row if it does not exist NavigableMap<Long, Update> colMap = rowMap.get(inc.getKey()); Update last = null; if (colMap == null) { colMap = Maps.newTreeMap(); rowMap.put(inc.getKey(), colMap); } else { last = colMap.lastEntry().getValue(); } Update merged = Updates.mergeUpdates(last, increment); // put into the column with given version long newValue = Bytes.toLong(merged.getBytes()); resultMap.put(inc.getKey(), newValue); colMap.put(versionForWrite, merged); } return resultMap; }
From source file:com.palantir.atlasdb.keyvalue.remoting.serialization.RowResultDeserializer.java
private SortedMap<byte[], Set<Value>> deserializeWithValuesSet(JsonNode node, DeserializationContext ctxt) throws IOException { SortedMap<byte[], Set<Value>> result = Maps.newTreeMap(UnsignedBytes.lexicographicalComparator()); Iterator<JsonNode> it = node.get("columns").elements(); while (it.hasNext()) { JsonNode col = it.next();/*from w w w. ja va 2s . c om*/ byte[] colName = col.get("column").binaryValue(); Set<Value> values = Sets.newHashSet(); Iterator<JsonNode> colIt = col.get("timestamps").elements(); while (colIt.hasNext()) { JsonNode colVal = colIt.next(); long timestamp = colVal.get("timestamp").asLong(); byte[] contents = colVal.get("contents").binaryValue(); values.add(Value.create(contents, timestamp)); } result.put(colName, values); } return result; }
From source file:co.cask.tigon.data.transaction.queue.AbstractQueueConsumer.java
protected AbstractQueueConsumer(ConsumerConfig consumerConfig, QueueName queueName) { this.consumerConfig = consumerConfig; this.queueName = queueName; this.entryCache = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); this.consumingEntries = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); this.queueRowPrefix = QueueEntryRow.getQueueRowPrefix(queueName); this.startRow = getRowKey(0L, 0); this.stateColumnName = Bytes.add(QueueEntryRow.STATE_COLUMN_PREFIX, Bytes.toBytes(consumerConfig.getGroupId())); }
From source file:org.terasology.fluidTransport.systems.FluidTransportAuthoritySystem.java
@Override public void update(float delta) { long currentTime = time.getGameTimeInMs(); if (currentTime > nextUpdateTime) { nextUpdateTime = currentTime + UPDATE_INTERVAL; // fluid flows naturally downwards // tanks even themselves out if they are on equal elevation // pumps create pressure which can move fluid against gravity // flow in and out of a tank is restricted to a static rate // distribute all fluid through the network for (Network network : fluidTransportBlockNetwork.getNetworks()) { SortedMap<Integer, EntityRef> tanksFromTopDown = Maps.newTreeMap(new Comparator<Integer>() { @Override//from w w w . j a va 2 s . com public int compare(Integer i1, Integer i2) { // sort descending return i1.compareTo(i2) * -1; } }); SortedMap<Integer, EntityRef> tanksFromBottomUp = Maps.newTreeMap(); SortedMap<Integer, EntityRef> pumpsFromBottomUp = Maps.newTreeMap(); // gather the tanks for this network for (NetworkNode leafNode : fluidTransportBlockNetwork.getNetworkNodes(network)) { EntityRef entity = blockEntityRegistry.getExistingEntityAt(leafNode.location.toVector3i()); if (ExtendedFluidManager.isTank(entity)) { tanksFromBottomUp.put(leafNode.location.y, entity); tanksFromTopDown.put(leafNode.location.y, entity); } else if (entity.hasComponent(FluidPumpComponent.class)) { pumpsFromBottomUp.put(leafNode.location.y, entity); } } // let tanks drop their fluid to a tank below for (EntityRef tank : tanksFromBottomUp.values()) { Vector3i tankBelowLocation = Side.BOTTOM.getAdjacentPos(getLocation(tank)); EntityRef tankBelow = blockEntityRegistry.getEntityAt(tankBelowLocation); String fluidType = ExtendedFluidManager.getTankFluidType(tank); if (tankBelow.hasComponent(FluidInventoryComponent.class)) { float volumeGiven = ExtendedFluidManager.giveFluid(tankBelow, ExtendedFluidManager.getTankFluidVolume(tank), fluidType); ExtendedFluidManager.removeFluid(tank, volumeGiven, fluidType); } } // distribute gravity flow for (EntityRef tank : tanksFromTopDown.values()) { float tankElevation = getTankElevation(tank); float remainingFlow = getTankFlowAvailable(tank); float totalVolumeTransfered = 0; String fluidType = ExtendedFluidManager.getTankFluidType(tank); for (EntityRef downstreamTank : tanksFromTopDown.values()) { if (!downstreamTank.equals(tank) && getTankElevation(downstreamTank) < tankElevation && remainingFlow > 0) { float volumeTransfered = ExtendedFluidManager.giveFluid(downstreamTank, remainingFlow, fluidType); totalVolumeTransfered += volumeTransfered; remainingFlow -= volumeTransfered; } } ExtendedFluidManager.removeFluid(tank, totalVolumeTransfered, fluidType); } // distribute pump flow starting from the bottom for (EntityRef pump : pumpsFromBottomUp.values()) { float pumpWorldPressure = getPumpWorldPressure(pump); float remainingFlow = getPumpFlowAvailable(pump); float totalVolumeTransfered = 0; EntityRef sourceTank = null; String fluidType = null; // check each side for a valid source of liquid for (Side side : Side.values()) { Vector3i sidePosition = side.getAdjacentPos(getLocation(pump)); // check for world liquid blocks LiquidData liquidData = worldProvider.getLiquid(sidePosition); if (liquidData.getDepth() > 0) { fluidType = fluidRegistry.getFluidType(liquidData.getType()); break; } // check for a tank block EntityRef sideEntity = blockEntityRegistry.getEntityAt(sidePosition); if (ExtendedFluidManager.isTank(sideEntity)) { sourceTank = sideEntity; fluidType = ExtendedFluidManager.getTankFluidType(sideEntity); break; } } if (fluidType != null) { // distribute this fluid for (EntityRef tank : tanksFromBottomUp.values()) { if (!tank.equals(sourceTank) && getTankElevation(tank) < pumpWorldPressure && remainingFlow > 0) { float volumeTransfered = ExtendedFluidManager.giveFluid(tank, remainingFlow, fluidType); remainingFlow -= volumeTransfered; totalVolumeTransfered += volumeTransfered; } } if (sourceTank != null) { ExtendedFluidManager.removeFluid(sourceTank, totalVolumeTransfered, fluidType); } } } } } }