List of usage examples for com.google.common.collect Sets newTreeSet
public static <E> TreeSet<E> newTreeSet(Comparator<? super E> comparator)
From source file:edu.harvard.med.screensaver.service.screens.ScreenDerivedPropertiesUpdater.java
private SortedSet<Integer> findMaxReplicatesPerPlateNumber(SortedSet<AssayPlate> assayPlatesScreened) { Multimap<Integer, AssayPlate> plateNumbersToAssayPlates = Multimaps.index(assayPlatesScreened, AssayPlate.ToPlateNumber);// ww w . ja v a 2 s . c o m SortedSet<Integer> maxReplicatesPerPlateNumber = Sets .newTreeSet(Iterables.transform(plateNumbersToAssayPlates.asMap().entrySet(), new Function<Map.Entry<Integer, Collection<AssayPlate>>, Integer>() { @Override public Integer apply(Map.Entry<Integer, Collection<AssayPlate>> e) { Iterable<Integer> replicateOrdinals = Iterables.transform(e.getValue(), AssayPlate.ToReplicateOrdinal); return Ordering.natural().max(replicateOrdinals) + 1; } })); return maxReplicatesPerPlateNumber; }
From source file:com.chingo247.structureapi.commands.StructureCommands.java
private static String getInfo(StructureNode structure, IColors colors) { TreeSet<String> owners = Sets.newTreeSet(ALPHABETICAL_ORDER); List<SettlerNode> mastersNode = structure.getOwnerDomain().getOwners(OwnerType.MASTER); for (SettlerNode master : mastersNode) { owners.add(master.getName());/*from w w w .j av a 2s. c o m*/ } String ownershipString = ""; int size = owners.size(); int count = 0; for (String ownership : owners) { ownershipString += colors.yellow() + ownership + colors.reset(); count++; if (count != size) { ownershipString += ", "; } } String line = "#" + colors.gold() + structure.getId() + " " + colors.blue() + structure.getName() + "\n" + colors.reset() + "World: " + colors.yellow() + structure.getWorldName() + "\n"; Vector position = structure.getOrigin(); line += colors.reset() + "Location: " + colors.yellow() + "X: " + colors.reset() + position.getX() + " " + colors.yellow() + "Y: " + colors.reset() + position.getY() + " " + colors.yellow() + "Z: " + colors.reset() + position.getZ() + "\n"; CuboidRegion region = structure.getCuboidRegion(); line += colors.reset() + "Width: " + colors.yellow() + region.getWidth() + colors.reset() + " Height: " + colors.yellow() + region.getHeight() + colors.reset() + " Length: " + colors.yellow() + region.getLength() + colors.reset() + "\n"; line += colors.reset() + "Status: " + colors.reset() + getStatusString(structure, colors) + "\n"; if (structure.getPrice() > 0) { line += colors.reset() + "Value: " + colors.yellow() + structure.getPrice() + "\n"; } if (!owners.isEmpty()) { if (owners.size() == 1) { line += colors.reset() + "Owners(MASTER): " + ownershipString + "\n"; } else { line += colors.reset() + "Owners(MASTER): \n" + ownershipString + "\n"; } } if (structure.getNode().hasProperty("WGRegion")) { line += colors.reset() + "WorldGuard-Region: " + colors.yellow() + structure.getNode().getProperty("WGRegion"); } return line; }
From source file:org.fenixedu.qubdocs.academic.documentRequests.providers.ExtraCurriculumEntriesDataProvider.java
protected void init() { if (extracurricularApprovements != null) { final Set<ICurriculumEntry> entries = Sets.newHashSet(extracurricularApprovements); curriculumEntries = Sets.newTreeSet(new Comparator<CurriculumEntry>() { @Override/*from w ww .j a v a 2 s. c o m*/ public int compare(final CurriculumEntry left, final CurriculumEntry right) { if (left.getExecutionYear() == right.getExecutionYear()) { return compareByName(left, right); } return left.getExecutionYear().compareTo(right.getExecutionYear()); } public int compareByName(final CurriculumEntry left, final CurriculumEntry right) { String leftContent = left.getName().getContent(locale) != null ? left.getName().getContent(locale) : left.getName().getContent(); String rightContent = right.getName().getContent(locale) != null ? right.getName().getContent(locale) : right.getName().getContent(); leftContent = leftContent.toLowerCase(); rightContent = rightContent.toLowerCase(); return leftContent.compareTo(rightContent); } }); curriculumEntries.addAll(CurriculumEntry.transform(registration, entries, remarksDataProvider)); } }
From source file:org.kuali.rice.xml.ingest.RiceConfigUtils.java
public static void add(Properties oldProps, Properties newProps) { SortedSet<String> newKeys = Sets .newTreeSet(Sets.difference(newProps.stringPropertyNames(), oldProps.stringPropertyNames())); if (newKeys.size() == 0) { return;/*from w w w. ja v a2s . co m*/ } logger.info("Adding {} properties", newKeys.size()); for (String newKey : newKeys) { String value = newProps.getProperty(newKey); logger.debug("Adding - [{}]=[{}]", newKey, toLogMsg(newKey, value)); oldProps.setProperty(newKey, value); } }
From source file:nl.socrates.dom.communicationchannel.CommunicationChannels.java
@Programmatic public SortedSet<CommunicationChannel> findByOwnerAndType(final CommunicationChannelOwner owner, CommunicationChannelType type) { return Sets.newTreeSet(allMatches("findByOwnerAndType", "owner", owner, "type", type)); }
From source file:edu.washington.cs.cupid.internal.CapabilityRegistry.java
@Override public synchronized SortedSet<ICapability> getPredicates() { SortedSet<ICapability> result = Sets.newTreeSet(CapabilityUtil.COMPARE_NAME); for (ICapability capability : capabilities) { Set<ICapability.IOutput<?>> bool = Sets.newHashSet(); for (ICapability.IOutput<?> output : capability.getOutputs()) { if (TypeManager.isJavaCompatible(TypeToken.of(Boolean.class), output.getType())) { bool.add(output);//from www. j a va 2 s. c o m } } if (bool.size() == 1) { result.add(capability); } } return result; }
From source file:org.ldp4j.http.ContentNegotiationAlgorithm.java
private SortedSet<AlternativeEvaluation> rankAlternatives() { final Builder alternativesBuilder = ImmutableAlternatives.builder(); final SortedSet<AlternativeEvaluation> sortedCalculations = Sets .newTreeSet(AlternativeEvaluation.COMPARATOR); for (AlternativeEvaluation calculation : createCalculations()) { calculation.evaluate(this.accepts, this.acceptCharsets, this.acceptLanguages); if (Double.compare(0D, calculation.quality().weight()) != 0) { sortedCalculations.add(calculation); }/*from w w w.java2s .com*/ alternativesBuilder.add(calculation.quality(), calculation.alternative()); } this.alternatives = alternativesBuilder.build(); return sortedCalculations; }
From source file:net.sourceforge.vaticanfetcher.model.parse.ParseService.java
/** * Returns a list containing all parsers that support the mime type and/or file extension of the given file. * <p>//ww w. ja v a 2s . c o m * The list is sorted by the degree of matching: If a parser supports <em>both</em> the mime type <em>and</em> * the file extension of the given file, it appears in the returned list before other parsers that support * either only the mime type or only the file extension. */ @MutableCopy @NotNull @VisibleForTesting static List<Parser> getSortedMatchingParsers(@NotNull IndexingConfig config, @NotNull File file, @NotNull String filename) throws IOException { class Match { final Parser parser; boolean mimeMatch = false; boolean extMatch = false; public Match(@NotNull Parser parser) { this.parser = parser; } public int getMatchCount() { return (mimeMatch ? 1 : 0) + (extMatch ? 1 : 0); } } Set<Match> matches = Sets.newTreeSet(new Comparator<Match>() { public int compare(Match m1, Match m2) { // Element with higher match count comes first int cmp = -1 * Ints.compare(m1.getMatchCount(), m2.getMatchCount()); if (cmp != 0) return cmp; // Element with mime match comes before element with file // extension match if (m1.mimeMatch && !m2.mimeMatch) return -1; if (!m1.mimeMatch && m2.mimeMatch) return 1; // Compare parser names String name1 = m1.parser.getClass().getSimpleName(); String name2 = m2.parser.getClass().getSimpleName(); return name1.compareTo(name2); } }); List<String> mimeTypes = getPossibleMimeTypes(file); String ext = Util.getExtension(filename); for (Parser parser : parsers) { Match match = new Match(parser); if (!Collections.disjoint(mimeTypes, parser.getTypes())) match.mimeMatch = true; for (String candidateExt : getExtensions(config, parser)) { if (candidateExt.toLowerCase().equals(ext)) { match.extMatch = true; break; } } if (match.mimeMatch || match.extMatch) matches.add(match); } List<Parser> parsers = Util.createEmptyList(matches); for (Match match : matches) parsers.add(match.parser); return parsers; }
From source file:org.apache.giraph.comm.messages.SequentialFileMessageStore.java
@Override public void addMessages(MessageStore<I, M> messageStore) throws IOException { // Writes messages to its file if (file.exists()) { if (LOG.isDebugEnabled()) { LOG.debug("addMessages: Deleting " + file); }//from ww w. jav a 2s . c om file.delete(); } file.createNewFile(); if (LOG.isDebugEnabled()) { LOG.debug("addMessages: Creating " + file); } DataOutputStream out = null; try { out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file), bufferSize)); int destinationVertexIdCount = Iterables.size(messageStore.getDestinationVertices()); out.writeInt(destinationVertexIdCount); // Since the message store messages might not be sorted, sort them if // necessary SortedSet<I> sortedSet; if (messageStore.getDestinationVertices() instanceof SortedSet) { sortedSet = (SortedSet<I>) messageStore.getDestinationVertices(); } else { sortedSet = Sets.newTreeSet(messageStore.getDestinationVertices()); for (I destinationVertexId : messageStore.getDestinationVertices()) { sortedSet.add(destinationVertexId); } } // Dump the vertices and their messages in a sorted order for (I destinationVertexId : sortedSet) { destinationVertexId.write(out); Iterable<M> messages = messageStore.getVertexMessages(destinationVertexId); int messageCount = Iterables.size(messages); out.writeInt(messageCount); if (LOG.isDebugEnabled()) { LOG.debug("addMessages: For vertex id " + destinationVertexId + ", messages = " + messageCount + " to file " + file); } for (M message : messages) { if (LOG.isDebugEnabled()) { LOG.debug("addMessages: Wrote " + message + " to " + file); } message.write(out); } } } finally { if (out != null) { out.close(); } } }
From source file:com.eucalyptus.reporting.art.entity.ComputeCapacityArtEntity.java
public Set<String> getVmTypes() { return Sets .newTreeSet(Iterables.concat(this.ec2VmTypeToAvailable.keySet(), this.ec2VmTypeToTotal.keySet())); }