org.tm4j.topicmap.utils.testers
Class InScopeTester

java.lang.Object
  extended byorg.tm4j.topicmap.utils.testers.InScopeTester
All Implemented Interfaces:
uk.co.jezuk.mango.Predicate

public class InScopeTester
extends java.lang.Object
implements uk.co.jezuk.mango.Predicate

Predicate function which returns true if the tested object is a scoped object and if the scope of the object matches the context specified in the tester's constructor.

The tester supports two kinds of comparison. The default comparison will return true if the context specified in the constructor contains one or more topics which are in the scope of the scoped object being tester. If the matchAll option in the constructor is set to true, then the tester will return true only if every topic in the scope of the tested object is found in the context specified in the constructor.

Note To handle merging, this method normalises both the context and the scoping topics to their base topics. So if the context is specified as {TopicA, TopicB} and TopicA is merged with TopicA2, then this context will match scopes {TopicA}, {TopicB}, {TopicA, TopicB}, {TopicA2, TopicB} and {TopicA, TopicA2, TopicB2}


Constructor Summary
InScopeTester(java.util.Collection context)
          Create a new InScopeTester which will test scoped objects against a scope comrising themes.
InScopeTester(java.util.Collection context, boolean matchAll)
          Create a new InScopeTester which will test scoped objects against a context comprising of the specified themes.
InScopeTester(Topic[] context)
          Create a new InScopeTester which will test scoped objects against a scope comrising themes.
InScopeTester(Topic[] context, boolean matchAll)
          Create a new InScopeTester which will test scoped objects against a context comprising of the specified themes.
 
Method Summary
 boolean test(java.lang.Object x)
          Test if x is a ScopedObject which is in the scope of the themes specified in the constructor of this tester.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InScopeTester

public InScopeTester(Topic[] context)
Create a new InScopeTester which will test scoped objects against a scope comrising themes.

Parameters:
context - an array of Topic objects that ScopedObjects scopes will be tested against. If this parameter is null, then all ScopedObject instances will pass this test.

InScopeTester

public InScopeTester(Topic[] context,
                     boolean matchAll)
Create a new InScopeTester which will test scoped objects against a context comprising of the specified themes. The test can be either for the context to be a subset of the scope or for there to be an intersection between the context and the scope.

Parameters:
context - the collection of Topic objects which define the context to test against.
matchAll - if true, then a ScopedObject will pass this test only if all the topics in the context are found in the Scope of the ScopedObject. If false, then a ScopedObject will pass this test if one or more topics in the context are found in the Scope of the ScopedObject.

InScopeTester

public InScopeTester(java.util.Collection context)
Create a new InScopeTester which will test scoped objects against a scope comrising themes.

Parameters:
context - a Collection of Topic objects that ScopedObjects scopes will be tested against. If this parameter is null, or the Collection is empty then all ScopedObject instances will pass this test, otherwise only those ScopedObject instances whose scope contains one or more Topic objects in context will pass the test.

InScopeTester

public InScopeTester(java.util.Collection context,
                     boolean matchAll)
Create a new InScopeTester which will test scoped objects against a context comprising of the specified themes. The test can be either for the context to be a subset of the scope or for there to be an intersection between the context and the scope.

Parameters:
context - the collection of Topic objects which define the context to test against.
matchAll - if true, then a ScopedObject will pass this test only if all the topics in the context are found in the Scope of the ScopedObject. If false, then a ScopedObject will pass this test if one or more topics in the context are found in the Scope of the ScopedObject.
Method Detail

test

public boolean test(java.lang.Object x)
Test if x is a ScopedObject which is in the scope of the themes specified in the constructor of this tester.

Specified by:
test in interface uk.co.jezuk.mango.Predicate
Parameters:
x - the object to be tested.
Returns:
false if x is not a ScopedObject; true if x is a ScopedObject and the set of test themes is empty; or else true if the set of scoping topics for the matches the context specified for this tester. If the boolean matchAll property is set to true, then a match is determined if and only if every scoping topic for x is in the context, otherwise a match is determined if one or more scoping topics of x are found in the context.