org.apache.commons.collections.iterators.FilterIterator Java Examples

The following examples show how to use org.apache.commons.collections.iterators.FilterIterator. 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: ConsumerContext.java    From AvatarMQ with Apache License 2.0 6 votes vote down vote up
public static int getClustersStat(String clusters) {

        Predicate predicate = new Predicate() {
            public boolean evaluate(Object object) {
                String clustersId = ((ClustersState) object).getClusters();
                return clustersId.compareTo(clusters) == 0;
            }
        };

        Iterator iterator = new FilterIterator(stateArray.iterator(), predicate);

        ClustersState state = null;
        while (iterator.hasNext()) {
            state = (ClustersState) iterator.next();
            break;

        }
        return (state != null) ? state.getState() : 0;
    }
 
Example #2
Source File: ConsumerContext.java    From AvatarMQ with Apache License 2.0 6 votes vote down vote up
public static ConsumerClusters selectByClusters(String clusters) {
    Predicate predicate = new Predicate() {
        public boolean evaluate(Object object) {
            String id = ((ClustersRelation) object).getId();
            return id.compareTo(clusters) == 0;
        }
    };

    Iterator iterator = new FilterIterator(relationArray.iterator(), predicate);

    ClustersRelation relation = null;
    while (iterator.hasNext()) {
        relation = (ClustersRelation) iterator.next();
        break;
    }

    return (relation != null) ? relation.getClusters() : null;
}
 
Example #3
Source File: ProgramModuleSymbol.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public Collection<IModulaSymbol> getExportedSymbols() {
	Iterable<IModulaSymbol> iterable = () -> {
		return new FilterIterator(ProgramModuleSymbol.this.iterator(), o -> !imports.containsValue(o)
                && ((IModulaSymbol)o).isAttributeSet(SymbolAttribute.PUBLIC));
	};
	
	return Lists.newArrayList(iterable);
}
 
Example #4
Source File: FilteringBalanceIteratorImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates the FilterIterator that underlies this Iterator
 */
protected void initialize() {
    if (!initialized) {
        filteredBalances = new FilterIterator(balancesSource, new Predicate() {
            public boolean evaluate(Object obj) {
                return balancePredicate.select((Balance) obj);
            }
        });
        initialized = true;
    }
}
 
Example #5
Source File: ChildrenDataSourceServlet.java    From commerce-cif-connector with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Iterator<Resource> listChildren() {
    return new TransformIterator(new FilterIterator(super.listChildren(), predicate), o -> new PredicatedResourceWrapper(
        (Resource) o, predicate));
}
 
Example #6
Source File: IteratorUtils.java    From Penetration_Testing_POC with Apache License 2.0 3 votes vote down vote up
/**
 * Gets an iterator that filters another iterator.
 * <p>
 * The returned iterator will only return objects that match the specified
 * filtering predicate.
 *
 * @param iterator  the iterator to use, not null
 * @param predicate  the predicate to use as a filter, not null
 * @return a new filtered iterator
 * @throws NullPointerException if either parameter is null
 */
public static Iterator filteredIterator(Iterator iterator, Predicate predicate) {
    if (iterator == null) {
        throw new NullPointerException("Iterator must not be null");
    }
    if (predicate == null) {
        throw new NullPointerException("Predicate must not be null");
    }
    return new FilterIterator(iterator, predicate);
}