|
Components | |||||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.util.PrefixPredicate
public class PrefixPredicate
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()
PredicateEnumeration
,
Enumerable.getItems()
,
EnumerationTransform
,
Serialized FormConstructor Summary | |
---|---|
PrefixPredicate(java.lang.String prefix)
Construct a PrefixPredicate that tests for strings matching the given prefix. |
Method Summary | |
---|---|
int |
findItemByPrefix(java.util.Enumeration enumer,
int startIndex)
Return the index of the item starting with the prefix string. |
int |
findItemByPrefix(IndexedGetInterface collection,
int startIndex)
Return the index of the item starting with the prefix string. |
java.lang.String |
getPrefix()
Return the value of the prefix string |
boolean |
predicate(java.lang.Object object)
the predicate test: does the object start with the stored prefix string? |
boolean |
predicate(java.lang.String string)
The predicate test: does the object start with the stored prefix string? |
void |
setPrefix(java.lang.String newPrefix)
Set the prefix string |
Constructor Detail |
---|
public PrefixPredicate(java.lang.String prefix)
prefix
- a prefix string. Must be non-null.Method Detail |
---|
public boolean predicate(java.lang.Object object)
predicate
in interface com.sas.util.PredicateInterface
public boolean predicate(java.lang.String string)
predicate
in interface StringPredicateInterface
string
- The String which should be tested
public void setPrefix(java.lang.String newPrefix)
newPrefix
- the new value for the prefix stringpublic java.lang.String getPrefix()
public int findItemByPrefix(java.util.Enumeration enumer, int startIndex)
enumer
- the enumeration in which to find the item with the prefix string in.startIndex
- the index to start searching the enumeratio from.
public int findItemByPrefix(IndexedGetInterface collection, int startIndex)
collection
- the collection to find the item with the prefix string in.startIndex
- the index to start searching the collection from.
|
Components | |||||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |