Example usage for java.util List sort

List of usage examples for java.util List sort

Introduction

In this page you can find the example usage for java.util List sort.

Prototype

@SuppressWarnings({ "unchecked", "rawtypes" })
default void sort(Comparator<? super E> c) 

Source Link

Document

Sorts this list according to the order induced by the specified Comparator .

Usage

From source file:org.opennms.smoketest.topo.GraphMLTopologyIT.java

@Test
public void canUseTopology() throws IOException {
    topologyUIPage.selectTopologyProvider(() -> LABEL);
    topologyUIPage.defaultFocus();/*  w w  w  .  j  a v  a  2 s . c o  m*/

    List<TopologyIT.FocusedVertex> focusedVertices = topologyUIPage.getFocusedVertices();
    assertEquals(4, focusedVertices.size());
    assertEquals(4, topologyUIPage.getVisibleVertices().size());
    assertEquals(1, topologyUIPage.getSzl());
    focusedVertices.sort(Comparator.comparing(TopologyIT.FocusedVertex::getNamespace)
            .thenComparing(TopologyIT.FocusedVertex::getLabel));
    assertEquals(Lists.newArrayList(focusVertex(topologyUIPage, "Acme:regions:", "East Region"),
            focusVertex(topologyUIPage, "Acme:regions:", "North Region"),
            focusVertex(topologyUIPage, "Acme:regions:", "South Region"),
            focusVertex(topologyUIPage, "Acme:regions:", "West Region")), focusedVertices);

    // Search for and select a region
    final String regionName = "South";
    TopologyIT.TopologyUISearchResults searchResult = topologyUIPage.search(regionName);
    assertEquals(5, searchResult.countItemsThatContain(regionName));
    searchResult.selectItemThatContains("South Region");

    // Focus should not have changed
    assertEquals(4, focusedVertices.size());
    assertEquals(4, topologyUIPage.getVisibleVertices().size());

    // Verify that the layout is the D3 Layout as this layer does not provide a preferredLayout
    assertEquals(Layout.D3, topologyUIPage.getSelectedLayout());

    // Switch Layer
    topologyUIPage.selectLayer("Markets");
    assertEquals(0, topologyUIPage.getSzl());
    assertEquals(1, topologyUIPage.getFocusedVertices().size());
    assertEquals("North 4", topologyUIPage.getFocusedVertices().get(0).getLabel());
}

From source file:com.joyent.manta.client.MantaObjectDepthComparatorTest.java

public void verifyOrderingWithSmallDataSetAndEmptyDirectories() {
    List<MantaObject> objects = new ArrayList<>();
    List<MantaObject> dirs = dirObjects(12);

    for (MantaObject dir : dirs) {
        objects.add(dir);/*from   ww  w  . j  a  v a  2s  .  c o m*/
        objects.addAll(fileObjects(dir, 3));
        objects.add(mockDirectory(dir.getPath() + MantaClient.SEPARATOR + "empty-dir"));
    }

    Collections.shuffle(objects);

    objects.sort(MantaObjectDepthComparator.INSTANCE);

    assertOrdering(objects);
}

From source file:com.navercorp.pinpoint.web.service.AgentInfoServiceImpl.java

@Override
public AgentDownloadInfo getLatestStableAgentDownloadInfo() {
    if (cachedAgentDownloadInfo != null) {
        return cachedAgentDownloadInfo;
    }/*from  w w w. jav  a  2s .c  o  m*/

    List<AgentDownloadInfo> downloadInfoList = agentDownloadInfoDao.getDownloadInfoList();
    if (CollectionUtils.isEmpty(downloadInfoList)) {
        return null;
    }

    downloadInfoList.sort(new Comparator<AgentDownloadInfo>() {
        @Override
        public int compare(AgentDownloadInfo o1, AgentDownloadInfo o2) {
            return o2.getVersion().compareTo(o1.getVersion());
        }
    });

    // 1st. find same
    for (AgentDownloadInfo downloadInfo : downloadInfoList) {
        if (Version.VERSION.equals(downloadInfo.getVersion())) {
            cachedAgentDownloadInfo = downloadInfo;
            return downloadInfo;
        }
    }

    // 2nd. find lower
    for (AgentDownloadInfo downloadInfo : downloadInfoList) {
        if (Version.VERSION.compareTo(downloadInfo.getVersion()) > 0) {
            cachedAgentDownloadInfo = downloadInfo;
            return downloadInfo;
        }
    }

    // 3rd find greater
    AgentDownloadInfo downloadInfo = ListUtils.getLast(downloadInfoList);
    cachedAgentDownloadInfo = downloadInfo;
    return downloadInfo;
}

From source file:com.searchcode.app.service.CodeMatcher.java

public List<String> splitTerms(String matchTerms) {
    List<String> splitMatchTerms = new ArrayList<>();
    List<String> newTerms = new ArrayList<>();

    for (String s : matchTerms.trim().split(" ")) {
        if (!s.isEmpty()) {
            switch (s) {
            case "AND":
            case "OR":
            case "NOT":
                splitMatchTerms.add(s);/*from   w  ww.j  a  va2  s. c  om*/
                break;
            default:
                splitMatchTerms.add(s.toLowerCase());
            }
        }
    }

    for (String s : splitMatchTerms) {
        for (String t : s.split("\\.")) {
            if (!t.isEmpty()) {
                newTerms.add(t);
            }
        }
        for (String t : s.split("\\(")) {
            if (!t.isEmpty()) {
                newTerms.add(t);
            }
        }
        for (String t : s.split("\\-")) {
            if (!t.isEmpty()) {
                newTerms.add(t);
            }
        }
        for (String t : s.split("<")) {
            if (!t.isEmpty()) {
                newTerms.add(t);
            }
        }
        for (String t : s.split(">")) {
            if (!t.isEmpty()) {
                newTerms.add(t);
            }
        }
        newTerms.add(s);
    }

    // Remove duplicates
    List<String> depdupeTerms = new ArrayList<>(new LinkedHashSet<>(newTerms));
    // Sort largest to smallest to produce largest matching results
    depdupeTerms.sort((p1, p2) -> Integer.valueOf(p2.length()).compareTo(p1.length()));
    return depdupeTerms;
}

From source file:org.apache.syncope.client.console.panels.RealmChoicePanel.java

public RealmChoicePanel(final String id, final PageReference pageRef) {
    super(id);/*  w  w  w .j ava2 s.  c  om*/
    this.pageRef = pageRef;
    tree = new HashMap<>();

    RealmTO fakeRootRealm = new RealmTO();
    fakeRootRealm.setName(SyncopeConstants.ROOT_REALM);
    fakeRootRealm.setFullPath(SyncopeConstants.ROOT_REALM);
    model = Model.of(fakeRootRealm);

    realmTree = new LoadableDetachableModel<List<Pair<String, RealmTO>>>() {

        private static final long serialVersionUID = -7688359318035249200L;

        private void getChildren(final List<Pair<String, RealmTO>> full, final String key,
                final Map<String, Pair<RealmTO, List<RealmTO>>> tree, final String indent) {

            if (tree.containsKey(key)) {
                Pair<RealmTO, List<RealmTO>> subtree = tree.get(key);
                subtree.getValue().forEach(child -> {
                    full.add(Pair.of(indent + child.getName(), child));
                    getChildren(full, child.getKey(), tree,
                            "     " + indent + (indent.isEmpty() ? "|--- " : ""));
                });
            }
        }

        @Override
        protected List<Pair<String, RealmTO>> load() {
            Map<String, Pair<RealmTO, List<RealmTO>>> map = reloadRealmParentMap();
            model.setObject(map.get(null).getKey());

            final List<Pair<String, RealmTO>> full = new ArrayList<>();
            getChildren(full, null, map, StringUtils.EMPTY);
            return full;
        }
    };

    dynRealmTree = new LoadableDetachableModel<List<DynRealmTO>>() {

        private static final long serialVersionUID = 5275935387613157437L;

        @Override
        protected List<DynRealmTO> load() {
            List<DynRealmTO> dynRealms = realmRestClient.listDynReams();
            dynRealms.sort((left, right) -> {
                if (left == null) {
                    return -1;
                } else if (right == null) {
                    return 1;
                } else {
                    return left.getKey().compareTo(right.getKey());
                }
            });

            return dynRealms;
        }
    };

    container = new WebMarkupContainer("container", realmTree);
    container.setOutputMarkupId(true);
    add(container);

    availableRealms = SyncopeConsoleSession.get().getAuthRealms();

    reloadRealmTree();
}

From source file:br.com.webbudget.domain.model.service.PeriodDetailService.java

/**
 * Agrupa todas as datas de pagamento dos movimentos pagos no periodo
 *
 * @param movements a lista de movimentos
 * @return a lista de datas/*  w ww.ja va 2 s  .co m*/
 */
private List<LocalDate> groupPaymentDates(List<Movement> movements) {

    final List<LocalDate> dates = new ArrayList<>();

    movements.stream().forEach(movement -> {
        if (!dates.contains(movement.getPaymentDate())) {
            dates.add(movement.getPaymentDate());
        }
    });

    dates.sort((d1, d2) -> d1.compareTo(d2));

    return dates;
}

From source file:org.fenixedu.ulisboa.integration.sas.ui.spring.controller.manageScholarshipReportRequests.ScholarshipReportRequestController.java

@RequestMapping(value = "/")
public String search(Model model) {
    List<ScholarshipReportRequest> searchscholarshipreportrequestResultsDataSet = getSearchUniverseSearchScholarshipReportRequestDataSet()
            .stream().collect(Collectors.toList());
    Comparator<? super ScholarshipReportRequest> byMoreRecentFirst = (x,
            y) -> x.getWhenRequested().isAfter(y.getWhenRequested()) ? 1 : -1;
    searchscholarshipreportrequestResultsDataSet.sort(byMoreRecentFirst);

    model.addAttribute("searchscholarshipreportrequestResultsDataSet",
            searchscholarshipreportrequestResultsDataSet);
    return "integration/sas/managescholarshipreportrequests/scholarshipreportrequest/search";
}

From source file:org.neo4j.nlp.impl.util.VectorUtil.java

public static Map<String, List<LinkedHashMap<String, Object>>> similarDocumentMapForClass(
        GraphDatabaseService db, String className) {

    Map<String, List<LinkedHashMap<String, Object>>> documents;
    Map<String, List<LinkedHashMap<String, Object>>> results = new HashMap<>();
    List<Integer> featureIndexList;

    VsmCacheModel vsmCacheModel = new VsmCacheModel(db).invoke();
    featureIndexList = vsmCacheModel.getFeatureIndexList();
    documents = vsmCacheModel.getDocuments();

    final String key = className;

    List<LinkedHashMap<String, Object>> resultList = new ArrayList<>();
    LinkedHashMap<String, Double> classMap = new LinkedHashMap<>();

    List<Double> v1 = getFeatureVectorForDocumentClass(documents, featureIndexList, key);

    documents.keySet().stream().filter(otherKey -> !key.equals(otherKey)).forEach(otherKey -> {
        List<Double> v2 = getBinaryFeatureVectorForDocumentClass(documents, featureIndexList, otherKey);
        classMap.put(otherKey, cosineSimilarity(v1, v2));
    });//from ww  w  .  j  av a 2  s . com

    classMap.keySet().forEach(ks -> {
        if (!ks.equals(key) && classMap.get(ks) > 0.0) {
            LinkedHashMap<String, Object> localMap = new LinkedHashMap<>();
            localMap.put("class", ks);
            localMap.put("similarity", classMap.get(ks));
            resultList.add(localMap);
        }
    });

    resultList.sort((a, b) -> {
        Double diff = (((double) a.get("similarity")) - ((double) b.get("similarity")));
        return diff > 0 ? -1 : diff.equals(0.0) ? 0 : 1;
    });

    results.put("classes", resultList);

    return results;
}

From source file:fi.hsl.parkandride.back.RequestLogDao.java

@TransactionalRead
@Override//from w  ww.j a v a2  s . co m
public List<RequestLogEntry> getLogEntriesBetween(DateTime startInclusive, DateTime endInclusive) {
    final BiMap<Long, String> urls = getAllUrlPatterns();
    final BiMap<Long, String> sources = getAllSources();
    final List<RequestLogEntry> list = queryFactory
            .from(qRequestLog).select(constructor(RequestLogEntry.class,
                    new RequestLogKeyProjection(sources, urls), qRequestLog.count))
            .where(qRequestLog.ts.between(startInclusive, endInclusive)).fetch();
    list.sort(comparing(entry -> entry.key));
    return list;
}

From source file:net.sourceforge.pmd.util.fxdesigner.MainDesignerController.java

private void initializeLanguageVersionMenu() {
    List<LanguageVersion> supported = DesignerUtil.getSupportedLanguageVersions();
    supported.sort(LanguageVersion::compareTo);
    languageChoiceBox.getItems().addAll(supported);

    languageChoiceBox.setConverter(DesignerUtil.languageVersionStringConverter());

    languageChoiceBox.getSelectionModel().select(DesignerUtil.defaultLanguageVersion());
    languageChoiceBox.show();//from w w w .  j a  v  a 2 s .  c o m
}