Am具有arrayLists的ArrayList的实现,并试图为此编写谓词实现。
请找到我下面的代码。
Pojo类Menu.java
public class Menu {
private String name;
private String code;
private ArrayList<ArrayList<Menu>> childMenus = new ArrayList<ArrayList<Menu>>();
private ArrayList<Menu> Defaults = new ArrayList<Menu>();
public boolean hasChildMenus() {
childMenus.add(Defaults);
return childMenus != null && !childMenus.isEmpty();
}
将下面的实现写在另一个类中。更新的谓词方法
private Predicate<? super Menu> byRoleAndPermissions(final Role role, final Set<String> permissionsSet) {
return new Predicate<Menu>() {
@Override
public boolean apply(Menu menu) {
final boolean filterForExternalUser = !role.isRoleInternal() && !menu.isVisibleToExternal() && !(role.getCode().equals("DLR_ADMN") && menu.getCode().equals("MDFY_USER_PRVG"));
// for dealer and dealer read only related changes : MDFY_USER_PRVG
if(!role.isRoleInternal() && (role.getCode().equals("DLR") || role.getCode().equals("DLR_RD_ONLY")) && menu.getCode().equals("MDFY_USER_PRVG")){
return true;
}
if (filterForExternalUser) {
return false;
}
SetView<String> intersection = Sets.intersection(menu.getPermissions(), permissionsSet);
if (intersection.size() == 0) {
return false;
}
if (menu.hasChildMenus()) {
menu.setChildMenus(new ArrayList<Menu>(filter(menu.getChildMenus(), byRoleAndPermissions(role, permissionsSet))));
}
return true;
}
};
}
并收到以下错误
Multiple markers at this line
- The method filter(Collection<E>, Predicate<? super E>) in the type Collections2 is not applicable for the arguments (ArrayList<ArrayList<Menu>>, Predicate<capture#4-of ? super
Menu>)
- The method setChildMenus(ArrayList<ArrayList<Menu>>) in the type Menu is not applicable for the arguments (ArrayList<Menu>)
我如何使其适用于arrayLists实现的ArrayList
更新1
正在尝试此实现,以添加带有菜单的菜单栏。像下面的设计。
Admin (mainMenu)
- User
- Role
- Default
- System Default
- Exit
这是一种正在尝试的实现方式。
更新2
我在Predicate
方法中修改了该行,如下所示:
menu.setChildMenus(new ArrayList<ArrayList<Menu>>(filter(menu.getChildMenus(), byRoleAndPermissions(role, permissionsSet))));
但是现在出现错误:
Error : The method filter(Collection<E>, Predicate<? super E>) in the type Collections2 is not applicable for the arguments (ArrayList<ArrayList<Menu>>, Predicate<capture#4-of ? super Menu>)