Имею реализацию ArrayList для arrayLists и пытаюсь написать реализацию Predicate для того же.
Пожалуйста, найдите мой код ниже.
Класс 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();
}
Пишу приведенную ниже реализацию в другом классе. Обновлен метод Predicate
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>)
как мне заставить его работать для ArrayList реализации arrayLists
Обновление 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>)