[英]Guava Collections filter
I am just starting with Guava collections and am trying to write a predicate for a list. 我只是从Guava集合开始,正在尝试为列表编写谓词。 I am using Guava 11 since I am on java 5. 我正在使用Guava 11,因为我在Java 5上。
Here is my first effort.... 这是我的第一步。
public abstract class StatusBean {
public enum Status {GREEN, AMBER, RED, BLUE};
}
public class RegisterReplicationSynchTime {
private Status status = null;
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
}
public class RegisterReplicationSynchTime {
public void doFilter() {
List<RegisterReplicationSynchTime> registerReplicationSynchTimes = dao.getMyList();
Predicate<StatusBean.Status> predicate = new Predicate<StatusBean.Status>() {
public boolean apply(StatusBean.Status status) {
return status != StatusBean.Status.GREEN;
}
};
// !!!! COMPILER DOES NOT LIKE THIS LINE!!!!!!
Collections2.filter(registerReplicationSynchTimes, predicate);
}
}
The compiler does not like the call I am making to filter and it is giving me an error as per below. 编译器不喜欢我要过滤的调用,它给了我如下错误。
The method filter (Collection<E>,<Predicate<? super E>) in the type
Collections 2 is not applicable for the arguements
(List<RegisterReplicationSynchTime>,Predicate<StatusBean.Status>)
I am not sure what I need to do to get it right. 我不确定该怎么做才能正确处理。 Can someone please give me a hand? 有人可以帮我吗?
As the error message tells you, there is a mismatch between the type of elements in your List
( RegisterReplicationSynchTime
) and the elements processed by the predicate ( StatusBean.Status
). 如错误消息所告知, List
的元素类型( RegisterReplicationSynchTime
)与谓词处理的元素( StatusBean.Status
)之间不匹配。
Perhaps you want to change your code to filter a List<StatusBean.Status>
? 也许您想更改代码以过滤List<StatusBean.Status>
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.