just format
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2891 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
11acc98a34
commit
14cb7a7f1b
|
@ -37,71 +37,67 @@
|
|||
*/
|
||||
package com.ibm.wala.demandpa.genericutil;
|
||||
|
||||
|
||||
/**
|
||||
* Interface for defining an arbitrary predicate on {@link Object}s.
|
||||
*/
|
||||
public abstract class Predicate<T> {
|
||||
public static final Predicate FALSE = new Predicate() {
|
||||
public static final Predicate FALSE = new Predicate() {
|
||||
@Override
|
||||
public boolean test(Object obj_) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean test(Object obj_) {
|
||||
return false;
|
||||
}
|
||||
public static final Predicate TRUE = FALSE.not();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Predicate<T> truePred() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Predicate<T> falsePred() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/** Test whether an {@link Object} satisfies this {@link Predicate} */
|
||||
public abstract boolean test(T obj_);
|
||||
|
||||
/** Return a predicate that is a negation of this predicate */
|
||||
public Predicate<T> not() {
|
||||
final Predicate<T> originalPredicate = this;
|
||||
return new Predicate<T>() {
|
||||
@Override
|
||||
public boolean test(T obj_) {
|
||||
return !originalPredicate.test(obj_);
|
||||
}
|
||||
};
|
||||
|
||||
public static final Predicate TRUE = FALSE.not();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Predicate<T> truePred() {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Predicate<T> falsePred() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/** Test whether an {@link Object} satisfies this {@link Predicate} */
|
||||
public abstract boolean test(T obj_);
|
||||
/**
|
||||
* Return a predicate that is a conjunction of this predicate and another predicate
|
||||
*/
|
||||
public Predicate<T> and(final Predicate<T> conjunct_) {
|
||||
final Predicate<T> originalPredicate = this;
|
||||
return new Predicate<T>() {
|
||||
@Override
|
||||
public boolean test(T obj_) {
|
||||
return originalPredicate.test(obj_) && conjunct_.test(obj_);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** Return a predicate that is a negation of this predicate */
|
||||
public Predicate<T> not() {
|
||||
final Predicate<T> originalPredicate = this;
|
||||
return new Predicate<T>() {
|
||||
@Override
|
||||
public boolean test(T obj_) {
|
||||
return !originalPredicate.test(obj_);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a predicate that is a conjunction of this predicate and another
|
||||
* predicate
|
||||
*/
|
||||
public Predicate<T> and(final Predicate<T> conjunct_) {
|
||||
final Predicate<T> originalPredicate = this;
|
||||
return new Predicate<T>() {
|
||||
@Override
|
||||
public boolean test(T obj_) {
|
||||
return originalPredicate.test(obj_) && conjunct_.test(obj_);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a predicate that is a conjunction of this predicate and another
|
||||
* predicate
|
||||
*/
|
||||
public Predicate<T> or(final Predicate<T> disjunct_) {
|
||||
final Predicate<T> originalPredicate = this;
|
||||
return new Predicate<T>() {
|
||||
@Override
|
||||
public boolean test(T obj_) {
|
||||
return originalPredicate.test(obj_) || disjunct_.test(obj_);
|
||||
}
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Return a predicate that is a conjunction of this predicate and another predicate
|
||||
*/
|
||||
public Predicate<T> or(final Predicate<T> disjunct_) {
|
||||
final Predicate<T> originalPredicate = this;
|
||||
return new Predicate<T>() {
|
||||
@Override
|
||||
public boolean test(T obj_) {
|
||||
return originalPredicate.test(obj_) || disjunct_.test(obj_);
|
||||
}
|
||||
};
|
||||
}
|
||||
} // class Predicate
|
||||
|
||||
|
|
Loading…
Reference in New Issue