List of usage examples for com.google.common.collect Ordering natural
@GwtCompatible(serializable = true) @SuppressWarnings("unchecked") public static <C extends Comparable> Ordering<C> natural()
From source file:org.isisaddons.app.kitchensink.dom.other.OtherBoundedObject.java
@Override public int compareTo(OtherBoundedObject other) { return Ordering.natural().onResultOf(OtherBoundedObject::getName).compare(this, other); }
From source file:org.apache.gobblin.data.management.copy.replication.ReplicationDataValidPathPicker.java
@SuppressWarnings("unchecked") public static Collection<Path> getValidPaths(HadoopFsEndPoint hadoopFsEndPoint) throws IOException { Config selectionConfig = hadoopFsEndPoint.getSelectionConfig(); FileSystemDataset tmpDataset = new HadoopFsEndPointDataset(hadoopFsEndPoint); FileSystem theFs = FileSystem.get(hadoopFsEndPoint.getFsURI(), new Configuration()); /**/*ww w .j a va2 s . co m*/ * Use {@link FileSystemDatasetVersion} as * {@link DateTimeDatasetVersionFinder} / {@link GlobModTimeDatasetVersionFinder} use {@link TimestampedDatasetVersion} * {@link SingleVersionFinder} uses {@link FileStatusDatasetVersion} */ VersionFinder<FileSystemDatasetVersion> finder; try { finder = (VersionFinder<FileSystemDatasetVersion>) ConstructorUtils.invokeConstructor( Class.forName(selectionConfig.getString(FINDER_CLASS)), theFs, selectionConfig); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new IllegalArgumentException(e); } List<FileSystemDatasetVersion> versions = Ordering.natural().reverse() .sortedCopy(finder.findDatasetVersions(tmpDataset)); VersionSelectionPolicy<FileSystemDatasetVersion> selector; try { selector = (VersionSelectionPolicy<FileSystemDatasetVersion>) ConstructorUtils .invokeConstructor(Class.forName(selectionConfig.getString(POLICY_CLASS)), selectionConfig); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new IllegalArgumentException(e); } Collection<FileSystemDatasetVersion> versionsSelected = selector.listSelectedVersions(versions); List<Path> result = new ArrayList<Path>(); for (FileSystemDatasetVersion t : versionsSelected) { // get the first element out result.add(t.getPaths().iterator().next()); } return result; }
From source file:dmg.util.command.AnnotatedCommandUtils.java
/** * Returns the arguments fields of a given command class. *///from w w w . j a va2 s. c o m public static List<Field> getArguments(Class<?> clazz) { List<Field> arguments = Lists.newArrayList(); for (Class<?> c = clazz; c != null; c = c.getSuperclass()) { for (Field field : c.getDeclaredFields()) { if (field.isAnnotationPresent(Argument.class)) { arguments.add(field); } } } Collections.sort(arguments, Ordering.natural().onResultOf(GET_ARGUMENT_INDEX)); return arguments; }
From source file:de.cubeisland.engine.core.util.matcher.StringMatcher.java
/** * Returns all matches with their editDistance, having an editDistance <= maxDistance * * @param search the String to search for * @param in the Strings to match in/* w w w . j av a 2s . c o m*/ * @param maxDistance the maximum editDistance * @param ignoreCase * @return a map of all matches sorted by their editDistance */ public TreeMap<String, Integer> getMatches(String search, Collection<String> in, int maxDistance, boolean ignoreCase) { if (maxDistance < 1) { CubeEngine.getLog().warn(new Throwable(), "Checking EditDistance lower than 1!"); return new TreeMap<>(); } Map<String, Integer> matches = new HashMap<>(); Ordering<String> comparator = Ordering.natural().onResultOf(Functions.forMap(matches)) .compound(Ordering.natural()); for (String target : in) { int distance = target.length() - search.length(); if (distance > maxDistance || -distance > maxDistance) // too long/short to match { continue; } if (ignoreCase) { distance = this.editDistance.executeIgnoreCase(search, target); } else { distance = this.editDistance.execute(search, target); } if (distance <= maxDistance) { matches.put(target, distance); } } TreeMap<String, Integer> result = new TreeMap<>(comparator); result.putAll(matches); return result; }
From source file:components.cells.Cells.java
private static <T> Map<IPosition, T> merge(final T initialSymbol, final Map<IPosition, T> left, final Map<IPosition, T> right) { final Builder<IPosition, T> builder = new ImmutableSortedMap.Builder<IPosition, T>(Ordering.natural()); final MapDifference<IPosition, T> difference = Maps.difference(left, right); for (final Entry<IPosition, T> mutation : difference.entriesInCommon().entrySet()) if (!mutation.getValue().equals(initialSymbol)) builder.put(mutation);/*from w w w . j ava2s.c o m*/ for (final Entry<IPosition, T> mutation : difference.entriesOnlyOnLeft().entrySet()) if (!mutation.getValue().equals(initialSymbol)) builder.put(mutation); for (final Entry<IPosition, T> mutation : difference.entriesOnlyOnRight().entrySet()) if (!mutation.getValue().equals(initialSymbol)) builder.put(mutation); for (final Entry<IPosition, ValueDifference<T>> mutation : difference.entriesDiffering().entrySet()) { final T rightValue = mutation.getValue().rightValue(); if (!rightValue.equals(initialSymbol)) builder.put(mutation.getKey(), rightValue); } return builder.build(); }
From source file:org.jetbrains.jet.plugin.DirectiveBasedActionUtils.java
public static void checkForUnexpectedErrors(JetFile file) { if (!InTextDirectivesUtils.findLinesWithPrefixesRemoved(file.getText(), "// DISABLE-ERRORS").isEmpty()) { return;/*from ww w . j a v a2s.c o m*/ } AnalyzeExhaust exhaust = AnalyzerFacadeWithCache.analyzeFileWithCache(file); Collection<Diagnostic> diagnostics = exhaust.getBindingContext().getDiagnostics().all(); Collection<Diagnostic> errorDiagnostics = Collections2.filter(diagnostics, new Predicate<Diagnostic>() { @Override public boolean apply(@Nullable Diagnostic diagnostic) { assert (diagnostic != null); return diagnostic.getSeverity() == Severity.ERROR; } }); Collection<String> actualErrorStrings = Collections2.transform(errorDiagnostics, new Function<Diagnostic, String>() { @Override public String apply(@Nullable Diagnostic diagnostic) { assert (diagnostic != null); return IdeErrorMessages.RENDERER.render(diagnostic); } }); List<String> expectedErrorStrings = InTextDirectivesUtils.findLinesWithPrefixesRemoved(file.getText(), "// ERROR:"); Collections.sort(expectedErrorStrings); UsefulTestCase.assertOrderedEquals( "All actual errors should be mentioned in test data with // ERROR: directive. But no unnecessary errors should be me mentioned", Ordering.natural().sortedCopy(actualErrorStrings), expectedErrorStrings); }
From source file:org.sonar.server.computation.task.projectanalysis.issue.ScmAccountToUserLoader.java
@Override public String load(String scmAccount) { List<UserDoc> users = index.getAtMostThreeActiveUsersForScmAccount(scmAccount); if (users.size() == 1) { return users.get(0).login(); }//from ww w. j a v a2 s .co m if (!users.isEmpty()) { // multiple users are associated to the same SCM account, for example // the same email Collection<String> logins = users.stream().map(UserDoc::login).sorted(Ordering.natural()) .collect(MoreCollectors.toList(users.size())); LOGGER.warn(String.format("Multiple users share the SCM account '%s': %s", scmAccount, Joiner.on(", ").join(logins))); } return null; }
From source file:com.github.jtse.puzzle.ui.MedianMouseEventFilter.java
MouseEvent median() {
return new MouseEvent(Ordering.natural().sortedCopy(xs).get(middle),
Ordering.natural().sortedCopy(ys).get(middle), Ordering.natural().sortedCopy(booleans).get(middle));
}
From source file:org.isisaddons.app.kitchensink.dom.other.AutoObject.java
@Override public int compareTo(AutoObject other) { return Ordering.natural().onResultOf(AutoObject::getName).compare(this, other); }
From source file:dk.frankbille.scoreboard.components.LeagueSelector.java
public LeagueSelector(String id, IModel<League> model) { super(id, model); setRenderBodyOnly(true);//from w w w . ja v a2 s . c o m final IModel<SortedMap<Boolean, Set<League>>> allLeaguesModel = new LoadableDetachableModel<SortedMap<Boolean, Set<League>>>() { @Override protected SortedMap<Boolean, Set<League>> load() { SortedMap<Boolean, Set<League>> groupedLeagues = new TreeMap<Boolean, Set<League>>( Ordering.natural().reverse()); List<League> allLeagues = scoreBoardService.getAllLeagues(); for (League league : allLeagues) { Set<League> leaguesByState = groupedLeagues.get(league.isActive()); if (leaguesByState == null) { leaguesByState = new HashSet<League>(); groupedLeagues.put(league.isActive(), leaguesByState); } leaguesByState.add(league); } return groupedLeagues; } }; IModel<List<Boolean>> leagueStatesModel = new LoadableDetachableModel<List<Boolean>>() { @Override protected List<Boolean> load() { return new ArrayList<Boolean>(allLeaguesModel.getObject().keySet()); } }; Select<League> select = new Select<League>("select", model) { }; select.add(new Select2Enabler()); select.add(AttributeAppender.replace("class", new AbstractReadOnlyModel<String>() { @Override public String getObject() { return LeagueSelector.this.getMarkupAttributes().getString("class", ""); } })); add(select); select.add(new ListView<Boolean>("leagueGroups", leagueStatesModel) { @Override protected void populateItem(ListItem<Boolean> item) { item.add(AttributeAppender.replace("label", new StringResourceModel("active.${modelObject}", new Model<Serializable>(item)))); List<League> leagueList = Ordering.usingToString() .sortedCopy(allLeaguesModel.getObject().get(item.getModelObject())); item.add(new SelectOptions<League>("leagues", leagueList, new IOptionRenderer<League>() { @Override public String getDisplayValue(League league) { return league.getName(); } @Override public IModel<League> getModel(League league) { return new Model<League>(league); } })); } }); }