Java Code Examples for org.apache.commons.collections.ListUtils#intersection()

The following examples show how to use org.apache.commons.collections.ListUtils#intersection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserFinderAction.java    From entando-components with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<String> getSearchResult() {
	List<String> mainSearchResult = super.getSearchResult();
	try {
		Integer userType = this.getUserType();
		if (null == userType || userType == 0) {
			return mainSearchResult;
		} else {
			Boolean entandoUser = (userType == 1);
			List<String> ldapUsernames = this.getLdapUsernames();
			List<String> newList = null;
			if (entandoUser) {
				newList = (List<String>) ListUtils.removeAll(mainSearchResult, ldapUsernames);
			} else {
				newList = (List<String>) ListUtils.intersection(mainSearchResult, ldapUsernames);
			}
			return newList;
		}
	} catch (Throwable t) {
		ApsSystemUtils.logThrowable(t, this, "getSearchResult");
		throw new RuntimeException("Error while searching users", t);
	}
}
 
Example 2
Source File: CollectionGroupBuilder.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Performs any filtering necessary on the collection before building the collection fields.
 *
 * <p>If showInactive is set to false and the collection line type implements {@code Inactivatable},
 * invokes the active collection filter. Then any {@link CollectionFilter} instances configured for the collection
 * group are invoked to filter the collection. Collections lines must pass all filters in order to be
 * displayed</p>
 *
 * @param view view instance that contains the collection
 * @param model object containing the views data
 * @param collectionGroup collection group component instance that will display the collection
 * @param collection collection instance that will be filtered
 */
protected List<Integer> performCollectionFiltering(View view, Object model, CollectionGroup collectionGroup,
        Collection<?> collection) {
    List<Integer> filteredIndexes = new ArrayList<Integer>();
    for (int i = 0; i < collection.size(); i++) {
        filteredIndexes.add(Integer.valueOf(i));
    }

    if (Inactivatable.class.isAssignableFrom(collectionGroup.getCollectionObjectClass()) && !collectionGroup
            .isShowInactiveLines()) {
        List<Integer> activeIndexes = collectionGroup.getActiveCollectionFilter().filter(view, model,
                collectionGroup);
        filteredIndexes = ListUtils.intersection(filteredIndexes, activeIndexes);
    }

    for (CollectionFilter collectionFilter : collectionGroup.getFilters()) {
        List<Integer> indexes = collectionFilter.filter(view, model, collectionGroup);
        filteredIndexes = ListUtils.intersection(filteredIndexes, indexes);
        if (filteredIndexes.isEmpty()) {
            break;
        }
    }

    return filteredIndexes;
}
 
Example 3
Source File: GroupItem.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * The accepted data types of a group item is the same as of the underlying base item.
 * If none is defined, the intersection of all sets of accepted data types of all group
 * members is used instead.
 *
 * @return the accepted data types of this group item
 */
@Override
@SuppressWarnings("unchecked")
public List<Class<? extends State>> getAcceptedDataTypes() {
    if (baseItem != null) {
        return baseItem.getAcceptedDataTypes();
    } else {
        List<Class<? extends State>> acceptedDataTypes = null;

        for (Item item : members) {
            if (acceptedDataTypes == null) {
                acceptedDataTypes = item.getAcceptedDataTypes();
            } else {
                acceptedDataTypes = ListUtils.intersection(acceptedDataTypes, item.getAcceptedDataTypes());
            }
        }
        return acceptedDataTypes == null ? ListUtils.EMPTY_LIST : acceptedDataTypes;
    }
}
 
Example 4
Source File: GroupItem.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * The accepted command types of a group item is the same as of the underlying base item.
 * If none is defined, the intersection of all sets of accepted command types of all group
 * members is used instead.
 *
 * @return the accepted command types of this group item
 */
@Override
@SuppressWarnings("unchecked")
public List<Class<? extends Command>> getAcceptedCommandTypes() {
    if (baseItem != null) {
        return baseItem.getAcceptedCommandTypes();
    } else {
        List<Class<? extends Command>> acceptedCommandTypes = null;

        for (Item item : members) {
            if (acceptedCommandTypes == null) {
                acceptedCommandTypes = item.getAcceptedCommandTypes();
            } else {
                acceptedCommandTypes = ListUtils.intersection(acceptedCommandTypes, item.getAcceptedCommandTypes());
            }
        }
        return acceptedCommandTypes == null ? ListUtils.EMPTY_LIST : acceptedCommandTypes;
    }
}
 
Example 5
Source File: ContentListHelper.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected List<String> executeFullTextSearch(IContentListTagBean bean,
        List<String> masterContentsId, RequestContext reqCtx) throws ApsSystemException {
    UserFilterOptionBean fullTextUserFilter = null;
    List<UserFilterOptionBean> userFilterOptions = bean.getUserFilterOptions();
    if (null != userFilterOptions) {
        for (UserFilterOptionBean userFilter : userFilterOptions) {
            if (null != userFilter.getFormFieldValues() && userFilter.getFormFieldValues().size() > 0) {
                if (!userFilter.isAttributeFilter()
                        && userFilter.getKey().equals(UserFilterOptionBean.KEY_FULLTEXT)) {
                    fullTextUserFilter = userFilter;
                }
            }
        }
    }
    if (fullTextUserFilter != null && null != fullTextUserFilter.getFormFieldValues()) {
        String word = fullTextUserFilter.getFormFieldValues().get(fullTextUserFilter.getFormFieldNames()[0]);
        Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        List<String> fullTextResult = this.getSearchEngineManager().searchEntityId(currentLang.getCode(), word, this.getAllowedGroups(reqCtx));
        if (null != fullTextResult) {
            return ListUtils.intersection(fullTextResult, masterContentsId);
        } else {
            return new ArrayList<>();
        }
    } else {
        return masterContentsId;
    }
}
 
Example 6
Source File: DataObjectListHelper.java    From entando-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected List<String> executeFullTextSearch(IDataObjectListTagBean bean,
         List<String> masterContentsId, RequestContext reqCtx) throws ApsSystemException {
     UserFilterOptionBean fullTextUserFilter = null;
     List<UserFilterOptionBean> userFilterOptions = bean.getUserFilterOptions();
     if (null != userFilterOptions) {
         for (int i = 0; i < userFilterOptions.size(); i++) {
             UserFilterOptionBean userFilter = userFilterOptions.get(i);
             if (null != userFilter.getFormFieldValues() && userFilter.getFormFieldValues().size() > 0) {
                 if (!userFilter.isAttributeFilter()
                         && userFilter.getKey().equals(UserFilterOptionBean.KEY_FULLTEXT)) {
                     fullTextUserFilter = userFilter;
                 }
             }
         }
     }
     if (fullTextUserFilter != null && null != fullTextUserFilter.getFormFieldValues()) {
         String word = fullTextUserFilter.getFormFieldValues().get(fullTextUserFilter.getFormFieldNames()[0]);
         /*
String optionString = fullTextUserFilter.getFormFieldValues().get(fullTextUserFilter.getFormFieldNames()[1]);
SearchEngineFilter.TextSearchOption option = SearchEngineFilter.TextSearchOption.AT_LEAST_ONE_WORD;
if (null != optionString) {
	if (optionString.equals(UserFilterOptionBean.FULLTEXT_OPTION_ALL_WORDS)) {
		option = SearchEngineFilter.TextSearchOption.ALL_WORDS;
	} else if (optionString.equals(UserFilterOptionBean.FULLTEXT_OPTION_EXACT)) {
		option = SearchEngineFilter.TextSearchOption.EXACT;
	}
}
          */
         Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
         /*
SearchEngineFilter filter = new SearchEngineFilter(currentLang.getCode(), word, option);
SearchEngineFilter[] filters = {filter};
List<String> fullTextResult = this.getSearchEngineManager().searchEntityId(filters, null, this.getAllowedGroups(reqCtx));
          */
         List<String> fullTextResult = this.getSearchEngineManager().searchEntityId(currentLang.getCode(), word, this.getAllowedGroups(reqCtx));
         if (null != fullTextResult) {
             return ListUtils.intersection(fullTextResult, masterContentsId);
         } else {
             return new ArrayList<String>();
         }
     } else {
         return masterContentsId;
     }
 }