use of org.apache.commons.collections.Predicate in project gocd by gocd.
the class MaterialRepository method pmrModificationsKey.
private List<String> pmrModificationsKey(Modification modification, List<PipelineMaterialRevision> pmrs) {
final long id = modification.getId();
final MaterialInstance materialInstance = modification.getMaterialInstance();
Collection<PipelineMaterialRevision> matchedPmrs = (Collection<PipelineMaterialRevision>) CollectionUtils.select(pmrs, new Predicate() {
@Override
public boolean evaluate(Object o) {
PipelineMaterialRevision pmr = (PipelineMaterialRevision) o;
long from = pmr.getFromModification().getId();
long to = pmr.getToModification().getId();
MaterialInstance pmi = findMaterialInstance(pmr.getMaterial());
return from <= id && id <= to && materialInstance.equals(pmi);
}
});
List<String> keys = new ArrayList<>(matchedPmrs.size());
for (PipelineMaterialRevision matchedPmr : matchedPmrs) {
keys.add(pmrModificationsKey(matchedPmr));
}
return keys;
}
use of org.apache.commons.collections.Predicate in project symmetric-ds by JumpMind.
the class AbstractDdlBuilder method applyForSelectedChanges.
/**
* Calls the given closure for all changes that are of one of the given
* types, and then removes them from the changes collection.
*
* @param changes
* The changes
* @param changeTypes
* The types to search for
* @param closure
* The closure to invoke
*/
protected void applyForSelectedChanges(Collection<IModelChange> changes, Class<?>[] changeTypes, final Closure closure) {
final Predicate predicate = new MultiInstanceofPredicate(changeTypes);
// basically we filter the changes for all objects where the above
// predicate returns true, and for these filtered objects we invoke the
// given closure
CollectionUtils.filter(changes, new Predicate() {
public boolean evaluate(Object obj) {
if (predicate.evaluate(obj)) {
closure.execute(obj);
return false;
} else {
return true;
}
}
});
}
use of org.apache.commons.collections.Predicate in project symmetric-ds by JumpMind.
the class AbstractDdlBuilder method processChanges.
/**
* Processes the changes. The default argument performs several passes:
* <ol>
* <li>
* {@link org.jumpmind.db.alter.RemoveForeignKeyChange} and
* {@link org.jumpmind.db.alter.RemoveIndexChange} come first to allow for
* e.g. subsequent primary key changes or column removal.</li>
* <li>{@link org.jumpmind.db.alter.RemoveTableChange} comes after the
* removal of foreign keys and indices.</li>
* <li>These are all handled together:<br/>
* {@link org.jumpmind.db.alter.RemovePrimaryKeyChange}<br/>
* {@link org.jumpmind.db.alter.AddPrimaryKeyChange}<br/>
* {@link org.jumpmind.db.alter.PrimaryKeyChange}<br/>
* {@link org.jumpmind.db.alter.RemoveColumnChange}<br/>
* {@link org.jumpmind.db.alter.AddColumnChange}<br/>
* {@link org.jumpmind.db.alter.ColumnAutoIncrementChange} <br/>
* {@link org.jumpmind.db.alter.ColumnDefaultValueChange} <br/>
* {@link org.jumpmind.db.alter.ColumnRequiredChange}<br/>
* {@link org.jumpmind.db.alter.ColumnDataTypeChange}<br/>
* {@link org.jumpmind.db.alter.ColumnSizeChange}<br/>
* The reason for this is that the default algorithm rebuilds the table for
* these changes and thus their order is irrelevant.</li>
* <li>{@link org.jumpmind.db.alter.AddTableChange}<br/>
* needs to come after the table removal (so that tables of the same name
* are removed) and before the addition of foreign keys etc.</li>
* <li>{@link org.jumpmind.db.alter.AddForeignKeyChange} and
* {@link org.jumpmind.db.alter.AddIndexChange} come last after
* table/column/primary key additions or changes.</li>
* </ol>
*/
@SuppressWarnings("unchecked")
protected void processChanges(Database currentModel, Database desiredModel, List<IModelChange> changes, StringBuilder ddl) {
CallbackClosure callbackClosure = new CallbackClosure(this, "processChange", new Class[] { Database.class, Database.class, null, StringBuilder.class }, new Object[] { currentModel, desiredModel, null, ddl });
// 1st pass: removing external constraints and indices
applyForSelectedChanges(changes, new Class[] { RemoveForeignKeyChange.class, RemoveIndexChange.class }, callbackClosure);
// 2nd pass: removing tables
applyForSelectedChanges(changes, new Class[] { RemoveTableChange.class }, callbackClosure);
// 3rd pass: changing the structure of tables
Predicate predicate = new MultiInstanceofPredicate(new Class[] { RemovePrimaryKeyChange.class, AddPrimaryKeyChange.class, PrimaryKeyChange.class, RemoveColumnChange.class, AddColumnChange.class, ColumnAutoIncrementChange.class, ColumnDefaultValueChange.class, ColumnRequiredChange.class, ColumnDataTypeChange.class, ColumnSizeChange.class, CopyColumnValueChange.class });
processTableStructureChanges(currentModel, desiredModel, CollectionUtils.select(changes, predicate), ddl);
// 4th pass: adding tables
applyForSelectedChanges(changes, new Class[] { AddTableChange.class }, callbackClosure);
// 5th pass: adding external constraints and indices
applyForSelectedChanges(changes, new Class[] { AddForeignKeyChange.class, AddIndexChange.class }, callbackClosure);
}
use of org.apache.commons.collections.Predicate in project shifu by ShifuML.
the class DataFilterWorker method purifyData.
/**
* Filter the data - it uses @dataPurifier to filter data
*
* @param inputDataList - input data to filter
*/
private void purifyData(List<String> inputDataList) {
log.info("starting to filter data ... ");
CollectionUtils.filter(inputDataList, new Predicate() {
@Override
public boolean evaluate(Object object) {
String inputData = (String) object;
return dataPurifier.isFilterOut(inputData);
}
});
log.info("there are {} records after filter.", inputDataList.size());
}
use of org.apache.commons.collections.Predicate in project incubator-atlas by apache.
the class FilterUtil method getPredicateFromSearchFilter.
public static Predicate getPredicateFromSearchFilter(SearchFilter searchFilter) {
List<Predicate> predicates = new ArrayList<>();
final String type = searchFilter.getParam(SearchFilter.PARAM_TYPE);
final String name = searchFilter.getParam(SearchFilter.PARAM_NAME);
final String supertype = searchFilter.getParam(SearchFilter.PARAM_SUPERTYPE);
final String notSupertype = searchFilter.getParam(SearchFilter.PARAM_NOT_SUPERTYPE);
// Add filter for the type/category
if (StringUtils.isNotBlank(type)) {
predicates.add(getTypePredicate(type));
}
// Add filter for the name
if (StringUtils.isNotBlank(name)) {
predicates.add(getNamePredicate(name));
}
// Add filter for the supertype
if (StringUtils.isNotBlank(supertype)) {
predicates.add(getSuperTypePredicate(supertype));
}
// Add filter for the supertype negation
if (StringUtils.isNotBlank(notSupertype)) {
predicates.add(new NotPredicate(getSuperTypePredicate(notSupertype)));
}
return PredicateUtils.allPredicate(predicates);
}
Aggregations