com.google.common.collect.ComparisonChain Java Examples
The following examples show how to use
com.google.common.collect.ComparisonChain.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatatypeLong.java From metanome-algorithms with Apache License 2.0 | 6 votes |
public DatatypeLong(final Comparator<Long> comparator) { this.specificType = type.LONG; if (comparator == null) { this.indexedComparator = new Comparator<RowIndexedLongValue>() { @Override public int compare(final RowIndexedLongValue o1, final RowIndexedLongValue o2) { return ComparisonChain.start() .compare(o1.value, o2.value, Ordering.natural().nullsFirst()).result(); } }; } else { this.indexedComparator = new Comparator<RowIndexedLongValue>() { @Override public int compare(final RowIndexedLongValue o1, final RowIndexedLongValue o2) { return ComparisonChain.start() .compare(o1.value, o2.value, Ordering.from(comparator).nullsFirst()).result(); } }; } }
Example #2
Source File: CxxLinkGroupMappingTarget.java From buck with Apache License 2.0 | 6 votes |
@Override public int compareTo(CxxLinkGroupMappingTarget that) { if (this == that) { return 0; } int labelComparison = compareLabelPattern(that); if (labelComparison != 0) { return labelComparison; } return ComparisonChain.start() .compare(this.getBuildTarget(), that.getBuildTarget()) .compare(this.getTraversal(), that.getTraversal()) .result(); }
Example #3
Source File: AbstractTabListLogicTestBase.java From BungeeTabListPlus with GNU General Public License v3.0 | 6 votes |
List<TabListEntry> getVisibleEntries() { if (visibleEntries == null) { List<TabListEntry> entries = new ArrayList<>(this.entries.values()); entries.sort(new Comparator<TabListEntry>() { @Override public int compare(TabListEntry o1, TabListEntry o2) { return ComparisonChain.start().compareTrueFirst(o1.getGamemode() != 3, o2.getGamemode() != 3) .compare(MoreObjects.firstNonNull(playerToTeamMap.get(o1.getUsername()), ""), MoreObjects.firstNonNull(playerToTeamMap.get(o2.getUsername()), "")) .compare(o1.getUsername(), o2.getUsername()).result(); } }); if (entries.size() > 80) { entries = entries.subList(0, 80); } visibleEntries = Collections.unmodifiableList(entries); } return visibleEntries; }
Example #4
Source File: CheckContextsGenerator.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * This method sorts all contexts alphabetically so that the file always gets generated in the same order. * * @param model * context model */ private void sortAllContexts(final CtxHelpModel model) { Ordering<CtxHelpContext> ordering = Ordering.from((a, b) -> ComparisonChain.start().compare(a.getId(), b.getId()).result()); List<CtxHelpContext> allContexts = Lists.newArrayList(Iterables.filter(model.getCtxHelpRoot().getChildren(), CtxHelpContext.class)); List<CtxHelpContext> expectedContexts = ordering.sortedCopy(allContexts); CtxHelpRoot root = model.getCtxHelpRoot(); if (!expectedContexts.equals(allContexts)) { for (int i = 0; i < expectedContexts.size(); i++) { CtxHelpContext expected = expectedContexts.get(i); CtxHelpContext actual = allContexts.get(i); if (!actual.getId().equals(expected.getId())) { root.swap(actual, expected); allContexts.set(allContexts.indexOf(expected), actual); allContexts.set(i, expected); } } } }
Example #5
Source File: FrameworkUtils.java From data-polygamy with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override // TODO: is this efficient enough? It seems slow public int compareTo(MultipleSpatioTemporalWritable arg0) { spatialComp = arg0.getSpatial(); temporalComp = arg0.getTemporal(); ch = ComparisonChain.start(); // assuming they have the same size for (int i = 0; i < this.spatial.length; i++) ch = ch.compare(this.spatial[i], spatialComp[i]); for (int i = 0; i < this.temporal.length; i++) ch = ch.compare(this.temporal[i], temporalComp[i]); return ch.result(); }
Example #6
Source File: TypesRegistryServiceImpl.java From sql-layer with GNU Affero General Public License v3.0 | 6 votes |
private Object typesDescriptors() { List<Map<String,Comparable<?>>> result = new ArrayList<>(tClasses.size()); for (TClass tClass : tClasses) { Map<String,Comparable<?>> map = new LinkedHashMap<>(); buildTName("bundle", "name", tClass, map); map.put("category", tClass.name().categoryName()); map.put("internalVersion", tClass.internalRepresentationVersion()); map.put("serializationVersion", tClass.serializationVersion()); map.put("fixedSize", tClass.hasFixedSerializationSize() ? tClass.fixedSerializationSize() : null); result.add(map); } Collections.sort(result, new Comparator<Map<String, Comparable<?>>>() { @Override public int compare(Map<String, Comparable<?>> o1, Map<String, Comparable<?>> o2) { return ComparisonChain.start() .compare(o1.get("bundle"), o2.get("bundle")) .compare(o1.get("category"), o2.get("category")) .compare(o1.get("name"), o2.get("name")) .result(); } }); return result; }
Example #7
Source File: AegisthusKey.java From aegisthus with Apache License 2.0 | 6 votes |
public int compareTo(@Nonnull AegisthusKey other, Comparator<ByteBuffer> nameComparator) { // This is a workaround for comparators not handling nulls properly // The case where name or timestamp is null should only happen when there has been a delete int result = this.key.compareTo(other.key); if (result != 0) { return result; } result = this.sourcePath.compareTo(other.sourcePath); if (result != 0) { return result; } if (this.name == null || this.timestamp == null) { return -1; } else if (other.name == null || other.timestamp == null) { return 1; } return ComparisonChain.start() .compare(this.name, other.name, nameComparator) .compare(this.timestamp, other.timestamp) .result(); }
Example #8
Source File: ClaimCountTask.java From emodb with Apache License 2.0 | 6 votes |
@Override public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception { Map<String, Long> map = _eventStore.snapshotClaimCounts(); if (map.isEmpty()) { output.println("no claims"); return; } // Sort the entries in the map from biggest to smallest. List<Map.Entry<String,Long>> entries = Lists.newArrayList(map.entrySet()); Collections.sort(entries, new Comparator<Map.Entry<String, Long>>() { @Override public int compare(Map.Entry<String, Long> e1, Map.Entry<String, Long> e2) { return ComparisonChain.start() .compare(e2.getValue(), e1.getValue()) // Sort counts descending .compare(e1.getKey(), e2.getKey()) // Sort channel names ascending .result(); } }); // Print a formatted table with two columns. for (Map.Entry<String, Long> entry : entries) { output.println(Strings.padStart(entry.getValue().toString(), 9, ' ') + " " + entry.getKey()); } }
Example #9
Source File: ByJustificationLocation.java From tac-kbp-eal with MIT License | 6 votes |
@Override public int compare(final Answerable left, final Answerable right) { final Optional<Response> earliestLeftResponse = earliestResponse(left); final Optional<Response> earliestRightResponse = earliestResponse(right); if (earliestLeftResponse.isPresent()) { if (earliestRightResponse.isPresent()) { return ComparisonChain.start() .compare(earliestLeftResponse.get(), earliestRightResponse.get(), Response.ByJustificationLocation) .compare(left, right) .result(); } else { return -1; } } else if (earliestRightResponse.isPresent()) { return 1; } else { return left.compareTo(right); } }
Example #10
Source File: BlobValue.java From scalardb with Apache License 2.0 | 6 votes |
@Override public int compareTo(BlobValue o) { if (bytes.isPresent() && o.bytes.isPresent()) { return ComparisonChain.start() .compare(bytes.get(), o.bytes.get()) .compare(this.name, o.name) .result(); } else { // either bytes or o.bytes is empty if (bytes.isPresent()) { return 1; } else if (o.bytes.isPresent()) { return -1; } else { return 0; } } }
Example #11
Source File: MySQLVersion.java From guacamole-client with Apache License 2.0 | 6 votes |
/** * Returns whether this version is at least as recent as the given version. * * @param version * The version to compare against. * * @return * true if the versions are associated with the same database server * type (MariaDB vs. MySQL) and this version is at least as recent as * the given version, false otherwise. */ public boolean isAtLeast(MySQLVersion version) { // If the databases use different version numbering schemes, the // version numbers are not comparable if (isMariaDB != version.isMariaDB) return false; // Compare major, minor, and patch number in order of precedence return ComparisonChain.start() .compare(major, version.major) .compare(minor, version.minor) .compare(patch, version.patch) .result() >= 0; }
Example #12
Source File: SingularityTaskHistoryQuery.java From Singularity with Apache License 2.0 | 6 votes |
public Comparator<SingularityTaskIdHistory> getComparator() { final OrderDirection localOrderDirection = orderDirection.orElse(OrderDirection.DESC); return new Comparator<SingularityTaskIdHistory>() { @Override public int compare(SingularityTaskIdHistory o1, SingularityTaskIdHistory o2) { ComparisonChain chain = ComparisonChain.start(); if (localOrderDirection == OrderDirection.ASC) { chain = chain.compare(o1.getUpdatedAt(), o2.getUpdatedAt()); } else { chain = chain.compare(o2.getUpdatedAt(), o1.getUpdatedAt()); } return chain .compare(o1.getTaskId().getRequestId(), o2.getTaskId().getRequestId()) .result(); } }; }
Example #13
Source File: BrooklynImageChooser.java From brooklyn-server with Apache License 2.0 | 6 votes |
/** @deprecated since 0.7.0; kept for persisted state backwards compatibility */ @Deprecated @SuppressWarnings("unused") private static Ordering<Image> orderingWithDefaultsDeprecated(final Ordering<Image> primaryOrdering) { return new Ordering<Image>() { @Override public int compare(Image left, Image right) { return ComparisonChain.start() .compare(left, right, primaryOrdering) // fall back to default strategy otherwise, except preferring *non*-null values // TODO suggest to use NaturalOrderComparator (so 10>9) then order by: // 1) `name.replaceAll("([^0-9]+)", " ")` // 2) shortest non-empty name // 3) version (NaturalOrderComparator, prefer last) // 4) name (NaturalOrderComparator, prefer last) // 5) other fields (NaturalOrderComparator, prefer last) .compare(left.getName(), right.getName(), Ordering.<String> natural().nullsFirst()) .compare(left.getVersion(), right.getVersion(), Ordering.<String> natural().nullsFirst()) .compare(left.getDescription(), right.getDescription(), Ordering.<String> natural().nullsFirst()) .compare(left.getOperatingSystem().getName(), right.getOperatingSystem().getName(), Ordering.<String> natural().nullsFirst()) .compare(left.getOperatingSystem().getVersion(), right.getOperatingSystem().getVersion(), Ordering.<String> natural().nullsFirst()) .compare(left.getOperatingSystem().getDescription(), right.getOperatingSystem().getDescription(), Ordering.<String> natural().nullsFirst()) .compare(left.getOperatingSystem().getArch(), right.getOperatingSystem().getArch(), Ordering.<String> natural().nullsFirst()).result(); } }; }
Example #14
Source File: TermOccurrenceUtils.java From termsuite-core with Apache License 2.0 | 5 votes |
@Override public int compare(TermOccurrence o1, TermOccurrence o2) { return ComparisonChain.start() .compare(o1.getSourceDocument().getUrl(), o2.getSourceDocument().getUrl()) .compare(o1.getBegin(), o2.getBegin()) .compare(o2.getEnd(), o1.getEnd()) .result(); }
Example #15
Source File: CodaDocHead.java From estatio with Apache License 2.0 | 5 votes |
@Override public int compareTo(final CodaDocHead other) { return ComparisonChain.start() .compare(getCmpCode(), other.getCmpCode()) .compare(getDocCode(), other.getDocCode()) .compare(getDocNum(), other.getDocNum()) .result(); }
Example #16
Source File: VersionedName.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override public int compare(VersionedName o1, VersionedName o2) { if (o1==null) { return o2==null ? 0 : 1; } if (o2==null) { return -1; } return ComparisonChain.start() .compare(o1.getSymbolicName(), o2.getSymbolicName(), NaturalOrderComparator.INSTANCE) .compare(o2.getOsgiVersionString(), o1.getOsgiVersionString(), VersionComparator.INSTANCE) .compare(o2.getVersionString(), o1.getVersionString(), VersionComparator.INSTANCE) .result(); }
Example #17
Source File: Unique.java From data-polygamy with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public int compareTo(Aggregation arg0) { Unique agg = (Unique) arg0; return ComparisonChain.start(). compare(values.size(), agg.getValues().size()). compare(count, agg.getCount()). result(); }
Example #18
Source File: PermissionDetails.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Override public int compareTo(PermissionDetails other) { return ComparisonChain.start() .compare(username, other.username) .compare(resource.getName(), other.resource.getName()) .compare(permission, other.permission) .result(); }
Example #19
Source File: FrameworkUtils.java From data-polygamy with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public int compareTo(FloatArrayWritable arg0) { float[] thatVal = arg0.get(); ComparisonChain ch = ComparisonChain.start(); // assuming they have the same size for (int i = 0; i < this.values.length; i++) ch = ch.compare(this.values[i], thatVal[i]); return ch.result(); }
Example #20
Source File: SortUtils.java From zhcet-web with Apache License 2.0 | 5 votes |
public static void sortCourses(List<Course> courses) { courses.sort((course1, course2) -> ComparisonChain.start() .compare(course1.getSemester(), course2.getSemester(), Ordering.natural().nullsFirst()) .compare(course1.getCode(), course2.getCode()) .result() ); }
Example #21
Source File: SwaptionSensitivity.java From Strata with Apache License 2.0 | 5 votes |
@Override public int compareKey(PointSensitivity other) { if (other instanceof SwaptionSensitivity) { SwaptionSensitivity otherSwpt = (SwaptionSensitivity) other; return ComparisonChain.start() .compare(volatilitiesName, otherSwpt.volatilitiesName) .compare(currency, otherSwpt.currency) .compare(expiry, otherSwpt.expiry) .compare(tenor, otherSwpt.tenor) .compare(strike, otherSwpt.strike) .compare(forward, otherSwpt.forward) .result(); } return getClass().getSimpleName().compareTo(other.getClass().getSimpleName()); }
Example #22
Source File: SortUtils.java From zhcet-web with Apache License 2.0 | 5 votes |
public static void sortAttendanceUpload(List<AttendanceUpload> attendanceUploads) { attendanceUploads.sort((att1, att2) -> ComparisonChain.start() .compare(att1.getSection(), att2.getSection(), Ordering.natural().nullsFirst()) .compare(att1.getFacultyNo().substring(5), att2.getFacultyNo().substring(5)) .result() ); }
Example #23
Source File: ElasticByteBufferPool.java From big-c with Apache License 2.0 | 5 votes |
@Override public int compareTo(Key other) { return ComparisonChain.start(). compare(capacity, other.capacity). compare(insertionTime, other.insertionTime). result(); }
Example #24
Source File: FrameworkUtils.java From data-polygamy with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public int compareTo(SpatioTemporalFloatWritable arg0) { return ComparisonChain.start() .compare(this.spatial, arg0.getSpatial()) .compare(this.temporal, arg0.getTemporal()) .compare(this.value, arg0.getValue()) .result(); }
Example #25
Source File: SingularityDeployMarker.java From Singularity with Apache License 2.0 | 5 votes |
@Override public int compareTo(SingularityDeployMarker o) { return ComparisonChain .start() .compare(timestamp, o.getTimestamp()) .compare(deployId, o.getDeployId()) .result(); }
Example #26
Source File: IssueAcceptor.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Convert the given issues to diagnostics. Does not return issues in files that are neither in the workspace nor * currently opened in the editor. Does not return any issue with severity {@link Severity#IGNORE ignore}. */ protected List<Diagnostic> toDiagnostics(Iterable<? extends LSPIssue> issues) { if (IterableExtensions.isEmpty(issues)) { return Collections.emptyList(); } List<Diagnostic> sortedDiags = new ArrayList<>(); for (LSPIssue issue : issues) { if (issue.getSeverity() != Severity.IGNORE) { sortedDiags.add(diagnosticIssueConverter.toDiagnostic(issue)); } } // Sort issues according to line and position final Comparator<Diagnostic> comparator = new Comparator<>() { @Override public int compare(Diagnostic d1, Diagnostic d2) { Position p1 = d1.getRange().getStart(); Position p2 = d2.getRange().getStart(); int result = ComparisonChain.start() .compare(p1.getLine(), p2.getLine()) .compare(p2.getCharacter(), p2.getCharacter()) .result(); return result; } }; Collections.sort(sortedDiags, comparator); return sortedDiags; }
Example #27
Source File: CurrencyParameterSensitivity.java From Strata with Apache License 2.0 | 5 votes |
/** * Compares the key of two sensitivity objects, excluding the parameter sensitivity values. * * @param other the other sensitivity object * @return positive if greater, zero if equal, negative if less */ public int compareKey(CurrencyParameterSensitivity other) { return ComparisonChain.start() .compare(marketDataName, other.marketDataName) .compare(currency, other.currency) .result(); }
Example #28
Source File: Scope.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public int compareTo(final Scope other) { return ComparisonChain.start().compare(code, other.code) .compare(scopeType, other.scopeType).compare(type, other.type) .compare(astNodeType, other.astNodeType) .compare(astParentNodeType, other.astParentNodeType).result(); }
Example #29
Source File: Version.java From ScoreboardStats with MIT License | 5 votes |
@Override public int compareTo(Version other) { return ComparisonChain.start() .compare(major, other.major) .compare(minor, other.minor) .compare(build, other.build) .result(); }
Example #30
Source File: FunctionIdent.java From crate with Apache License 2.0 | 5 votes |
@Override public int compareTo(FunctionIdent o) { return ComparisonChain.start() .compare(fqnName, o.fqnName) .compare(argumentTypes, o.argumentTypes, Ordering.<DataType<?>>natural().lexicographical()) .result(); }