根据标签对列表进行排序

时间:2019-05-03 11:13:59

标签: java

我有一个包含几个对象的列表:

public class ListIssues
{
    private long id;
    private String title;
    private List<Label> labels;
    ...
}

我将所有内容保存在要排序的列表中。依次包含低,中,高...的第一个对象应放入列表中。

List<ListIssues> listIssues;

对于列表标签,我有几种类型:“高,中,低”

我尝试过:

        for (int w = 0; w < listIssues.size(); w++)
        {
            ListIssues get = listIssues.get(w);

            List<String> priorityLabelsList = new ArrayList<String>(); 
            priorityLabelsList.add("low");
            priorityLabelsList.add("medium");
            priorityLabelsList.add("high");
            priorityLabelsList.add("critical");            

            boolean valid_labels = get.getLabels().stream().anyMatch(priorityLabelsList::contains);

            if (valid_labels) {
                String label_in_current_objext = get.getLabels().get(0).getName();
               /// implement there main list sorting
            }

        }

如何根据标签内容对listIssues对象位置进行排序?

我尝试使用listIssues.sort(Comparator.comparing(ListIssues::getLabels).thenComparing(MyClass::getDate));,但我得到The type ListIssues does not define getLabels(T) that is applicable here

具有匹配项的第二个解决方案:

    List<String> priorityLabelsList = new ArrayList<String>(); 
                priorityLabelsList.add("low");
                priorityLabelsList.add("medium");
                priorityLabelsList.add("high");
                priorityLabelsList.add("critical");            


    List<Label> list; 

    list.get(0).getLabels().stream().anyMatch(priorityLabelsList::contains)

But how to get which exactly String is matched? IS there any way to print it?

0 个答案:

没有答案