/** * Compare two explicitly nullable Revisions. Unlike {@link #compareTo(Revision)}, this handles both arguments * being null such that total ordering is defined. * * @param first First revision * @param second Second revision * @return Positive, zero, or negative integer. */ public static int compare(final @Nullable Revision first, final @Nullable Revision second) { if (first != null) { return second != null ? first.compareTo(second) : 1; } return second != null ? -1 : 0; }
/** * Compare two explicitly nullable Revisions. Unlike {@link #compareTo(Revision)}, this handles both arguments * being null such that total ordering is defined. * * @param first First revision * @param second Second revision * @return Positive, zero, or negative integer. */ public static int compare(final @Nullable Revision first, final @Nullable Revision second) { if (first != null) { return second != null ? first.compareTo(second) : 1; } return second != null ? -1 : 0; }
/** * Compare two {@link Optional}s wrapping Revisions. Arguments and return value are consistent with * {@link java.util.Comparator#compare(Object, Object)} interface contract. Missing revisions compare as lower * than any other revision. * * @param first First optional revision * @param second Second optional revision * @return Positive, zero, or negative integer. */ public static int compare(final @NonNull Optional<Revision> first, final @NonNull Optional<Revision> second) { if (first.isPresent()) { return second.isPresent() ? first.get().compareTo(second.get()) : 1; } return second.isPresent() ? -1 : 0; }
/** * Compare two {@link Optional}s wrapping Revisions. Arguments and return value are consistent with * {@link java.util.Comparator#compare(Object, Object)} interface contract. Missing revisions compare as lower * than any other revision. * * @param first First optional revision * @param second Second optional revision * @return Positive, zero, or negative integer. */ public static int compare(final @NonNull Optional<Revision> first, final @NonNull Optional<Revision> second) { if (first.isPresent()) { return second.isPresent() ? first.get().compareTo(second.get()) : 1; } return second.isPresent() ? -1 : 0; }
public static Optional<Revision> getLatestRevision(final Iterable<? extends StmtContext<?, ?, ?>> subStmts) { Revision revision = null; for (final StmtContext<?, ?, ?> subStmt : subStmts) { if (subStmt.getPublicDefinition().getDeclaredRepresentationClass().isAssignableFrom( RevisionStatement.class)) { if (revision == null && subStmt.getStatementArgument() != null) { revision = (Revision) subStmt.getStatementArgument(); } else { final Revision subArg = (Revision) subStmt.getStatementArgument(); if (subArg != null && subArg.compareTo(revision) > 0) { revision = subArg; } } } } return Optional.ofNullable(revision); } }