Example usage for org.apache.commons.collections CollectionUtils select

List of usage examples for org.apache.commons.collections CollectionUtils select

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils select.

Prototype

public static Collection select(Collection inputCollection, Predicate predicate) 

Source Link

Document

Selects all elements from input collection which match the given predicate into an output collection.

Usage

From source file:org.apache.cayenne.xml.XMLUtil.java

/**
 * Returns all elements among the direct children that have a matching name.
 *///from w  w w.  j  a v a2 s. com
static List<Element> getChildren(Node node, final String name) {

    Predicate p = new Predicate() {

        public boolean evaluate(Object object) {
            if (object instanceof Element) {
                Element e = (Element) object;
                return name.equals(e.getNodeName());
            }
            return false;
        }
    };

    return (List<Element>) CollectionUtils.select(getChildren(node), p);
}

From source file:org.apache.ddlutils.model.Table.java

/**
 * Gets a list of non-unique indices on this table.
 * //  ww  w  .  ja va 2 s  .  c  o  m
 * @return The unique indices
 */
public Index[] getNonUniqueIndices() {
    Collection nonUniqueIndices = CollectionUtils.select(_indices, new Predicate() {
        public boolean evaluate(Object input) {
            return !((Index) input).isUnique();
        }
    });

    return (Index[]) nonUniqueIndices.toArray(new Index[nonUniqueIndices.size()]);
}

From source file:org.apache.ddlutils.model.Table.java

/**
 * Gets a list of unique indices on this table.
 * //from www .  j av  a2s.c o m
 * @return The unique indices
 */
public Index[] getUniqueIndices() {
    Collection uniqueIndices = CollectionUtils.select(_indices, new Predicate() {
        public boolean evaluate(Object input) {
            return ((Index) input).isUnique();
        }
    });

    return (Index[]) uniqueIndices.toArray(new Index[uniqueIndices.size()]);
}

From source file:org.apache.ddlutils.model.Table.java

/**
 * Returns the primary key columns of this table.
 * //from   w w  w. j  a  va  2s.c om
 * @return The primary key columns
 */
public Column[] getPrimaryKeyColumns() {
    Collection pkColumns = CollectionUtils.select(_columns, new Predicate() {
        public boolean evaluate(Object input) {
            return ((Column) input).isPrimaryKey();
        }
    });

    return (Column[]) pkColumns.toArray(new Column[pkColumns.size()]);
}

From source file:org.apache.ddlutils.model.Table.java

/**
 * Returns the auto increment columns in this table. If none are found,
 * then an empty array will be returned.
 * /*from w  w w  .  j  a  va2s. c o m*/
 * @return The auto increment columns
 */
public Column[] getAutoIncrementColumns() {
    Collection autoIncrColumns = CollectionUtils.select(_columns, new Predicate() {
        public boolean evaluate(Object input) {
            return ((Column) input).isAutoIncrement();
        }
    });

    return (Column[]) autoIncrColumns.toArray(new Column[autoIncrColumns.size()]);
}

From source file:org.apache.ddlutils.model.Table.java

/**
 * Returns the required (not-nullable) columns in this table. If none are found,
 * then an empty array will be returned.
 * /*w ww . j a v  a2  s. c  om*/
 * @return The required columns
 */
public Column[] getRequiredColumns() {
    Collection requiredColumns = CollectionUtils.select(_columns, new Predicate() {
        public boolean evaluate(Object input) {
            return ((Column) input).isRequired();
        }
    });

    return (Column[]) requiredColumns.toArray(new Column[requiredColumns.size()]);
}

From source file:org.apache.ddlutils.platform.PlatformImplBase.java

/**
 * Returns all properties where the column is not non-autoincrement and for which the bean
 * either has a value or the column hasn't got a default value, for the given dyna class.
 * //from w w  w.  j  ava2 s. co  m
 * @param model     The database model
 * @param dynaClass The dyna class
 * @param bean      The bean
 * @return The properties
 */
private SqlDynaProperty[] getPropertiesForInsertion(Database model, SqlDynaClass dynaClass,
        final DynaBean bean) {
    SqlDynaProperty[] properties = dynaClass.getSqlDynaProperties();

    Collection result = CollectionUtils.select(Arrays.asList(properties), new Predicate() {
        public boolean evaluate(Object input) {
            SqlDynaProperty prop = (SqlDynaProperty) input;

            if (bean.get(prop.getName()) != null) {
                // we ignore properties for which a value is present in the bean
                // only if they are identity and identity override is off or
                // the platform does not allow the override of the auto-increment
                // specification
                return !prop.getColumn().isAutoIncrement()
                        || (isIdentityOverrideOn() && getPlatformInfo().isIdentityOverrideAllowed());
            } else {
                // we also return properties without a value in the bean
                // if they ain't auto-increment and don't have a default value
                // in this case, a NULL is inserted
                return !prop.getColumn().isAutoIncrement() && (prop.getColumn().getDefaultValue() == null);
            }
        }
    });

    return (SqlDynaProperty[]) result.toArray(new SqlDynaProperty[result.size()]);
}

From source file:org.apache.ddlutils.platform.PlatformImplBase.java

/**
 * Returns all identity properties whose value were defined by the database and which
 * now need to be read back from the DB.
 * /*from w  w  w.  j  a  va  2 s.c  om*/
 * @param model     The database model
 * @param dynaClass The dyna class
 * @param bean      The bean
 * @return The columns
 */
private Column[] getRelevantIdentityColumns(Database model, SqlDynaClass dynaClass, final DynaBean bean) {
    SqlDynaProperty[] properties = dynaClass.getSqlDynaProperties();

    Collection relevantProperties = CollectionUtils.select(Arrays.asList(properties), new Predicate() {
        public boolean evaluate(Object input) {
            SqlDynaProperty prop = (SqlDynaProperty) input;

            // we only want those identity columns that were really specified by the DB
            // if the platform allows specification of values for identity columns
            // in INSERT/UPDATE statements, then we need to filter the corresponding
            // columns out
            return prop.getColumn().isAutoIncrement() && (!isIdentityOverrideOn()
                    || !getPlatformInfo().isIdentityOverrideAllowed() || (bean.get(prop.getName()) == null));
        }
    });

    Column[] columns = new Column[relevantProperties.size()];
    int idx = 0;

    for (Iterator propIt = relevantProperties.iterator(); propIt.hasNext(); idx++) {
        columns[idx] = ((SqlDynaProperty) propIt.next()).getColumn();
    }
    return columns;
}

From source file:org.apache.jackrabbit.standalone.cli.CommandLine.java

/**
 * @return required arguments/*www.java  2  s  .  c o  m*/
 */
public Collection getRequiredArguments() {
    Predicate p = new Predicate() {
        public boolean evaluate(Object o) {
            Argument arg = (Argument) o;
            return arg.isRequired();
        }
    };
    return CollectionUtils.select(this.arguments.values(), p);
}

From source file:org.apache.jackrabbit.standalone.cli.CommandLine.java

/**
 * @return required options//from   w w  w . j a va2s . co  m
 */
public Collection getRequiredOptions() {
    Predicate p = new Predicate() {
        public boolean evaluate(Object o) {
            Option opt = (Option) o;
            return opt.isRequired();
        }
    };
    return CollectionUtils.select(this.options.values(), p);
}