PrefixPredicate is a predicate which tests if a string
matches a prefix. Useful for collecting items from
a collection which begin with a prefix string.
You can use this in situations where you wish to have
incremental feedback/matching from alist.
For example, if you have a collection c, then
import com.sas.collection.PredicateEnumeration;
...
Enumeration e = new PredicateEnumeration(c.getItems(),
new PrefixPredicate("SAS"));
each e.nextElement() will return an item o from the collection
c such that o.toString() begins with "SAS".
Note, you can use a com.sas.util.transforms.EnumerationTransform
if the items in the collection/enumeration must be transformed
to String data (for prefix comparison) in a non-trivial manner.
For example, if you wish to search an Enumeration of Employee
records for one whose last name (e.getLastName()) starts
with "B", you could use an EnumerationTransform that extracts
the last name:
Enumeration employees = db.getEmployees();
Enumeration lastNames = new EnumerationTransform(employees,
new TransformInterface() {
public Object transform(Object obj) {
return ((Employee) obj).getLastName(); }
});
Enumeration e = new PredicateEnumeration(lastNames,
new PrefixPredicate("B"));
This is type of transformation is necessary if you wish to compare the
prefix to some other string than the object.toString()