Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在树状图中获得一个子集?_Java_Xpages - Fatal编程技术网

Java 如何在树状图中获得一个子集?

Java 如何在树状图中获得一个子集?,java,xpages,Java,Xpages,我有一个 TreeMap map=newtreemap() 根据选择条件在视图中存储文档中的值。map将创建日期存储为键,文档值存储为对象 在对象中,我有一个“form”字段。文件可以有不同的形式(备忘录、通知、传真等) 我有一个返回allEntries的方法。这是正常的,并按预期工作 现在,我想在表单字段上进行选择,以仅返回映射中文档的子集 有人能告诉我正确的方向怎么做吗 您可以使用两个地图来存储数据 一个简单的Hashmap就足以存储与memo notice等相对应的id,并将包含当前格式的

我有一个

TreeMap map=newtreemap()

根据选择条件在视图中存储文档中的值。map将创建日期存储为键,文档值存储为对象

在对象中,我有一个“form”字段。文件可以有不同的形式(备忘录、通知、传真等)

我有一个返回allEntries的方法。这是正常的,并按预期工作

现在,我想在表单字段上进行选择,以仅返回映射中文档的子集


有人能告诉我正确的方向怎么做吗

您可以使用两个地图来存储数据


一个简单的Hashmap就足以存储与memo notice等相对应的id,并将包含当前格式的所有对应数据的树状图作为一个值存储。

由于您要在不是映射键的内容上进行选择,您必须迭代所有项

如果你可以使用外部库,你可以使用谷歌的。即

TreeMap地图=。。。;
最终字符串formValue=“通知”;
Collection result=Collections2.filter(map.values(),new Predicate()){
公共布尔应用(文档输入){
返回formValue.equals(input.getForm());
}
}
您可以 1) 检查所有值并将这些匹配条件放入新集合 2)将其他集合(单独的变量或MAP>存储(或类似的东西,考虑使用SET而不是列表)< /P>
1) 检索速度越慢,删除速度越慢,消耗的内存越多,番石榴库也能正常工作,但有点过分了。因此,我最终得出以下结论

TreeMap<String, Object> mapFiltered = new TreeMap<String, Object>();
LinkedList<CommunicationDocumentEntry> map = new LinkedList<CommunicationDocumentEntry>();

    public Collection<Object> getAllEntries(String frm, boolean order) {
    this.mapFiltered.clear();

    Iterator<CommunicationDocumentEntry> itr = this.map.iterator();
    while (itr.hasNext()) {
        CommunicationDocumentEntry entry = itr.next();
        if (EMPTY_STRING.equals(frm) || frm == null) {
            this.mapFiltered.put(entry.getDateCreated(), entry.getEntry());
        } else {
            if (entry.getForm().toUpperCase().equals(frm.toUpperCase())) {
                this.mapFiltered.put(entry.getDateCreated(), entry.getEntry());
            }
        }
    }

    if (order) {
        return this.mapFiltered.descendingMap().values();
    } else {
        return this.mapFiltered.values();
    }
}
TreeMap mapFiltered=new TreeMap();
LinkedList映射=新建LinkedList();
公共集合getAllEntries(字符串frm,布尔顺序){
这是一个.mapFiltered.clear();
迭代器itr=this.map.Iterator();
while(itr.hasNext()){
CommunicationDocumentEntry=itr.next();
if(空字符串.equals(frm)| | frm==null){
this.mapFiltered.put(entry.getDateCreated(),entry.getEntry());
}否则{
if(entry.getForm().toUpperCase().equals(frm.toUpperCase())){
this.mapFiltered.put(entry.getDateCreated(),entry.getEntry());
}
}
}
如果(订单){
返回此.mapFiltered.DegendingMap().values();
}否则{
返回此.mapFiltered.values();
}
}

当然不是十全十美,但对我来说很有用…

同样,您也可以尝试Commons Collections谓词
TreeMap<String, Object> mapFiltered = new TreeMap<String, Object>();
LinkedList<CommunicationDocumentEntry> map = new LinkedList<CommunicationDocumentEntry>();

    public Collection<Object> getAllEntries(String frm, boolean order) {
    this.mapFiltered.clear();

    Iterator<CommunicationDocumentEntry> itr = this.map.iterator();
    while (itr.hasNext()) {
        CommunicationDocumentEntry entry = itr.next();
        if (EMPTY_STRING.equals(frm) || frm == null) {
            this.mapFiltered.put(entry.getDateCreated(), entry.getEntry());
        } else {
            if (entry.getForm().toUpperCase().equals(frm.toUpperCase())) {
                this.mapFiltered.put(entry.getDateCreated(), entry.getEntry());
            }
        }
    }

    if (order) {
        return this.mapFiltered.descendingMap().values();
    } else {
        return this.mapFiltered.values();
    }
}