From: Lars H. <lh...@us...> - 2005-03-08 13:58:44
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8497/src/org/tmapiutils/query/tolog/predicates Modified Files: DynamicAssociationPredicate.java Log Message: Added private class TypeTester Index: DynamicAssociationPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/DynamicAssociationPredicate.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DynamicAssociationPredicate.java 8 Mar 2005 12:33:56 -0000 1.4 --- DynamicAssociationPredicate.java 8 Mar 2005 13:58:33 -0000 1.5 *************** *** 34,37 **** --- 34,38 ---- import org.tmapiutils.query.tolog.utils.VariableSet; + import uk.co.jezuk.mango.Predicate; import uk.co.jezuk.mango.UnaryFunction; import uk.co.jezuk.mango.iterators.PredicatedIterator; *************** *** 43,48 **** import org.tmapi.core.Association; import org.tmapi.core.AssociationRole; - import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; import org.tmapi.core.TMAPIException; import org.tmapi.index.core.AssociationsIndex; --- 44,51 ---- import org.tmapi.core.Association; import org.tmapi.core.AssociationRole; import org.tmapi.core.TopicMap; + import org.tmapi.core.Topic; + import org.tmapi.core.Occurrence; + import org.tmapi.core.TopicName; import org.tmapi.core.TMAPIException; import org.tmapi.index.core.AssociationsIndex; *************** *** 447,451 **** ! // ToDo: TypeTester --- 450,493 ---- ! /** ! * A simplified version of the ! * org.tm4j.topicmap.utils.testers.TypeTester ! * ! * Returns <code>true</code> if the topic bounded to this ! * predicate is used as type of the specified TopicMapObject. ! */ ! private class TypeTester implements Predicate { ! ! private Topic _type; ! ! public TypeTester(Topic type) { ! _type = type; ! } ! ! /** ! * Performs the test. ! * @param o The object to be tested. ! * @return True if the object is a Topic, Association, ! * AssociationRole, Occurrence or TopicName ! * and if there is one or more type-specifying ! * topic for that object which is the allowed type. ! */ ! public boolean test(Object o) { ! Topic type = null; ! if (o instanceof Topic) { ! // Handle the special case ! return ((Topic) o).getTypes().contains(_type); ! } else if (o instanceof Association) { ! type = ((Association) o).getType(); ! } else if (o instanceof AssociationRole) { ! type = ((AssociationRole) o).getType(); ! } else if (o instanceof Occurrence) { ! type = ((Occurrence) o).getType(); ! } else if (o instanceof TopicName) { ! type = ((TopicName) o).getType(); ! } ! return (type != null && _type.equals(type)); ! } ! } |