List of usage examples for java.util List sort
@SuppressWarnings({ "unchecked", "rawtypes" }) default void sort(Comparator<? super E> c)
From source file:org.egov.api.controller.EmployeeController.java
private JsonArray createInboxData(final List<StateAware> inboxStates) { JsonArray inboxItems = new JsonArray(); inboxStates.sort(byCreatedDate()); for (final StateAware stateAware : inboxStates) { inboxItems.add(new JsonParser().parse(stateAware.getStateInfoJson()).getAsJsonObject()); }/*from ww w. j a v a2s . c om*/ return inboxItems; }
From source file:io.github.mikesaelim.arxivoaiharvester.xml.XMLParser.java
/** * Parse the XML response from the arXiv OAI repository. * * @throws NullPointerException if xmlResponse is null * @throws ParseException if parsing fails * @throws RepositoryError if the repository's response was parseable but invalid * @throws BadArgumentException if the repository's response contains a BadArgument error * @throws BadResumptionTokenException if the repository's response contains a BadResumptionToken error *//*from www. j a v a 2 s .c o m*/ public ParsedXmlResponse parse(@NonNull InputStream xmlResponse) { OAIPMHtype unmarshalledResponse; try { @SuppressWarnings("unchecked") JAXBElement<OAIPMHtype> jaxbElement = (JAXBElement<OAIPMHtype>) unmarshaller.unmarshal(xmlResponse); unmarshalledResponse = jaxbElement.getValue(); } catch (Exception e) { throw new ParseException("Error unmarshalling XML response from repository", e); } ZonedDateTime responseDate = parseResponseDate(unmarshalledResponse.getResponseDate()); // Parse any errors returned by the repository List<OAIPMHerrorType> errors = Lists.newArrayList(unmarshalledResponse.getError()); if (!errors.isEmpty()) { errors.sort(repositoryErrorSeverityComparator); // ID_DOES_NOT_EXIST and NO_RECORDS_MATCH are not considered errors, and simply result in an empty result set if (errors.get(0).getCode() == OAIPMHerrorcodeType.ID_DOES_NOT_EXIST || errors.get(0).getCode() == OAIPMHerrorcodeType.NO_RECORDS_MATCH) { return ParsedXmlResponse.builder().responseDate(responseDate).records(Lists.newArrayList()).build(); } // Produce error report StringBuilder errorStringBuilder = new StringBuilder("Received error from repository: \n"); errors.stream().forEach(error -> errorStringBuilder.append(error.getCode().value()).append(" : ") .append(normalizeSpace(error.getValue())).append("\n")); String errorString = errorStringBuilder.toString(); // Throw an exception corresponding to the most severe error switch (errors.get(0).getCode()) { case BAD_ARGUMENT: throw new BadArgumentException(errorString); case BAD_RESUMPTION_TOKEN: throw new BadResumptionTokenException(errorString); case BAD_VERB: case CANNOT_DISSEMINATE_FORMAT: case NO_METADATA_FORMATS: case NO_SET_HIERARCHY: default: throw new RepositoryError(errorString); } } // Handle the GetRecord response if (unmarshalledResponse.getGetRecord() != null) { ArticleMetadata record = parseRecord(unmarshalledResponse.getGetRecord().getRecord(), responseDate); return ParsedXmlResponse.builder().responseDate(responseDate).records(Lists.newArrayList(record)) .build(); } // Handle the ListRecords response if (unmarshalledResponse.getListRecords() != null) { ParsedXmlResponse.ParsedXmlResponseBuilder responseBuilder = ParsedXmlResponse.builder() .responseDate(responseDate).records(unmarshalledResponse.getListRecords().getRecord().stream() .map(xmlRecord -> parseRecord(xmlRecord, responseDate)).collect(Collectors.toList())); ResumptionTokenType resumptionToken = unmarshalledResponse.getListRecords().getResumptionToken(); if (resumptionToken != null) { responseBuilder.resumptionToken(normalizeSpace(resumptionToken.getValue())) .cursor(resumptionToken.getCursor()) .completeListSize(resumptionToken.getCompleteListSize()); } return responseBuilder.build(); } // Handling of other response types is undefined throw new RepositoryError("Response from repository was not an error, GetRecord, or ListRecords response"); }
From source file:com.netflix.conductor.dao.dynomite.RedisExecutionDAO.java
@Override public Workflow getWorkflow(String workflowId, boolean includeTasks) { Preconditions.checkNotNull(workflowId, "workflowId name cannot be null"); String json = dynoClient.get(nsKey(WORKFLOW, workflowId)); if (json == null) { throw new ApplicationException(Code.NOT_FOUND, "No such workflow found by id: " + workflowId); }// w w w . j a va2 s .co m Workflow workflow = readValue(json, Workflow.class); if (includeTasks) { List<Task> tasks = getTasksForWorkflow(workflowId); tasks.sort(Comparator.comparingLong(Task::getScheduledTime).thenComparingInt(Task::getSeq)); workflow.setTasks(tasks); } return workflow; }
From source file:fr.lepellerin.ecole.service.internal.CantineServiceImpl.java
@Override @Transactional(readOnly = true)/*from ww w .jav a2 s . c o m*/ public List<ComboItemDto> getMoisOuvertCantine() throws TechnicalException { final Activite activite = this.getCantineActivite(); final List<Ouverture> ouvertures = this.ouvertureRepository.findByActivite(activite); final Set<YearMonth> moisActs = new HashSet<>(); moisActs.add(YearMonth.now()); ouvertures.sort((o1, o2) -> o1.getDate().compareTo(o2.getDate())); ouvertures.forEach(o -> { moisActs.add(YearMonth.from(((java.sql.Date) o.getDate()).toLocalDate())); }); final List<ComboItemDto> comboMois = new ArrayList<>(); moisActs.forEach(ma -> { final Integer id = Integer .valueOf(ma.format(DateTimeFormatter.ofPattern(GeDateUtils.DATE_FORMAT_YYYYMM))); final String libelle = ma.format(DateTimeFormatter.ofPattern(GeDateUtils.DATE_FORMAT_ANNEE_MOIS_FULL)); comboMois.add(new ComboItemDto(id, libelle)); }); comboMois.sort((c1, c2) -> c1.getId().compareTo(c2.getId())); return comboMois; }
From source file:com.yqboots.menu.core.MenuItemManagerImpl.java
/** * {@inheritDoc}/*from w w w.j a va2 s .c o m*/ */ @PostFilter("hasPermission(filterObject, 'READ')") @Override public List<MenuItem> getMenuItems() { final List<MenuItem> results = new ArrayList<>(); final Map<Object, Object> nativeCache = cache.getNativeCache(); results.addAll(nativeCache.values().stream().map(value -> (MenuItem) value).collect(Collectors.toList())); results.sort(new Comparator<MenuItem>() { @Override public int compare(final MenuItem o1, final MenuItem o2) { return o1.getSequentialOrder().compareTo(o2.getSequentialOrder()); } }); return results; }
From source file:com.haulmont.cuba.gui.data.impl.GroupDelegate.java
protected void doGroupSort(CollectionDatasource.Sortable.SortInfo<MetaPropertyPath>[] sortInfo) { if (hasGroups()) { final MetaPropertyPath propertyPath = sortInfo[0].getPropertyPath(); final boolean asc = CollectionDatasource.Sortable.Order.ASC.equals(sortInfo[0].getOrder()); final int index = Arrays.asList(groupProperties).indexOf(propertyPath); if (index > -1) { if (index == 0) { // Sort roots roots.sort(new GroupInfoComparator(asc)); } else { final Object parentProperty = groupProperties[index - 1]; for (final Map.Entry<GroupInfo, List<GroupInfo>> entry : children.entrySet()) { Object property = entry.getKey().getProperty(); if (property.equals(parentProperty)) { entry.getValue().sort(new GroupInfoComparator(asc)); }// ww w. ja v a2s . c om } } } else { final Set<GroupInfo> groups = parents.keySet(); for (final GroupInfo groupInfo : groups) { List<K> items = groupItems.get(groupInfo); if (items != null) { items.sort(new EntityByIdComparator<>(propertyPath, datasource, asc)); } } } } }
From source file:org.springframework.context.support.DefaultLifecycleProcessor.java
private void stopBeans() { Map<String, Lifecycle> lifecycleBeans = getLifecycleBeans(); Map<Integer, LifecycleGroup> phases = new HashMap<>(); lifecycleBeans.forEach((beanName, bean) -> { int shutdownOrder = getPhase(bean); LifecycleGroup group = phases.get(shutdownOrder); if (group == null) { group = new LifecycleGroup(shutdownOrder, this.timeoutPerShutdownPhase, lifecycleBeans, false); phases.put(shutdownOrder, group); }// ww w . j ava 2s. c om group.add(beanName, bean); }); if (!phases.isEmpty()) { List<Integer> keys = new ArrayList<>(phases.keySet()); keys.sort(Collections.reverseOrder()); for (Integer key : keys) { phases.get(key).stop(); } } }
From source file:cc.kave.commons.pointsto.evaluation.events.MRREvaluation.java
private Set<ICoReTypeName> getQueryTypes(Collection<Map<ICompletionEvent, List<Usage>>> eventUsages) { List<ICoReTypeName> types = new ArrayList<>(eventUsages.stream().flatMap(eu -> eu.values().stream()) .flatMap(u -> u.stream()).map(u -> u.getType()).collect(Collectors.toSet())); types.sort(new TypeNameComparator()); return Sets.newLinkedHashSet(types); }
From source file:com.evolveum.midpoint.provisioning.impl.ShadowCaretaker.java
public List<PendingOperationType> sortPendingOperations(List<PendingOperationType> pendingOperations) { // Copy to mutable list that is not bound to the prism List<PendingOperationType> sortedList = new ArrayList<>(pendingOperations.size()); sortedList.addAll(pendingOperations); sortedList.sort((o1, o2) -> XmlTypeConverter.compare(o1.getRequestTimestamp(), o2.getRequestTimestamp())); return sortedList; }
From source file:org.primeframework.mvc.control.form.LocaleSelect.java
/** * Adds the countries Map and then calls super. */// ww w .j a v a 2 s . c om @Override protected Map<String, Object> makeParameters() { LinkedHashMap<String, String> locales = new LinkedHashMap<>(); String preferred = (String) attributes.get("preferredLocales"); if (preferred != null) { String[] parts = preferred.split(","); for (String part : parts) { Locale locale = LocaleUtils.toLocale(part); locales.put(locale.toString(), locale.getDisplayName(locale)); } } boolean includeCountries = attributes.containsKey("includeCountries") ? (Boolean) attributes.get("includeCountries") : true; List<Locale> allLocales = new ArrayList<>(); Collections.addAll(allLocales, Locale.getAvailableLocales()); allLocales.removeIf((locale) -> locale.getLanguage().isEmpty() || locale.hasExtensions() || !locale.getScript().isEmpty() || !locale.getVariant().isEmpty() || (!includeCountries && !locale.getCountry().isEmpty())); allLocales.sort((one, two) -> one.getDisplayName(locale).compareTo(two.getDisplayName(locale))); for (Locale locale : allLocales) { if (!locales.containsKey(locale.getCountry())) { locales.put(locale.toString(), locale.getDisplayName(this.locale)); } } attributes.put("items", locales); return super.makeParameters(); }