/** * Returns a comparator of {@link Optional} values which treats {@link Optional#empty} as less * than all other values, and orders the rest using {@code valueComparator} on the contained * value. * * @since 22.0 */ @Beta public static <T> Comparator<Optional<T>> emptiesFirst(Comparator<? super T> valueComparator) { checkNotNull(valueComparator); return Comparator.comparing(o -> o.orElse(null), Comparator.nullsFirst(valueComparator)); }
@Override public Comparator<String> getComparator() { return Comparator.nullsFirst(Comparator.naturalOrder()); }
public static Comparator<TestResult> comparingByTimeAsc() { return comparing( TestResult::getTime, nullsFirst(comparing(Time::getStart, nullsFirst(naturalOrder()))) ); }
private Ordering<Row> dimensionOrdering(final String dimension, final StringComparator comparator) { return Ordering.from( Comparator.comparing((Row row) -> getDimensionValue(row, dimension), Comparator.nullsFirst(comparator)) ); }
@Override public Comparator getComparator( final List<AggregatorFactory> aggregatorSpecs, final List<PostAggregator> postAggregatorSpecs ) { return Comparator.nullsFirst(delegate.getComparator(aggregatorSpecs, postAggregatorSpecs).reversed()); }
/** * Returns a comparator of {@link Optional} values which treats {@link Optional#empty} as less * than all other values, and orders the rest using {@code valueComparator} on the contained * value. * * @since 22.0 */ @Beta public static <T> Comparator<Optional<T>> emptiesFirst(Comparator<? super T> valueComparator) { checkNotNull(valueComparator); return Comparator.comparing(o -> o.orElse(null), Comparator.nullsFirst(valueComparator)); }
/** * Returns a comparator of {@link Optional} values which treats {@link Optional#empty} as less * than all other values, and orders the rest using {@code valueComparator} on the contained * value. * * @since 22.0 */ @Beta public static <T> Comparator<Optional<T>> emptiesFirst(Comparator<? super T> valueComparator) { checkNotNull(valueComparator); return Comparator.comparing(o -> o.orElse(null), Comparator.nullsFirst(valueComparator)); }
private static Optional<ExecutorInfo> extractLatestExecutor(final List<LaunchResults> launches) { final Comparator<ExecutorInfo> comparator = comparing(ExecutorInfo::getBuildOrder, nullsFirst(naturalOrder())); return launches.stream() .map(launch -> launch.getExtra(EXECUTORS_BLOCK_NAME)) .filter(Optional::isPresent) .map(Optional::get) .filter(ExecutorInfo.class::isInstance) .map(ExecutorInfo.class::cast) .max(comparator); }
private static Optional<ExecutorInfo> extractLatestExecutor(final List<LaunchResults> launches) { final Comparator<ExecutorInfo> comparator = comparing(ExecutorInfo::getBuildOrder, nullsFirst(naturalOrder())); return launches.stream() .map(launch -> launch.getExtra(EXECUTORS_BLOCK_NAME)) .filter(Optional::isPresent) .map(Optional::get) .filter(ExecutorInfo.class::isInstance) .map(ExecutorInfo.class::cast) .max(comparator); }
private List<Parameter> getParameters(final TestResult result) { final TreeSet<Parameter> parametersSet = new TreeSet<>( comparing(Parameter::getName, nullsFirst(naturalOrder())) .thenComparing(Parameter::getValue, nullsFirst(naturalOrder())) ); parametersSet.addAll(convert(result.getParameters(), this::convert)); return new ArrayList<>(parametersSet); }
private static Optional<ExecutorInfo> extractLatestExecutor(final List<LaunchResults> launches) { final Comparator<ExecutorInfo> comparator = comparing(ExecutorInfo::getBuildOrder, nullsFirst(naturalOrder())); return launches.stream() .map(launch -> launch.getExtra(EXECUTORS_BLOCK_NAME)) .filter(Optional::isPresent) .map(Optional::get) .filter(ExecutorInfo.class::isInstance) .map(ExecutorInfo.class::cast) .max(comparator); }
private List<Parameter> getParameters(final TestCaseResult source) { final TreeSet<Parameter> parametersSet = new TreeSet<>( comparing(Parameter::getName, nullsFirst(naturalOrder())) .thenComparing(Parameter::getValue, nullsFirst(naturalOrder())) ); parametersSet.addAll(convert(source.getParameters(), this::hasArgumentType, this::convert)); return new ArrayList<>(parametersSet); }
private static Optional<ExecutorInfo> extractLatestExecutor(final List<LaunchResults> launches) { final Comparator<ExecutorInfo> comparator = comparing(ExecutorInfo::getBuildOrder, nullsFirst(naturalOrder())); return launches.stream() .map(launch -> launch.getExtra(EXECUTORS_BLOCK_NAME)) .filter(Optional::isPresent) .map(Optional::get) .filter(ExecutorInfo.class::isInstance) .map(ExecutorInfo.class::cast) .max(comparator); }
private Ordering<Row> metricOrdering(final String column, final Comparator comparator) { // As per SQL standard we need to have same ordering for metrics as dimensions i.e nulls first // If SQL compatibility is not enabled we use nullsLast ordering for null metrics for backwards compatibility. if (NullHandling.sqlCompatible()) { return Ordering.from(Comparator.comparing((Row row) -> row.getRaw(column), Comparator.nullsFirst(comparator))); } else { return Ordering.from(Comparator.comparing((Row row) -> row.getRaw(column), Comparator.nullsLast(comparator))); } }
private UnaryOperator<ListResponse.Builder> addNotifications(DbSession dbSession, UserDto user) { return response -> { List<PropertyDto> properties = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).build(), dbSession); Map<Long, ComponentDto> componentsById = searchProjects(dbSession, properties); Map<String, OrganizationDto> organizationsByUuid = getOrganizations(dbSession, componentsById.values()); Predicate<PropertyDto> isNotification = prop -> prop.getKey().startsWith("notification."); Predicate<PropertyDto> isComponentInDb = prop -> prop.getResourceId() == null || componentsById.containsKey(prop.getResourceId()); Notification.Builder notification = Notification.newBuilder(); properties.stream() .filter(isNotification) .filter(channelAndDispatcherAuthorized()) .filter(isComponentInDb) .map(toWsNotification(notification, organizationsByUuid, componentsById)) .sorted(comparing(Notification::getProject, nullsFirst(naturalOrder())) .thenComparing(comparing(Notification::getChannel)) .thenComparing(comparing(Notification::getType))) .forEach(response::addNotifications); return response; }; }
Arrays.sort(keyArray, Comparator.nullsFirst( Comparator.comparing(this::getRelativeFilePath)));
comparing(Label::getName, nullsFirst(naturalOrder())) .thenComparing(Label::getValue, nullsFirst(naturalOrder())) ); set.addAll(convert(testSuite.getLabels(), this::convert));
Comparator<Student> cmp = Comparator.comparing(Student::getName, Comparator.nullsFirst(String.CASE_INSENSITIVE_ORDER));
/** * Returns a {@code RangeValidator} comparing values of a {@code Comparable} * type using their <i>natural order</i>. Passing null to either * {@code minValue} or {@code maxValue} means there is no limit in that * direction. Both limits may be null; this can be useful if the limits are * resolved programmatically. * <p> * Null is considered to be less than any non-null value. This means null * never passes validation if a minimum value is specified. * * @param <C> * the {@code Comparable} value type * @param errorMessage * the error message to return if validation fails, not null * @param minValue * the least value of the accepted range or null for no limit * @param maxValue * the greatest value of the accepted range or null for no limit * @return the new validator */ public static <C extends Comparable<? super C>> RangeValidator<C> of( String errorMessage, C minValue, C maxValue) { return new RangeValidator<>(errorMessage, Comparator.nullsFirst(Comparator.naturalOrder()), minValue, maxValue); }
/** * Returns one active replica shard for the given shard id or <code>null</code> if * no active replica is found. * * Since replicas could possibly be on nodes with a older version of ES than * the primary is, this will return replicas on the highest version of ES. * */ public ShardRouting activeReplicaWithHighestVersion(ShardId shardId) { // It's possible for replicaNodeVersion to be null, when deassociating dead nodes // that have been removed, the shards are failed, and part of the shard failing // calls this method with an out-of-date RoutingNodes, where the version might not // be accessible. Therefore, we need to protect against the version being null // (meaning the node will be going away). return assignedShards(shardId).stream() .filter(shr -> !shr.primary() && shr.active()) .filter(shr -> node(shr.currentNodeId()) != null) .max(Comparator.comparing(shr -> node(shr.currentNodeId()).node(), Comparator.nullsFirst(Comparator.comparing(DiscoveryNode::getVersion)))) .orElse(null); }