我必须通过Map过滤对象集合,它保存对象字段名称和字段值的键值对.我试图通过stream().filter()应用所有过滤器.
对象实际上是JSON,因此Map保存其变量的名称以及它们必须包含的值以便被接受,但为了简单起见并且因为它与问题无关,我编写了一个简单的Testclass来模拟行为:
public class TestObject {
private int property1;
private int property2;
private int property3;
public TestObject(int property1, int property2, int property3) {
this.property1 = property1;
this.property2 = property2;
this.property3 = property3;
}
public int getProperty(int key) {
switch(key) {
case 1: return property1;
case 2: return property2;
default: return property3;
}
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试了什么:
public static void main(String[] args) {
List<TestObject> list = new ArrayList<>();
Map<Integer, Integer> filterMap = new HashMap<>();
list.add(new TestObject(1, 2, 3));
list.add(new TestObject(1, 2, 4)); …Run Code Online (Sandbox Code Playgroud)