List of usage examples for com.google.common.collect Sets newTreeSet
public static <E> TreeSet<E> newTreeSet(Comparator<? super E> comparator)
From source file:com.twitter.aurora.scheduler.storage.StorageBackfill.java
private static void guaranteeShardUniqueness(ScheduledTask task, TaskStore.Mutable taskStore, Clock clock) { if (Tasks.isActive(task.getStatus())) { // Perform a sanity check on the number of active shards. TaskConfig config = task.getAssignedTask().getTask(); Query.Builder query = Query.instanceScoped( JobKeys.from(config.getOwner().getRole(), config.getEnvironment(), config.getJobName()), task.getAssignedTask().getInstanceId()).active(); Set<String> activeTasksInShard = FluentIterable.from(taskStore.fetchTasks(query)) .transform(Tasks.SCHEDULED_TO_ID).toSet(); if (activeTasksInShard.size() > 1) { SHARD_SANITY_CHECK_FAILS.incrementAndGet(); LOG.severe("Active shard sanity check failed when loading " + Tasks.id(task) + ", active tasks found: " + activeTasksInShard); // We want to keep exactly one task from this shard, so sort the IDs and keep the // highest (newest) in the hopes that it is legitimately running. String newestTask = Iterables.getLast(Sets.newTreeSet(activeTasksInShard)); if (!Tasks.id(task).equals(newestTask)) { task.setStatus(ScheduleStatus.KILLED); task.addToTaskEvents(new TaskEvent(clock.nowMillis(), ScheduleStatus.KILLED) .setMessage("Killed duplicate shard.")); // TODO(wfarner); Circle back if this is necessary. Currently there's a race // condition between the time the scheduler is actually available without hitting // IllegalStateException (see DriverImpl). // driver.killTask(Tasks.id(task)); } else { LOG.info("Retaining task " + Tasks.id(task)); }/*ww w . ja v a 2s . com*/ } } }
From source file:org.apache.mahout.knn.search.ProjectionSearch.java
public ProjectionSearch(int d, DistanceMeasure distance, int projections) { Preconditions.checkArgument(projections > 0 && projections < 100, "Unreasonable value for number of projections"); final DoubleFunction random = Functions.random(); this.distance = distance; vectors = Lists.newArrayList();/*w w w .ja va 2 s.c om*/ // we want to create several projections. Each is alike except for the // direction of the projection for (int i = 0; i < projections; i++) { // create a random vector to use for the basis of the projection final DenseVector projection = new DenseVector(d); projection.assign(random); projection.normalize(); // the projection is implemented by a tree set where the ordering of vectors // is based on the dot product of the vector with the projection vector TreeSet<Vector> s = Sets.newTreeSet(new Comparator<Vector>() { @Override public int compare(Vector v1, Vector v2) { int r = Double.compare(v1.dot(projection), v2.dot(projection)); if (r == 0) { return v1.hashCode() - v2.hashCode(); } else { return r; } } }); // so we have a project (s) and we need to add it to the list of projections for later vectors.add(s); } }
From source file:edu.washington.cs.cupid.internal.CapabilityRegistry.java
@Override public synchronized SortedSet<ICapability> getCapabilities(final TypeToken<?> type) { SortedSet<ICapability> result = Sets.newTreeSet(CapabilityUtil.COMPARE_NAME); for (ICapability capability : capabilities) { for (ICapability.IParameter<?> param : capability.getParameters()) { if (TypeManager.isCompatible(param, type)) { result.add(capability);// w w w . ja v a2 s . c o m break; } } } return result; }
From source file:com.facebook.buck.core.model.impl.InMemoryBuildFileTree.java
public InMemoryBuildFileTree(Collection<Path> basePaths) { TreeSet<Path> sortedBasePaths = Sets.newTreeSet(PATH_COMPARATOR); sortedBasePaths.addAll(basePaths);//from w w w . j a va 2 s. c o m // Initialize basePathToNodeIndex with a Node that corresponds to the empty string. This ensures // that findParent() will always return a non-null Node because the empty string is a prefix of // all base paths. basePathToNodeIndex = new HashMap<>(); Node root = new Node(Paths.get("")); basePathToNodeIndex.put(Paths.get(""), root); // Build up basePathToNodeIndex in a breadth-first manner. for (Path basePath : sortedBasePaths) { if (basePath.equals(Paths.get(""))) { continue; } Node child = new Node(basePath); Node parent = findParent(child, basePathToNodeIndex); Objects.requireNonNull(parent).addChild(child); basePathToNodeIndex.put(basePath, child); } }
From source file:uk.ac.ebi.atlas.utils.ExperimentInfo.java
public void setSpecies(Set<String> species) { this.species = Sets.newTreeSet(species); }
From source file:com.mapr.storm.DirectoryScanner.java
private File scanForFiles() { if (pendingFiles.size() == 0) { Set<File> files = Sets.newTreeSet(Lists.newArrayList(inputDirectory.listFiles(new FilenameFilter() { @Override// w ww . ja v a2s. c o m public boolean accept(File file, String s) { return fileNamePattern.matcher(s).matches(); } }))); oldFiles.retainAll(files); files.removeAll(oldFiles); oldFiles.addAll(files); pendingFiles.addAll(files); } return pendingFiles.poll(); }
From source file:org.fenixedu.qubdocs.academic.documentRequests.providers.ApprovementCertificateCurriculumEntries.java
protected Set<CurriculumEntry> getCurriculumEntries() { if (curriculumEntries == null) { final Set<ICurriculumEntry> entries = Sets.newHashSet(/*certificateRequest.getEntries*/); curriculumEntries = Sets.newTreeSet(new Comparator<CurriculumEntry>() { @Override/* www . j a v a 2 s. com*/ public int compare(final CurriculumEntry left, final CurriculumEntry right) { final String leftContent = left.getName().getContent(locale) != null ? left.getName().getContent(locale) : left.getName().getContent(); final String rightContent = right.getName().getContent(locale) != null ? right.getName().getContent(locale) : right.getName().getContent(); return leftContent.compareTo(rightContent); } }); curriculumEntries.addAll(CurriculumEntry.transform(registration, entries, remarksDataProvider)); } return curriculumEntries; }
From source file:cc.recommenders.evaluation.distribution.calc.F1AndSizeProvider.java
@Override protected void logResults() { append("rec\tsize\tf1\t%% boxplot\n"); Set<String> apps = Sets.newTreeSet(sizes.keySet()); for (String name : apps) { int size = sizes.get(name).getIntAverage(); Boxplot f1 = quality.get(name).getBoxplot(); append("%s\t%d\t%.5f\t%% %s\n", name, size, f1.getMean(), f1); }//from w w w .java 2s . c o m }
From source file:org.jclouds.openstack.swift.functions.ParseObjectInfoListFromJsonResponse.java
public PageSet<ObjectInfo> apply(InputStream stream) { checkState(args != null, "request should be initialized at this point"); Type listType = new TypeToken<SortedSet<ObjectInfoImpl>>() { }.getType();/*w w w .j a v a 2 s . c om*/ try { SortedSet<ObjectInfoImpl> list = apply(stream, listType); SortedSet<ObjectInfo> returnVal = Sets .newTreeSet(Iterables.transform(list, new Function<ObjectInfoImpl, ObjectInfo>() { public ObjectInfo apply(ObjectInfoImpl from) { return from.toBuilder().container(container).uri(uriBuilder(request.getEndpoint()) .clearQuery().appendPath(from.getName()).build()).build(); } })); boolean truncated = options.getMaxResults() == returnVal.size(); String marker = truncated ? returnVal.last().getName() : null; return new PageSetImpl<ObjectInfo>(returnVal, marker); } catch (IOException e) { throw new RuntimeException("problem reading response from request: " + request, e); } }
From source file:com.eucalyptus.auth.euare.identity.region.RegionInfo.java
public RegionInfo(final String name, final Collection<Integer> partitions, final Collection<RegionService> services, final Set<Cidr> remoteCidrs, final Set<Cidr> forwardedForCidrs, final String certificateFingerprintDigest, final String certificateFingerprint, final String sslCertificateFingerprintDigest, final String sslCertificateFingerprint) { Parameters.checkParam("name", name, not(isEmptyOrNullString())); Parameters.checkParam("partitions", partitions, hasSize(greaterThan(0))); Parameters.checkParam("services", services, hasSize(greaterThan(0))); this.name = name; this.partitions = ImmutableSet.copyOf(Sets.newTreeSet(partitions)); this.services = ImmutableSet.copyOf(Sets.newTreeSet(services)); this.remoteCidrs = remoteCidrs; this.forwardedForCidrs = forwardedForCidrs; this.certificateFingerprintDigest = certificateFingerprintDigest; this.certificateFingerprint = certificateFingerprint; this.sslCertificateFingerprintDigest = sslCertificateFingerprintDigest; this.sslCertificateFingerprint = sslCertificateFingerprint; }