List of usage examples for java.util List sort
@SuppressWarnings({ "unchecked", "rawtypes" }) default void sort(Comparator<? super E> c)
From source file:org.nuxeo.ecm.core.storage.dbs.DBSCachingRepository.java
@Override public List<State> readStates(List<String> ids) { ImmutableMap<String, State> statesMap = cache.getAllPresent(ids); List<String> idsToRetrieve = new ArrayList<>(ids); idsToRetrieve.removeAll(statesMap.keySet()); // Read missing states from repository List<State> states = repository.readStates(idsToRetrieve); // Cache them states.forEach(this::putInCache); // Add previous cached one states.addAll(statesMap.values());/*from w ww .ja v a 2 s . c om*/ // Sort them states.sort(Comparator.comparing(state -> state.get(KEY_ID).toString(), Ordering.explicit(ids))); return states; }
From source file:com.navercorp.pinpoint.common.server.bo.thrift.SpanFactory.java
private List<AnnotationBo> buildAnnotationList(List<TAnnotation> tAnnotationList) { if (tAnnotationList == null) { return new ArrayList<>(); }/*from w ww . j av a2s .c o m*/ List<AnnotationBo> boList = new ArrayList<>(tAnnotationList.size()); for (TAnnotation tAnnotation : tAnnotationList) { final AnnotationBo annotationBo = newAnnotationBo(tAnnotation); boList.add(annotationBo); } boList.sort(AnnotationComparator.INSTANCE); return boList; }
From source file:org.openehr.designer.repository.file.FileTemplateRepository.java
@Override public List<TemplateInfo> listTemplates() { List<TemplateInfo> result = templateMap.entrySet().stream().map(e -> { Archetype template = e.getValue().get(0); ArchetypeWrapper wrapper = new ArchetypeWrapper(template); String templateId = e.getKey(); String rmType = template.getDefinition().getRmTypeName(); String name = wrapper.getTermText(template.getDefinition().getNodeId()); return new TemplateInfo(templateId, rmType, name); }).collect(Collectors.toList()); result.sort((t, o) -> ObjectUtils.compare(t.getName(), o.getName())); return result; }
From source file:io.github.jeddict.jpa.modeler.widget.JavaClassWidget.java
public List<AttributeWidget<? extends Attribute>> getAllSortedAttributeWidgets() { List<AttributeWidget<? extends Attribute>> attributeWidgets = getAllAttributeWidgets(true); AttributeLocationComparator attributeLocationComparator = new AttributeLocationComparator(); attributeWidgets.sort( (a1, a2) -> attributeLocationComparator.compare(a1.getBaseElementSpec(), a2.getBaseElementSpec())); return attributeWidgets; }
From source file:org.talend.dataprep.transformation.actions.date.AbstractDate.java
/** * @return the Parameters to display for the date related action. */// w w w .j a v a 2 s . c o m protected List<Parameter> getParametersForDatePattern() { ResourceBundle patterns = ResourceBundle .getBundle("org.talend.dataprep.transformation.actions.date.date_patterns", Locale.ENGLISH); Enumeration<String> keys = patterns.getKeys(); List<Item> items = new ArrayList<>(); Item defaultItem = null; while (keys.hasMoreElements()) { String key = keys.nextElement(); String value = patterns.getString(key); Item item = Item.Builder.builder().value(value).label(key).build(); items.add(item); if ("ISO".equals(key)) { defaultItem = item; } } if (defaultItem == null) { defaultItem = items.get(0); } items.sort((item, t1) -> item.getLabel().compareTo(t1.getLabel())); List<Parameter> parameters = new ArrayList<>(); parameters.add(SelectParameter.Builder.builder() // .name(NEW_PATTERN) // .items(items) // .item("custom", CUSTOM_PATTERN_PARAMETER) // .defaultValue(defaultItem.getValue()) // .build()); return parameters; }
From source file:ch.eitchnet.csvrestendpoint.marshaller.CsvDataToJsonMarshaller.java
@Override public JsonObject marshall(CSVParser csvParser) { // validate any references to column names Map<String, Integer> headerMap = csvParser.getHeaderMap(); validate(headerMap);//from w w w. ja v a 2 s . co m // filter List<CSVRecord> allRecords = new ArrayList<>(); long dataSetSize = 0; for (CSVRecord record : csvParser) { dataSetSize++; if (isSelected(headerMap, record)) allRecords.add(record); } // sort if (StringHelper.isNotEmpty(sortBy)) { Integer columnIndex = headerMap.get(sortBy); if (this.ascending) allRecords.sort((r1, r2) -> r1.get(columnIndex).compareTo(r2.get(columnIndex))); else allRecords.sort((r1, r2) -> r2.get(columnIndex).compareTo(r1.get(columnIndex))); } // paging Paging<CSVRecord> paging = Paging.asPage(allRecords, this.pageSize, this.page); // get page List<CSVRecord> page = paging.getPage(); // build JSON response JsonObject root = new JsonObject(); root.addProperty("msg", "-"); root.addProperty("draw", this.draw); root.addProperty("dataSetSize", dataSetSize); root.addProperty("nrOfElements", paging.getNrOfElements()); if (StringHelper.isNotEmpty(sortBy)) root.addProperty("sortBy", this.sortBy); root.addProperty("ascending", this.ascending); root.addProperty("nrOfPages", paging.getNrOfPages()); root.addProperty("pageSize", paging.getPageSize()); root.addProperty("page", paging.getPageToReturn()); // prune any unwanted columns if (!this.returnFields.isEmpty()) { headerMap.keySet().retainAll(this.returnFields); } // add items JsonArray data = new JsonArray(); for (CSVRecord record : page) { JsonObject element = new JsonObject(); for (Entry<String, Integer> entry : headerMap.entrySet()) { String column = entry.getKey(); String value = record.get(entry.getValue()); element.addProperty(column, value); } data.add(element); } root.add("data", data); return root; }
From source file:at.salzburgresearch.vgi.vgianalyticsframework.osm.importer.impl.VgiOperationGeneratorDataHandlerImpl.java
/** * Adds coordinates to operations (OpAddNode, OpModifyWayCoordinate) * @param refElements list of child elements (way nodes and relation members) *//*from w w w. ja va2s.c om*/ private void addCoordinateToOperations(List<IVgiFeature> refElements) { log.info(refElements.size() + " ref elements found!"); refElements.sort(VgiFeatureImpl.getFeatureComparator()); int numFound = 0, numNotFound = 0; for (IVgiFeature feature : featureList) { TLongObjectHashMap<List<IVgiOperation>> childElementHistories = new TLongObjectHashMap<List<IVgiOperation>>(); TLongObjectHashMap<List<IVgiOperation>> featureChildElements = new TLongObjectHashMap<List<IVgiOperation>>(); /** Add coordinates to OpAddNode operations */ for (IVgiOperation featureOperation : feature.getOperationList()) { /** Create childElementHistory (will be used for adding OpModifyWayCoordinate) */ if (featureOperation.getVgiOperationType().equals(VgiOperationType.OP_ADD_NODE) || featureOperation.getVgiOperationType().equals(VgiOperationType.OP_REMOVE_NODE) || featureOperation.getVgiOperationType().equals(VgiOperationType.OP_ADD_MEMBER) || featureOperation.getVgiOperationType().equals(VgiOperationType.OP_REMOVE_MEMBER)) { if (!childElementHistories.containsKey(featureOperation.getRefId())) { /** Initialize child element history */ childElementHistories.put(featureOperation.getRefId(), new ArrayList<IVgiOperation>()); } childElementHistories.get(featureOperation.getRefId()).add(featureOperation); } /** Only OpAddNode (and OpAddMember) */ //TODO relations are not implemented from here to end if (!featureOperation.getVgiOperationType().equals(VgiOperationType.OP_ADD_NODE)) continue; /** Find ref element */ IVgiFeature refElement = null; IVgiFeature refElementForSearch = new VgiFeatureImpl(); refElementForSearch.setOid(featureOperation.getRefId()); if (featureOperation.getVgiOperationType().equals(VgiOperationType.OP_ADD_NODE)) { refElementForSearch.setVgiGeometryType(VgiGeometryType.POINT); } else if (featureOperation.getVgiOperationType().equals(VgiOperationType.OP_ADD_MEMBER)) { if (featureOperation.getKey().equals("n")) { refElementForSearch.setVgiGeometryType(VgiGeometryType.POINT); } else if (featureOperation.getKey().equals("w")) { refElementForSearch.setVgiGeometryType(VgiGeometryType.LINE); } else if (featureOperation.getKey().equals("r")) { refElementForSearch.setVgiGeometryType(VgiGeometryType.RELATION); } } int index = Collections.binarySearch(refElements, refElementForSearch, VgiFeatureImpl.getFeatureComparator()); if (index >= 0) { refElement = refElements.get(index); numFound++; } else { numNotFound++; if (settings.getFilterPolygon() == null) { /** only write error if no polygon filter is set */ if (numNotFound % 10000 == 0) log.error(featureOperation.getVgiGeometryType() + "/" + featureOperation.getOid() + "/v" + featureOperation.getVersion() + ": Cannot find ref element " + refElementForSearch.getVgiGeometryType() + "/" + refElementForSearch.getOid() + " (" + numNotFound + "/" + (numFound + numNotFound) + ")"); } continue; } /** Operations for added nodes */ featureChildElements.put(refElement.getOid(), refElement.getOperationList()); /** Some nodes are added to way before they are created (e.g. node 20950647 in way 4848297) */ /** we want to find a coordinate, also if the node has been created too late... */ for (IVgiOperation childNodeOperation : refElement.getOperationList()) { /** only operations which have a coordinate */ if (childNodeOperation.getCoordinate() == null) continue; /** Find latest node coordinate */ /** if (coordinate not found yet OR operation timestamp not after changeset timestamp */ if (featureOperation.getCoordinate() != null && childNodeOperation.getTimestamp().after(featureOperation.getTimestamp())) break; /** Add coordinate to operation */ featureOperation.setCoordinate(new Coordinate(childNodeOperation.getCoordinate())); } } /** Add OpModifyWayCoordinate operations */ for (long childElementId : featureChildElements .keys()) { /** Nodes which are part of way twice are processed once */ /** Get operations and sort them */ List<IVgiOperation> childElementHistory = childElementHistories.get(childElementId); List<IVgiOperation> childNodeOperations = featureChildElements.get(childElementId); Collections.sort(childElementHistory, VgiOperationImpl.getVersionComparator()); Collections.sort(childNodeOperations, VgiOperationImpl.getVersionComparator()); /** Add operation to feature if node is in node list at this timestamp */ for (IVgiOperation nodeOperation : childNodeOperations) { /** Only OpModifyCoordinate */ if (!nodeOperation.getVgiOperationType().equals(VgiOperationType.OP_MODIFY_COORDINATE)) continue; int membershipCount = 0; /** Iterate through OpAddNodes and OpRemoveNodes */ for (int i = 0; i < childElementHistory.size(); i++) { /** We want the way node history before the node operation */ if (childElementHistory.get(i).getTimestamp().after(nodeOperation.getTimestamp())) break; if (childElementHistory.get(i).getVgiOperationType().equals(VgiOperationType.OP_ADD_NODE)) membershipCount++; if (childElementHistory.get(i).getVgiOperationType() .equals(VgiOperationType.OP_REMOVE_NODE)) membershipCount--; } /** Node should be member of way at least once */ if (membershipCount == 0) continue; /** Add OP_UPDATE_WAY_COORDINATE */ IVgiOperation newOperation = new VgiOperationImpl(feature.getOid(), feature.getVgiGeometryType(), VgiOperationType.OP_MODIFY_WAY_COORDINATE, nodeOperation.getUid(), nodeOperation.getUser(), nodeOperation.getTimestamp(), Short.MAX_VALUE, nodeOperation.getChangesetid(), nodeOperation.getCoordinate(), "", "", nodeOperation.getOid(), -1); /** Find index and version with feature operation list */ int index = Collections.binarySearch(feature.getOperationList(), newOperation, VgiOperationImpl.getTimestampComparator()); if (index >= 0) { /** Timestamp/OpType combination already exists */ newOperation.setVersion(feature.getOperationList().get(index).getVersion()); feature.getOperationList().add(index + 1, newOperation); } else { index = (index + 1) * -1; newOperation.setVersion(feature.getOperationList().get(index - 1).getVersion()); feature.getOperationList().add(index, newOperation); } } } /** Sort operations */ Collections.sort(feature.getOperationList(), VgiOperationImpl.getVersionComparator()); } }
From source file:org.grouplens.samantha.modeler.knn.KnnModelFeatureTrigger.java
public List<ObjectNode> getTriggeredFeatures(List<ObjectNode> bases) { Object2DoubleMap<String> item2score = new Object2DoubleOpenHashMap<>(); int numInter = 0; for (ObjectNode inter : bases) { double weight = 1.0; if (inter.has(weightAttr)) { weight = inter.get(weightAttr).asDouble(); }//from w ww .ja v a 2 s . co m String key = FeatureExtractorUtilities.composeConcatenatedKey(inter, feaAttrs); if (weight >= 0.5 && featureKnnModel != null) { getNeighbors(item2score, featureKnnModel, key, weight); } if (weight < 0.5 && featureKdnModel != null) { getNeighbors(item2score, featureKdnModel, key, weight); } numInter++; if (numInter >= maxInter) { break; } } List<ObjectNode> results = new ArrayList<>(); for (Map.Entry<String, Double> entry : item2score.entrySet()) { ObjectNode entity = Json.newObject(); Map<String, String> attrVals = FeatureExtractorUtilities.decomposeKey(entry.getKey()); for (Map.Entry<String, String> ent : attrVals.entrySet()) { entity.put(ent.getKey(), ent.getValue()); } entity.put(scoreAttr, entry.getValue()); results.add(entity); } results.sort(SortingUtilities.jsonFieldReverseComparator(scoreAttr)); return results; }
From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.OrganizerImpl.java
private List<Tag> getAllTags() { LOGGER.debug("fetching categories"); try {//from w w w . j ava 2s .com List<Tag> list = tagService.getAllTags(); LOGGER.debug("fetching categories succeeded with {} items", list.size()); list.sort((a, b) -> a.getName().compareTo(b.getName())); list.add(0, null); return list; } catch (ServiceException ex) { LOGGER.error("fetching categories failed", ex); ErrorDialog.show(root, "Fehler beim Laden", "Foto-Kategorien konnten nicht geladen werden."); return new ArrayList<>(); } }
From source file:jease.Registry.java
private void initDomainTypes(Set<String> domainClasses) { List<Content> contentList = new ArrayList<>(); TreeSet<Property> propertyList = new TreeSet<>(Comparator.comparing(Property::getType)); for (String domainClass : domainClasses) { Object obj = Reflections.newInstance(domainClass); if (Content.class.isInstance(obj)) { contentList.add((Content) obj); }//from w ww. j a v a 2s . co m if (Property.class.isInstance(obj)) { propertyList.add((Property) obj); } } contentList.sort(Comparator.comparing(Content::getType)); contents = contentList.toArray(new Content[contentList.size()]); properties = propertyList; }