List of usage examples for java.util Comparator naturalOrder
@SuppressWarnings("unchecked") public static <T extends Comparable<? super T>> Comparator<T> naturalOrder()
From source file:com.netflix.spinnaker.igor.build.BuildCache.java
public List<String> getDeprecatedJobNames(String master) { List<String> jobs = new ArrayList<>(); redisClientDelegate.withKeyScan(baseKey() + ":" + master + ":*", 1000, page -> jobs.addAll( page.getResults().stream().map(BuildCache::extractDeprecatedJobName).collect(Collectors.toList()))); jobs.sort(Comparator.naturalOrder()); return jobs;//from w w w . ja va 2 s. c o m }
From source file:com.netflix.spinnaker.halyard.core.registry.v1.Versions.java
public static Comparator<String> orderBySemVer() { Comparator<SemVer> comparator = Comparator.nullsLast(SemVer.comparator()); return Comparator.comparing(SemVer::fromString, comparator).thenComparing(Comparator.naturalOrder()); }
From source file:com.haulmont.cuba.core.sys.AppProperties.java
/** * @return all property names defined in the set of {@code app.properties} files and exported by the app components *///from w w w .ja v a 2s. c o m public String[] getPropertyNames() { Set<String> namesSet = new HashSet<>(); for (AppComponent appComponent : appComponents.getComponents()) { namesSet.addAll(appComponent.getPropertyNames()); } namesSet.addAll(properties.keySet()); List<String> list = new ArrayList<>(namesSet); list.sort(Comparator.naturalOrder()); return list.toArray(new String[list.size()]); }
From source file:io.github.moosbusch.lumpi.gui.form.spi.AbstractDynamicForm.java
protected final Form.Section createSection(Class<?> beanClass, PropertyDescriptor[] propDescs) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { Form.Section result = new Form.Section(); String sectHeading = getSectionHeading(); Map<String, Class<?>> propertyMap = new HashMap<>(); propertyMap.setComparator(Comparator.naturalOrder()); if ((isShowSectionHeading()) && (StringUtils.isNotBlank(sectHeading))) { result.setHeading(sectHeading);/* w w w . ja va 2 s. co m*/ } for (PropertyDescriptor propDesc : propDescs) { propertyMap.put(propDesc.getName(), propDesc.getPropertyType()); } for (String propertyName : propertyMap) { Class<?> propertyClass = ClassUtils.primitiveToWrapper(propertyMap.get(propertyName)); FormEditor<? extends Component> editor; if (!isExcludedProperty(beanClass, propertyName)) { editor = getEditor(beanClass.getName(), propertyClass.getName(), propertyName); if (editor != null) { Component cmp = editor.getComponent(); PropertyUtils.setProperty(cmp, editor.getDataBindingKeyPropertyName(), propertyName); setLabel(cmp, StringUtils.capitalize(propertyName)); if (editor.isScrollable()) { ScrollPane scroll = Objects.requireNonNull(createScrollPane()); scroll.setView(cmp); result.add(scroll); } else { result.add(cmp); } } } } return result; }
From source file:com.netflix.imfutility.itunes.destcontext.InputDestContextResolveStrategy.java
private <T extends Comparable<T>> T getMinResourceParameterValue(ContextInfo contextInfo, ResourceContextParameters parameter, Function<String, T> parser) { return segmentStream(contextInfo).flatMap(this::resourceStream) .map(info -> getResourceParameterValue(info, parameter, parser)).min(Comparator.naturalOrder()) .get();/*from w w w .ja v a 2s. c o m*/ }
From source file:io.undertow.servlet.test.listener.request.async.AsyncListenerExceptionTest.java
private void doTest(String urlTail, boolean timeout) throws IOException, InterruptedException { TestHttpClient client = new TestHttpClient(); try {//w w w .j a v a 2s. c o m HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/" + urlTail); if (timeout) { get.addHeader("timeout", "true"); } HttpResponse result = client.execute(get); Assert.assertEquals(timeout ? 500 : 200, result.getStatusLine().getStatusCode()); HttpClientUtils.readResponse(result); List<String> expected = new LinkedList<>(); expected.add("onComplete"); expected.add("onComplete"); if (timeout) { expected.add("onTimeout"); expected.add("onTimeout"); } List<String> actual = new LinkedList<>(); for (int i = 0; i < expected.size(); i++) { actual.add(AbstractAsyncServlet.QUEUE.poll(10, TimeUnit.SECONDS)); } actual.sort(Comparator.naturalOrder()); Assert.assertEquals(expected, actual); } finally { client.getConnectionManager().shutdown(); } }
From source file:com.publictransitanalytics.scoregenerator.datalayer.directories.GTFSReadingStopTimesDirectory.java
private void parseStopTimesFile(final ImmutableSetMultimap<String, FrequencyRecord> frequencyRecordMap, final Reader stopTimesReader) throws FileNotFoundException, IOException, InterruptedException { final CSVParser parser = new CSVParser(stopTimesReader, CSVFormat.DEFAULT.withHeader()); final SortedSetMultimap<String, RawTripStop> rawTripMap = TreeMultimap.create(Comparator.naturalOrder(), (stop1, stop2) -> Integer.compare(stop1.getSequence(), stop2.getSequence())); final Iterator<CSVRecord> stopTimesIter = parser.iterator(); while (stopTimesIter.hasNext()) { final CSVRecord record = stopTimesIter.next(); final String rawTripId = record.get("trip_id"); final int stopSequence = Integer.valueOf(record.get("stop_sequence")); final String stopId = record.get("stop_id"); final String arrivalTimeString = record.get("arrival_time"); final TransitTime arrivalTime = (arrivalTimeString == null) ? null : TransitTime.parse(arrivalTimeString); final String departureTimeString = record.get("departure_time"); final TransitTime departureTime = (departureTimeString == null) ? null : TransitTime.parse(arrivalTimeString); if (frequencyRecordMap.containsKey(rawTripId)) { final RawTripStop rawTripStop = new RawTripStop(arrivalTime, departureTime, stopId, rawTripId, stopSequence);/* w w w .j a v a2s .c o m*/ rawTripMap.put(rawTripId, rawTripStop); } else { final TripId tripId = new TripId(rawTripId); final TripStop tripStop = new TripStop(arrivalTime, stopId, tripId, stopSequence); try { final TripIdKey tripIdKey = new TripIdKey(rawTripId); tripsStore.put(tripIdKey, tripId); tripSequenceStore.put(new TripSequenceKey(tripIdKey, arrivalTime, stopSequence), tripStop); stopTimesStore.put(StopTimeKey.getWriteKey(stopId, arrivalTime), tripStop); } catch (final BitvantageStoreException e) { throw new ScoreGeneratorFatalException(e); } } } for (final String rawTripId : rawTripMap.keySet()) { final ImmutableSet<FrequencyRecord> frequencyRecords = frequencyRecordMap.get(rawTripId); for (final FrequencyRecord frequencyRecord : frequencyRecords) { TransitTime recurringTime = frequencyRecord.getStartTime(); while (recurringTime.isBefore(frequencyRecord.getEndTime())) { final TransitTime baseArrivalTime = rawTripMap.get(rawTripId).first().getArrivalTime(); final TripId tripId = new TripId(rawTripId, recurringTime.toString()); for (final RawTripStop rawTripStop : rawTripMap.get(rawTripId)) { final TransitTime arrivalTime = recurringTime .plus(TransitTime.durationBetween(baseArrivalTime, rawTripStop.getArrivalTime())); final int stopSequence = rawTripStop.getSequence(); final String stopId = rawTripStop.getStopId(); final TripStop tripStop = new TripStop(arrivalTime, stopId, tripId, stopSequence); final TripIdKey tripIdKey = new TripIdKey(tripId.getRawTripId(), tripId.getQualifier()); try { tripsStore.put(tripIdKey, tripId); tripSequenceStore.put(new TripSequenceKey(tripIdKey, arrivalTime, stopSequence), tripStop); stopTimesStore.put(StopTimeKey.getWriteKey(stopId, arrivalTime), tripStop); } catch (final BitvantageStoreException e) { throw new ScoreGeneratorFatalException(e); } } recurringTime = recurringTime.plus(frequencyRecord.getInterval()); } } } }
From source file:com.acmutv.ontoqa.tool.io.IOManagerTest.java
/** * Tests directory listing.//w w w . j a v a 2 s. c o m */ @Test public void test_listAllFiles() throws IOException { String directory = IOManagerTest.class.getResource("/tool/io/").getPath(); List<Path> actual = IOManager.allFiles(directory); actual.sort(Comparator.naturalOrder()); List<Path> expected = new ArrayList<>(); expected.add( FileSystems.getDefault().getPath(IOManagerTest.class.getResource("/tool/io/sample").getPath())); expected.add( FileSystems.getDefault().getPath(IOManagerTest.class.getResource("/tool/io/sample.txt").getPath())); expected.sort(Comparator.naturalOrder()); Assert.assertEquals(expected, actual); }
From source file:com.acmutv.ontoqa.tool.io.IOManagerTest.java
/** * Tests directory listing with filter.//from w w w. j a v a 2s .co m */ @Test public void test_listAllFiles_withExtension() throws IOException { String directory = IOManagerTest.class.getResource("/tool/io/").getPath(); List<Path> actual = IOManager.allFiles(directory, "*.txt"); actual.sort(Comparator.naturalOrder()); List<Path> expected = new ArrayList<>(); expected.add( FileSystems.getDefault().getPath(IOManagerTest.class.getResource("/tool/io/sample.txt").getPath())); expected.sort(Comparator.naturalOrder()); Assert.assertEquals(expected, actual); }
From source file:com.evolveum.midpoint.schema.util.WfContextUtil.java
@NotNull private static List<ApprovalStageDefinitionType> getSortedStages(ApprovalSchemaType schema) { List<ApprovalStageDefinitionType> stages = new ArrayList<>(getStages(schema)); stages.sort(/*from www. j ava 2s . c o m*/ Comparator.comparing(stage -> getNumber(stage), Comparator.nullsLast(Comparator.naturalOrder()))); return stages; }