Example usage for org.apache.commons.collections.iterators FilterIterator FilterIterator

List of usage examples for org.apache.commons.collections.iterators FilterIterator FilterIterator

Introduction

In this page you can find the example usage for org.apache.commons.collections.iterators FilterIterator FilterIterator.

Prototype

public FilterIterator(Iterator iterator, Predicate predicate) 

Source Link

Document

Constructs a new FilterIterator that will use the given iterator and predicate.

Usage

From source file:com.newlandframework.avatarmq.consumer.ConsumerContext.java

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;
        }//from  w  w  w  .j av a2  s  .co  m
    };

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

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

    }
    return (state != null) ? state.getState() : 0;
}

From source file:edu.umd.cfar.lamp.viper.util.CropIteratorUtility.java

public Iterator getIterator(Iterator iter) {
    return new TransformIterator(new FilterIterator(iter, pred), trans);
}

From source file:com.newlandframework.avatarmq.consumer.ConsumerContext.java

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;
        }//from w w  w  . j  a va  2 s  .  com
    };

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

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

    return (relation != null) ? relation.getClusters() : null;
}

From source file:com.sworddance.util.NotNullIterator.java

@Override
protected void setIterator(Object iterator) {
    Iterator<?> iter = extractIterator(iterator);
    TransformIterator transformIterator = new TransformIterator(iter, ReferenceTransformer.INSTANCE);
    super.setIterator(new FilterIterator(transformIterator, NotNullKeyValuePredicate.INSTANCE));
}

From source file:flex2.compiler.mxml.rep.Array.java

/**
 * Note that we do *not* filter out bindings for element initializers.
 *///  w w  w  .j  a v  a  2  s . co m
@SuppressWarnings("unchecked")
public final Iterator<ArrayElementInitializer> getElementInitializerIterator() {
    return new FilterIterator(list.iterator(), new Predicate() {
        public boolean evaluate(Object object) {
            return (!(((ArrayElementInitializer) object).getValue() instanceof Reparent));
        }
    });
}

From source file:flex2.compiler.mxml.gen.DescriptorGenerator.java

/**
 *
 *//*from w w w.j a v  a2  s. c  o  m*/
private static void addDescriptorProperties(CodeFragmentList list, Model model,
        final Set<String> includePropNames, boolean includeDesignLayer, String indent) {
    //  ordinary properties
    Iterator propIter = includePropNames == null ? model.getPropertyInitializerIterator(false)
            : new FilterIterator(model.getPropertyInitializerIterator(false), new Predicate() {
                public boolean evaluate(Object obj) {
                    return includePropNames.contains(((NamedInitializer) obj).getName());
                }
            });

    //  visual children
    Iterator vcIter = (model instanceof MovieClip && ((MovieClip) model).hasChildren())
            ? ((MovieClip) model).children().iterator()
            : Collections.EMPTY_LIST.iterator();

    // designLayer ?
    Boolean hasDesignLayer = (includeDesignLayer && (model.layerParent != null)
            && model.getType().isAssignableTo(model.getStandardDefs().INTERFACE_IVISUALELEMENT));

    if (propIter.hasNext() || vcIter.hasNext() || hasDesignLayer) {
        if (!list.isEmpty()) {
            list.add(indent, ",", 0);
        }

        list.add(indent, "propertiesFactory: function():Object { return {", 0);
        indent += DescriptorGenerator.INDENT;

        while (propIter.hasNext()) {
            NamedInitializer init = (NamedInitializer) propIter.next();
            if (!init.isStateSpecific()) {
                list.add(indent, init.getName(), ": ", init.getValueExpr(),
                        (propIter.hasNext() || vcIter.hasNext() || hasDesignLayer ? "," : ""),
                        init.getLineRef());
            }
        }

        if (hasDesignLayer) {
            list.add(indent, "designLayer", ": ", model.layerParent.getId(), (vcIter.hasNext() ? "," : ""),
                    model.getXmlLineNumber());
        }

        if (vcIter.hasNext()) {
            list.add(indent, "childDescriptors: [", 0);

            // Generate each child descriptor unless the child as explicitly filtered out.
            boolean isFirst = true;
            while (vcIter.hasNext()) {
                VisualChildInitializer init = (VisualChildInitializer) vcIter.next();
                Model child = (MovieClip) init.getValue();
                if (child.isDescriptorInit()) {
                    if (!isFirst) {
                        list.add(indent, ",", 0);
                    }

                    addDescriptorInitializerFragments(list, child, indent + DescriptorGenerator.INDENT);
                    isFirst = false;
                }

            }

            list.add(indent, "]", 0);
        }

        indent = indent.substring(0, indent.length() - INDENT.length());
        list.add(indent, "}}", 0);
    }
}

From source file:mondrian.rolap.RolapMeasureGroup.java

/**
 * Finds out non-joining dimensions for this measure group.
 *
 * <p>The result preserves the order in {@code otherDims}.</p>
 *
 * @param otherDims Collection of dimensions to be tested for existence in
 *                  this measure group//from   w  w w . j a v  a  2 s.c  o  m
 * @return Set of dimensions that do not exist (non joining) in this cube
 */
public Iterable<RolapCubeDimension> nonJoiningDimensions(
        final Iterable<? extends RolapCubeDimension> otherDims) {
    return new Iterable<RolapCubeDimension>() {
        public Iterator<RolapCubeDimension> iterator() {
            //noinspection unchecked
            return (Iterator<RolapCubeDimension>) new FilterIterator(otherDims.iterator(),
                    new Util.Predicate1<RolapCubeDimension>() {
                        public boolean test(RolapCubeDimension dimension) {
                            return !dimensionMap3.containsKey(dimension) && !dimension.isMeasures();
                        }
                    });
        }
    };
}

From source file:io.wcm.config.core.persistence.impl.ToolsConfigPagePersistenceProvider.java

@SuppressWarnings("unchecked")
private Iterator<String> findConfigRefs(Resource startResource) {
    // collect all context path resources without config ref, and expand to config page path
    Iterator<ContextResource> contextResources = contextPathStrategy.findContextResources(startResource);
    return new FilterIterator(new TransformIterator(contextResources, new Transformer() {
        @Override// w  w w  . ja  v a  2  s . com
        public Object transform(Object input) {
            ContextResource contextResource = (ContextResource) input;
            if (contextResource.getConfigRef() == null) {
                String configPath = getConfigPagePath(contextResource.getResource().getPath());
                log.trace("+ Found reference for context path {}: {}", contextResource.getResource().getPath(),
                        configPath);
                return configPath;
            }
            return null;
        }
    }), PredicateUtils.notNullPredicate());
}

From source file:io.wcm.caconfig.extensions.persistence.impl.ToolsConfigPagePersistenceStrategy.java

/**
 * Searches the resource hierarchy upwards for all config references and returns them.
 *//*from www . j  a v a2  s.  co m*/
@SuppressWarnings("unchecked")
private Iterator<String> findConfigRefs(@NotNull final Resource startResource,
        @NotNull final Collection<String> bucketNames) {

    // collect all context path resources (but filter out those without config reference)
    final Iterator<ContextResource> contextResources = new FilterIterator(
            contextPathStrategy.findContextResources(startResource), new Predicate() {
                @Override
                public boolean evaluate(Object object) {
                    ContextResource contextResource = (ContextResource) object;
                    return StringUtils.isNotBlank(contextResource.getConfigRef());
                }
            });

    // get config resource path for each context resource, filter out items where not reference could be resolved
    final Iterator<String> configPaths = new TransformIterator(contextResources, new Transformer() {
        @Override
        public Object transform(Object input) {
            final ContextResource contextResource = (ContextResource) input;
            String val = checkPath(contextResource, contextResource.getConfigRef(), bucketNames);
            if (val != null) {
                log.trace("+ Found reference for context path {}: {}", contextResource.getResource().getPath(),
                        val);
            }
            return val;
        }
    });
    return new FilterIterator(configPaths, PredicateUtils.notNullPredicate());
}

From source file:io.wcm.config.core.persistence.impl.ToolsConfigPagePersistenceProvider.java

@Override
@SuppressWarnings("unchecked")
public Resource getResource(Iterator<Resource> configResources) {
    if (!config.enabled() || !configResources.hasNext()) {
        return null;
    }/*  w  w  w. j ava 2 s. co m*/

    Iterator<Resource> configPageResources = new FilterIterator(configResources, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            Resource resource = (Resource) object;
            return isConfigPagePath(resource.getPath());
        }
    });

    return getInheritedResourceInternal(configPageResources);
}