本文整理汇总了Java中org.apache.commons.collections15.Predicate类的典型用法代码示例。如果您正苦于以下问题:Java Predicate类的具体用法?Java Predicate怎么用?Java Predicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Predicate类属于org.apache.commons.collections15包,在下文中一共展示了Predicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConvertOneBDD
import org.apache.commons.collections15.Predicate; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testConvertOneBDD() {
String var1 = "sensor1";
Term s1 = new LiteralTerm<>(var1);
ANDTerm and = new ANDTerm();
and.add(s1);
Predicate p1[] = { new EqualPredicate<>(var1) };
Predicate<String> p = new AllPredicate<String>(p1);
BDDTTRFSimulative<String> ttrf = new BDDTTRFSimulative<>(provider);
int samples = 10;
SampledReliabilityFunction function = (SampledReliabilityFunction) ttrf.convert(and, new TestTransformer(), p,
samples);
for (int i = 0; i < samples; i++) {
Assert.assertEquals(0.0, function.getSamples().get(i), 1.0E-5);
}
}
示例2: testConvertToBDDExistsPredicate
import org.apache.commons.collections15.Predicate; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testConvertToBDDExistsPredicate() {
String var1 = "sensor1";
String var2 = "sensor2";
Term s1 = new LiteralTerm<>(var1);
Term s2 = new LiteralTerm<>(var2);
ANDTerm and = new ANDTerm();
and.add(s1, s2);
BDDTTRF<String> ttrf = new BDDTTRF<>(provider);
Predicate p2[] = { new EqualPredicate<>(var2) };
Predicate<String> p = new AllPredicate<String>(p2);
BDD<String> result = ttrf.convertToBDD(and, p);
BDD<String> ref = provider.get(var1);
Assert.assertEquals(result, ref);
}
示例3: collectScoringSortOrderAndTraitInstanceByKey
import org.apache.commons.collections15.Predicate; //导入依赖的package包/类
private boolean collectScoringSortOrderAndTraitInstanceByKey(
Map<Integer, Integer> ssoByTraitId,
Map<String, TraitInstance> tiByKey)
{
try {
Predicate<TraitInstance> visitor = new Predicate<TraitInstance>() {
@Override
public boolean evaluate(TraitInstance ti) {
tiByKey.put(makeTiKey(ti), ti);
if (! ssoByTraitId.containsKey(ti.getTraitId())) {
int scoringSortOrder = ti.getScoringSortOrder();
ssoByTraitId.put(ti.getTraitId(), scoringSortOrder);
}
return true;
}
};
kdxploreDatabase.getKDXploreKSmartDatabase().visitTraitInstancesForTrial(trial.getTrialId(),
WithTraitOption.ONLY_NON_CALC_TRAITS,
visitor);
}
catch (IOException e1) {
MsgBox.error(AddScoringSetDialog.this, e1.getMessage(), getTitle());
return false;
}
return true;
}
示例4: visitTraitInstancesForTrial
import org.apache.commons.collections15.Predicate; //导入依赖的package包/类
@Override
public void visitTraitInstancesForTrial(int trialId, boolean withTraits,
Predicate<TraitInstance> traitInstanceVisitor)
throws IOException {
WithTraitOption withTraitOption = withTraits
? WithTraitOption.ALL_WITH_TRAITS
: WithTraitOption.ALL_WITHOUT_TRAITS;
Predicate<TraitInstance> visitor = new Predicate<TraitInstance>() {
@Override
public boolean evaluate(TraitInstance ti) {
Boolean result = Boolean.TRUE;
if (traitIds.contains(ti.getTraitId())) {
result = traitInstanceVisitor.evaluate(ti);
}
return result;
}
};
kdsmartDatabase.visitTraitInstancesForTrial(trialId,
withTraitOption,
visitor);
}
示例5: getEditStateSamplesByPlot
import org.apache.commons.collections15.Predicate; //导入依赖的package包/类
public Map<Plot,Map<Integer,KdxSample>> getEditStateSamplesByPlot(TraitInstance ti, Predicate<Plot> plotFilter) {
Map<Plot,Map<Integer,KdxSample>> result = new HashMap<>(plots.size());
for (Plot plot : plots) {
if (plotFilter == null || plotFilter.evaluate(plot)) {
for (Integer psnum : plot.getSpecimenNumbers(PlotOrSpecimen.INCLUDE_PLOT)) {
PlotOrSpecimen pos = plot.getPlotOrSpecimen(psnum);
KdxSample sm = getEditStateSampleFor(ti, pos);
if (sm != null) {
Map<Integer, KdxSample> map = result.get(plot);
if (map == null) {
map = new HashMap<>();
result.put(plot, map);
}
map.put(psnum, sm);
}
}
}
}
return result;
}
示例6: filterGraph
import org.apache.commons.collections15.Predicate; //导入依赖的package包/类
/** <p>Filters a graph removing those edges whose weight is equal to {@code Double.MAX_VALUE}, or whose capacity is below a certain threshold.</p>
*
* <p><b>Important</b>: Returned graph is not backed in the input one, so changes will not be reflected on it.
*
* @param <V> Class type for vertices
* @param <E> Class type for edges
* @param graph Graph representing the network
* @param nev Object responsible for returning weights for edges
* @param edgeSpareCapacityTransformer Object responsible for returning capacity for edges (if null, it will not applied)
* @param requiredCapacity Capacity threshold. Edges whose capacity is below that value it will be removed
* @return Filtered graph */
public static <V, E> Graph<V, E> filterGraph(Graph<V, E> graph, final Transformer<E, Double> nev, final Transformer<E, Double> edgeSpareCapacityTransformer, final double requiredCapacity)
{
EdgePredicateFilter<V, E> linkFilter = new EdgePredicateFilter<V, E>(new Predicate<E>()
{
@Override
public boolean evaluate(E edge)
{
if (nev != null && nev.transform(edge) == Double.MAX_VALUE)
return false;
else if (edgeSpareCapacityTransformer != null && edgeSpareCapacityTransformer.transform(edge) < requiredCapacity) return false;
return true;
}
});
return linkFilter.transform(graph);
}
示例7: filter
import org.apache.commons.collections15.Predicate; //导入依赖的package包/类
public static <V, E> Graph<V, E> filter(Graph<V, E> graph, final Collection<V> vertices) {
Predicate<V> predicate = new Predicate<V>() {
@Override
public boolean evaluate(V vertex) {
if(vertices.contains(vertex))
return true;
return false;
}
};
//Filter graph
Filter<V, E> verticesFilter = new VertexPredicateFilter<V, E>(predicate);
graph = verticesFilter.transform(graph);
return graph;
}
示例8: validate
import org.apache.commons.collections15.Predicate; //导入依赖的package包/类
/**
* Validate the predicates to ensure that all is well.
*
* @param predicates the predicates to validate
* @return predicate array
*/
static <T> Predicate<? super T>[] validate(Collection<Predicate<? super T>> predicates) {
if (predicates == null) {
throw new IllegalArgumentException("The predicate collection must not be null");
}
if (predicates.size() < 2) {
throw new IllegalArgumentException("At least 2 predicates must be specified in the predicate collection, size was " + predicates.size());
}
// convert to array like this to guarantee iterator() ordering
Predicate<? super T>[] preds = new Predicate[predicates.size()];
int i = 0;
for (Iterator<Predicate<? super T>> it = predicates.iterator(); it.hasNext();) {
preds[i] = it.next();
if (preds[i] == null) {
throw new IllegalArgumentException("The predicate collection must not contain a null predicate, index " + i + " was null");
}
i++;
}
return preds;
}
示例9: convertToBDD
import org.apache.commons.collections15.Predicate; //导入依赖的package包/类
/**
* Returns a {@link BDD} representing the given {@link Term} while respecting the exists-variables.
*
* @param term
* the term
* @param existsPredicate
* the exists predicate
* @return a bdd representing the given term
*/
public BDD<T> convertToBDD(Term term, Predicate<T> existsPredicate) {
BDD<T> bdd = transform(term);
if (!(existsPredicate == null)) {
Set<T> variables = Terms.getVariables(term);
for (T variable : variables) {
if (existsPredicate.evaluate(variable)) {
BDD<T> tmp = bdd.exist(variable);
bdd.free();
bdd = tmp;
}
}
}
return bdd;
}
示例10: createSampleGroupAndCollectTraitInstances
import org.apache.commons.collections15.Predicate; //导入依赖的package包/类
private SampleGroup createSampleGroupAndCollectTraitInstances(DeviceIdentifier scoringDevId,
Map<Integer, Integer> ssoByTraitId, Map<String, TraitInstance> tiByKey,
List<TraitInstance> traitInstances)
{
// int maxSso = 0;
// if (! ssoByTraitId.isEmpty()) {
// List<Integer> ssos = new ArrayList<>(ssoByTraitId.values());
// ssos.sort(Comparator.reverseOrder());
// maxSso = ssos.get(0);
// }
SampleGroup sampleGroup = new SampleGroup();
sampleGroup.setDateLoaded(new Date());
sampleGroup.setDeviceIdentifierId(scoringDevId.getDeviceIdentifierId());
sampleGroup.setOperatorName(descriptionField.getText().trim());
sampleGroup.setTrialId(trial.getTrialId());
// Now need to create the samples - but first - need all the TraitInstances
java.util.function.Predicate<TraitInstance> visitor = new java.util.function.Predicate<TraitInstance>() {
@Override
public boolean test(TraitInstance ti) {
traitInstances.add(ti);
return true;
}
};
traitInstanceChoiceTreeModel.visitChosenChildNodes(visitor);
return sampleGroup;
}
示例11: getSpecimens
import org.apache.commons.collections15.Predicate; //导入依赖的package包/类
private List<Specimen> getSpecimens(KDSmartDatabase db) throws IOException {
final List<Specimen> specimens = new ArrayList<>();
Predicate<Specimen> visitor = new Predicate<Specimen>() {
@Override
public boolean evaluate(Specimen s) {
specimens.add(s);
return true;
}
};
db.visitSpecimensForTrial(trial.getEntityId(), visitor);
return specimens;
}
示例12: getEditStateSamplesByPlotOrSpecimen
import org.apache.commons.collections15.Predicate; //导入依赖的package包/类
public Map<PlotOrSpecimen,KdxSample> getEditStateSamplesByPlotOrSpecimen(TraitInstance ti, Predicate<Plot> plotFilter) {
Map<PlotOrSpecimen,KdxSample> result = new HashMap<>(plots.size());
for (Plot plot : plots) {
if (plotFilter == null || plotFilter.evaluate(plot)) {
for (Integer psnum : plot.getSpecimenNumbers(PlotOrSpecimen.INCLUDE_PLOT)) {
PlotOrSpecimen pos = plot.getPlotOrSpecimen(psnum);
KdxSample sm = getEditStateSampleFor(ti, pos);
if (sm != null) {
result.put(pos, sm);
}
}
}
}
return result;
}
示例13: collectColumnIndices
import org.apache.commons.collections15.Predicate; //导入依赖的package包/类
protected List<Integer> collectColumnIndices(Predicate<ValueRetriever<?>> predicate) {
List<Integer> result = new ArrayList<>();
for (int vfIndex = valueRetrievers.size(); --vfIndex >= 0; ) {
ValueRetriever<?> vr = valueRetrievers.get(vfIndex);
if (predicate.evaluate(vr)) {
result.add(vfIndex);
}
}
return result;
}
示例14: makeBlockAllFilter
import org.apache.commons.collections15.Predicate; //导入依赖的package包/类
/**
* Returns a FilterIterator that blocks
* all of its elements
*
* @param i the Iterator to "filter"
* @return "filtered" iterator
*/
protected FilterIterator makeBlockAllFilter(Iterator i) {
Predicate pred = new Predicate() {
public boolean evaluate(Object x) {
return false;
}
};
return new FilterIterator(i, pred);
}
示例15: PredicatedMap
import org.apache.commons.collections15.Predicate; //导入依赖的package包/类
/**
* Constructor that wraps (not copies).
*
* @param map the map to decorate, must not be null
* @param keyPredicate the predicate to validate the keys, null means no check
* @param valuePredicate the predicate to validate to values, null means no check
* @throws IllegalArgumentException if the map is null
*/
protected PredicatedMap(Map<K, V> map, Predicate<? super K> keyPredicate, Predicate<? super V> valuePredicate) {
super(map);
this.keyPredicate = keyPredicate;
this.valuePredicate = valuePredicate;
Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<K, V> entry = it.next();
K key = entry.getKey();
V value = entry.getValue();
validate(key, value);
}
}