List of usage examples for java.util Comparator comparingInt
public static <T> Comparator<T> comparingInt(ToIntFunction<? super T> keyExtractor)
From source file:org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.java
private void determineGlobalShadowOrder() { // Topological sorting with Kahn's algorithm List<Pair<ShadowVariableDescriptor<Solution_>, Integer>> pairList = new ArrayList<>(); Map<ShadowVariableDescriptor<Solution_>, Pair<ShadowVariableDescriptor<Solution_>, Integer>> shadowToPairMap = new HashMap<>(); for (EntityDescriptor<Solution_> entityDescriptor : entityDescriptorMap.values()) { for (ShadowVariableDescriptor<Solution_> shadow : entityDescriptor .getDeclaredShadowVariableDescriptors()) { int sourceSize = shadow.getSourceVariableDescriptorList().size(); Pair<ShadowVariableDescriptor<Solution_>, Integer> pair = MutablePair.of(shadow, sourceSize); pairList.add(pair);/*w w w . j av a2 s .c om*/ shadowToPairMap.put(shadow, pair); } } for (EntityDescriptor<Solution_> entityDescriptor : entityDescriptorMap.values()) { for (GenuineVariableDescriptor<Solution_> genuine : entityDescriptor .getDeclaredGenuineVariableDescriptors()) { for (ShadowVariableDescriptor<Solution_> sink : genuine.getSinkVariableDescriptorList()) { Pair<ShadowVariableDescriptor<Solution_>, Integer> sinkPair = shadowToPairMap.get(sink); sinkPair.setValue(sinkPair.getValue() - 1); } } } int globalShadowOrder = 0; while (!pairList.isEmpty()) { pairList.sort(Comparator.comparingInt(Pair::getValue)); Pair<ShadowVariableDescriptor<Solution_>, Integer> pair = pairList.remove(0); ShadowVariableDescriptor<Solution_> shadow = pair.getKey(); if (pair.getValue() != 0) { if (pair.getValue() < 0) { throw new IllegalStateException("Impossible state because the shadowVariable (" + shadow.getSimpleEntityAndVariableName() + ") can not be used more as a sink than it has sources."); } throw new IllegalStateException("There is a cyclic shadow variable path" + " that involves the shadowVariable (" + shadow.getSimpleEntityAndVariableName() + ") because it must be later than its sources (" + shadow.getSourceVariableDescriptorList() + ") and also earlier than its sinks (" + shadow.getSinkVariableDescriptorList() + ")."); } for (ShadowVariableDescriptor<Solution_> sink : shadow.getSinkVariableDescriptorList()) { Pair<ShadowVariableDescriptor<Solution_>, Integer> sinkPair = shadowToPairMap.get(sink); sinkPair.setValue(sinkPair.getValue() - 1); } shadow.setGlobalShadowOrder(globalShadowOrder); globalShadowOrder++; } }
From source file:org.sejda.impl.sambox.component.OutlineUtils.java
/** * @param document// www. j a v a 2 s. c o m * @return A sorted flat representation of the document outline */ public static List<OutlineItem> getFlatOutline(PDDocument document) { return ofNullable(document.getDocumentCatalog().getDocumentOutline()).map(PDDocumentOutline::children) .map(c -> recurseFlatOutline(document, c, 1)).orElseGet(ArrayList::new).stream() .sorted(Comparator.comparingInt(i -> i.page)).collect(Collectors.toList()); }
From source file:org.talend.dataprep.transformation.service.TransformationService.java
/** * Get the available export formats/* w ww . jav a2 s .c o m*/ */ @RequestMapping(value = "/export/formats", method = GET) @ApiOperation(value = "Get the available format types") @Timed @PublicAPI public Stream<ExportFormatMessage> exportTypes() { return formatRegistrationService.getExternalFormats() // .sorted(Comparator.comparingInt(ExportFormat::getOrder)) // Enforce strict order. .map(f -> beanConversionService.convert(f, ExportFormatMessage.class)) // .filter(ExportFormatMessage::isEnabled); }
From source file:org.talend.dataprep.transformation.service.TransformationService.java
/** * Get the available export formats for dataset. */// ww w . ja v a 2 s .c o m @RequestMapping(value = "/export/formats/datasets/{dataSetId}", method = GET) @ApiOperation(value = "Get the available format types for the preparation") @Timed public Stream<ExportFormatMessage> getPreparationExportTypesForDataSet(@PathVariable String dataSetId) { final DataSetMetadata metadata = context.getBean(DataSetGetMetadata.class, dataSetId).execute(); return formatRegistrationService.getExternalFormats() // .sorted(Comparator.comparingInt(ExportFormat::getOrder)) // Enforce strict order. .filter(ExportFormat::isEnabled) // .filter(f -> f.isCompatible(metadata)) // .map(f -> beanConversionService.convert(f, ExportFormatMessage.class)); }
From source file:org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder.java
private Comparator<ClaimFilter> getClaimFilterComparator() { // Sort based on priority in descending order, ie. highest priority comes to the first element of the list. return Comparator.comparingInt(ClaimFilter::getPriority).reversed(); }
From source file:org.wso2.carbon.identity.openidconnect.internal.OpenIDConnectServiceComponent.java
private Comparator<OpenIDConnectClaimFilter> getOIDCClaimFilterComparator() { // Sort based on priority in descending order, ie. highest priority comes to the first element of the list. return Comparator.comparingInt(OpenIDConnectClaimFilter::getPriority).reversed(); }