List of usage examples for com.google.common.collect Sets newTreeSet
public static <E extends Comparable> TreeSet<E> newTreeSet()
From source file:com.gwtplatform.dispatch.rest.rebind.resource.MethodDefinition.java
public MethodDefinition(JMethod method, List<Parameter> parameters, List<Parameter> inheritedParameters) { this.method = method; this.parameters = parameters; this.inheritedParameters = inheritedParameters; this.imports = Sets.newTreeSet(); }
From source file:com.facebook.buck.rules.BuckPyFunction.java
public String toPythonFunction(BuildRuleType type, ConstructorArg dto) { Preconditions.checkNotNull(type);// w w w . j a v a2 s .c om Preconditions.checkNotNull(dto); StringBuilder builder = new StringBuilder(); SortedSet<ParamInfo> mandatory = Sets.newTreeSet(); SortedSet<ParamInfo> optional = Sets.newTreeSet(); for (ParamInfo param : argMarshaller.getAllParamInfo(dto)) { if (isSkippable(param)) { continue; } if (param.isOptional()) { optional.add(param); } else { mandatory.add(param); } } @Nullable TargetName defaultName = dto.getClass().getAnnotation(TargetName.class); builder.append("@provide_for_build\n").append("def ").append(type.getName()).append("("); if (defaultName == null) { builder.append("name, "); } // Construct the args. for (ParamInfo param : Iterables.concat(mandatory, optional)) { appendPythonParameter(builder, param); } builder.append("visibility=[], build_env=None):\n") // Define the rule. .append(" add_rule({\n").append(" 'type' : '").append(type.getName()).append("',\n"); if (defaultName != null) { builder.append(" 'name' : '").append(defaultName.name()).append("',\n"); } else { builder.append(" 'name' : name,\n"); } // Iterate over args. for (ParamInfo param : Iterables.concat(mandatory, optional)) { builder.append(" '").append(param.getName()).append("' : ").append(param.getPythonName()) .append(",\n"); } builder.append(" 'visibility' : visibility,\n"); builder.append(" }, build_env)\n\n"); return builder.toString(); }
From source file:com.enonic.cms.core.search.builder.ContentIndexDataCustomDataFactory.java
private Set<String> getAllValuesForFieldName(String fieldName, final Collection<UserDefinedField> userDefinedFields) { final Set<String> values = Sets.newTreeSet(); for (final UserDefinedField userDefinedField : userDefinedFields) { if (fieldName.equals(userDefinedField.getName())) { values.add(userDefinedField.getValue().getText()); }/*from w w w.j a v a 2 s . c om*/ } return values; }
From source file:indigo.runtime.GetContrainedSets.java
@SuppressWarnings("unchecked") @Override//from w w w . j av a 2 s. c o m public <P, T, E> T evalBinaryOperation(P parent, String op, E left, E right) { Set<String> predicateNames = Sets.newTreeSet(); switch (op) { // case "=": // return (T) z3.ctx.mkEq((Expr) left, (Expr) right); // case "==": // return (T) z3.ctx.mkEq((Expr) left, (Expr) right); // case "<>": // return (T) z3.Not(z3.ctx.mkEq((Expr) left, (Expr) right)); case "<": case "<=": case ">": case ">=": case "and": case "/\\": case "or": case "\\/": predicateNames.addAll((Collection<String>) left); predicateNames.addAll((Collection<String>) right); constrainedSets.addAll(predicateNames); break; default: } return (T) ImmutableSet.copyOf(predicateNames); }
From source file:com.google.devtools.build.workspace.maven.Rule.java
public Rule(Artifact artifact) { this.artifact = artifact; this.parents = Sets.newHashSet(); this.dependencies = Sets.newTreeSet(); this.exclusions = Sets.newHashSet(); this.repository = MavenConnector.MAVEN_CENTRAL_URL; }
From source file:eu.interedition.text.util.Ranges.java
public static SortedSet<TextRange> compress(SortedSet<TextRange> ranges) { final SortedSet<TextRange> compressed = Sets.newTreeSet(); TextRange current = null;/* ww w. j a va 2 s.com*/ for (Iterator<TextRange> rangeIt = ranges.iterator(); rangeIt.hasNext();) { final TextRange range = rangeIt.next(); if (current == null) { current = new TextRange(range); } else { if (current.getEnd() >= range.getStart()) { current = new TextRange(current.getStart(), Math.max(current.getEnd(), range.getEnd())); } else { compressed.add(current); current = new TextRange(range); } } if (!rangeIt.hasNext()) { compressed.add(current); } } return compressed; }
From source file:com.metamx.druid.partition.PartitionHolder.java
public PartitionHolder(List<PartitionChunk<T>> initialChunks) { this.holderSet = Sets.newTreeSet(); for (PartitionChunk<T> chunk : initialChunks) { add(chunk);//from w ww . j ava 2s. c o m } }
From source file:org.apache.mahout.knn.means.ThreadedKmeansScaling.java
public static void testScaling() { DistanceMeasure m = new EuclideanDistanceMeasure(); for (int d : new int[] { 5, 10, 20, 50, 100, 200, 500 }) { MultiNormal gen = new MultiNormal(d); final DenseVector projection = new DenseVector(d); projection.assign(gen.sample()); projection.normalize();//from w w w. jav a2s . c om Matrix data = new DenseMatrix(10000, d); TreeSet<WeightedVector> tmp = Sets.newTreeSet(); for (MatrixSlice row : data) { row.vector().assign(gen.sample()); tmp.add(WeightedVector.project(row.vector(), projection, row.index())); } Searcher ref = new Brute(data); double correct = 0; double depthSum = 0; double[] cnt = new double[MAX_DEPTH]; OnlineSummarizer distanceRatio = new OnlineSummarizer(); for (int i = 0; i < QUERIES; i++) { Vector query = new DenseVector(d); query.assign(gen.sample()); List<WeightedVector> nearest = ref.search(query, MAX_DEPTH); WeightedVector qp = WeightedVector.project(query, projection); List<WeightedVector> r = Lists.newArrayList(); for (WeightedVector v : Iterables.limit(tmp.tailSet(qp, false), SEARCH_SIZE)) { final WeightedVector projectedVector = new WeightedVector(v.getVector(), m.distance(query, v), v.getIndex()); r.add(projectedVector); } for (WeightedVector v : Iterables.limit(tmp.headSet(qp, false).descendingSet(), SEARCH_SIZE)) { r.add(new WeightedVector(v.getVector(), m.distance(query, v), v.getIndex())); } Collections.sort(r); distanceRatio.add(r.get(0).getWeight() / nearest.get(0).getWeight()); if (nearest.get(0).getIndex() == r.get(0).getIndex()) { correct++; } int depth = 0; for (WeightedVector vector : nearest) { if (vector.getIndex() == r.get(0).getIndex()) { depthSum += depth; cnt[depth]++; break; } depth++; } } System.out.printf("%d\t%.2f\t%.2f", d, correct / QUERIES, depthSum / QUERIES); System.out.printf("\t%.2f\t%.2f\t%.2f", distanceRatio.getQuartile(1), distanceRatio.getQuartile(2), distanceRatio.getQuartile(3)); for (int i = 0; i < 10; i++) { System.out.printf("\t%.2f", cnt[i] / QUERIES); } System.out.printf("\n"); } }
From source file:com.cinchapi.concourse.server.upgrade.UpgradeTasks.java
/** * Run all the upgrade tasks that are greater than the * {@link UpgradeTask#getCurrentSystemVersion() current system version}. *//*from www .ja v a 2 s .c o m*/ public static void runLatest() { int currentSystemVersion = 0; try { currentSystemVersion = bootstrap(); } catch (Exception e) { String user = System.getProperty("user.name"); Logger.error("An error occurred while trying to bootstrap the upgrade framework, " + "which usually indicates that Concourse Server is configured to store " + "data in one or more locations where the current user ({}) does not " + "have write permission. Please check the prefs file at {} to make sure " + "you have properly configured the buffer_directory and database_directory. " + "If those properties are properly configured, please give \"{}\" write " + "permission to those directories.", user, GlobalState.getPrefsFilePath(), user); throw e; } // Find the new upgrade tasks Set<UpgradeTask> tasks = Sets.newTreeSet(); for (String pkg : pkgs) { Reflections reflections = new Reflections(pkg); Set<Class<? extends UpgradeTask>> classes = reflections.getSubTypesOf(UpgradeTask.class); classes.addAll(reflections.getSubTypesOf(SmartUpgradeTask.class)); for (Class<? extends UpgradeTask> clazz : classes) { UpgradeTask task = Reflection.newInstance(clazz); if (task.version() > currentSystemVersion) { tasks.add(task); } } } // Run the new upgrade tasks for (UpgradeTask task : tasks) { try { task.run(); } catch (Exception e) { if (task instanceof Upgrade2) { // CON-137: Even if Upgrade2 fails and we can't migrate // data, still set the system version so we aren't // blocked on this task in the future. UpgradeTask.setCurrentSystemVersion(task.version()); Logger.info("Due to a bug in a previous " + "release, the system version has " + "been force upgraded " + "to {}", task.version()); } else { throw e; // fail fast because we assume subsequent tasks // depend on the one that failed } } } }
From source file:com.google.devtools.build.lib.buildtool.InstrumentationFilterSupport.java
/** * Method implements a heuristic used to set default value of the * --instrumentation_filter option. Following algorithm is used: * 1) Identify all test targets on the command line. * 2) Expand all test suites into the individual test targets * 3) Calculate list of package names containing all test targets above. * 4) Replace all "javatests/" substrings in package names with "java/". * 5) If two packages reside in the same directory, use filter based on * the parent directory name instead. Doing so significantly simplifies * instrumentation filter in majority of real-life scenarios (in * particular when dealing with my/package/... wildcards). * 6) Set --instrumentation_filter default value to instrument everything * in those packages.//from w ww.j a v a 2 s .com */ @VisibleForTesting public static String computeInstrumentationFilter(EventHandler eventHandler, Collection<Target> testTargets) { SortedSet<String> packageFilters = Sets.newTreeSet(); collectInstrumentedPackages(testTargets, packageFilters); optimizeFilterSet(packageFilters); String instrumentationFilter = "//" + Joiner.on(",//").join(packageFilters); if (!packageFilters.isEmpty()) { eventHandler.handle(Event .info("Using default value for --instrumentation_filter: \"" + instrumentationFilter + "\".")); eventHandler.handle(Event.info("Override the above default with --" + INSTRUMENTATION_FILTER_FLAG)); } return instrumentationFilter; }