edu.iu.iv.modeling.tarl.topic.impl
Class DefaultTopicGroup

java.lang.Object
  |
  +--edu.iu.iv.modeling.tarl.topic.impl.DefaultTopicGroup
All Implemented Interfaces:
TopicGroup

public class DefaultTopicGroup
extends java.lang.Object
implements TopicGroup

This class defines the Group of Topics. It provides facilities for duplicate detection, and for iterating over the group. It also provides some sophisticated Group operations (borrowed from ExtendedHashSet) such as union, intersection, random subgroup extraction, etc.

Author:
Jeegar T Maru
See Also:
DefaultTopic, ExtendedHashSet, TopicGroup

Constructor Summary
DefaultTopicGroup()
          Creates a new instance of an empty TopicGroup
DefaultTopicGroup(TopicGroup topics)
          Creates a new instance for a TopicGroup as an exact replica of the specified TopicGroup object
 
Method Summary
 void addTopic(Topic topic)
          Adds a Topic to the group only if it is not already present in the group
static boolean areSetEqual(TopicGroup topic_group1, TopicGroup topic_group2)
          Tests whether the two TopicGroups are equal or not in terms of Set Equality.
 boolean containsTopic(Topic topic)
          Tests whether the Group contains the Topic or not
 void difference(TopicGroup topic_group)
          Modifies the Group to be the difference of the current TopicGroup and the specified TopicGroup.
static TopicGroup difference(TopicGroup topic_group1, TopicGroup topic_group2)
          Returns the difference of the two specified TopicGroups.
 java.util.Iterator getIterator()
          Returns the Iterator over the Group of Topics
 Topic getRandomTopic()
          Returns a Random Topic from the TopicGroup
 TopicGroup getRandomTopics(int num_elements)
          Returns the specified number of different random Topics from the TopicGroup as a TopicGroup.
 java.util.Collection getTopics()
          Returns the Group of Topics
 void initialize(java.util.Collection collection)
          Initializes the group of Topics with the specified Collection
 void intersection(TopicGroup topic_group)
          Modifies the TopicGroup to be the intersection of the Group and the specified TopicGroup.
static TopicGroup intersection(TopicGroup topic_group1, TopicGroup topic_group2)
          Returns the intersection of two specified TopicGroups.
static boolean isSubset(TopicGroup topic_group1, TopicGroup topic_group2)
          Tests whether the TopicGroup specified by the second argument is a subset of the TopicGroup specified by the first argument
 void removeAllTopics()
          Removes all the Topics from the Group
 boolean removeTopic(Topic topic)
          Removes the Topic from the Group
 int size()
          Returns the number of topics in the Group
 java.lang.String toString()
          Returns the details of the TopicGroup as a String
 void union(TopicGroup topic_group)
          Modifies the TopicGroup to be the union of itself and the specified TopicGroup.
static TopicGroup union(TopicGroup topic_group1, TopicGroup topic_group2)
          Returns the union of two specified TopicGroups as a TopicGroup.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultTopicGroup

public DefaultTopicGroup()
Creates a new instance of an empty TopicGroup


DefaultTopicGroup

public DefaultTopicGroup(TopicGroup topics)
                  throws java.lang.NullPointerException
Creates a new instance for a TopicGroup as an exact replica of the specified TopicGroup object

Parameters:
topics - Specifies the topic group to be replicated
Throws:
java.lang.NullPointerException - if the parameter topics is null
Method Detail

initialize

public void initialize(java.util.Collection collection)
Initializes the group of Topics with the specified Collection

Specified by:
initialize in interface TopicGroup
Parameters:
collection - Specifies the collection of topics

getTopics

public java.util.Collection getTopics()
Returns the Group of Topics

Specified by:
getTopics in interface TopicGroup
Returns:
the group of topics

getIterator

public java.util.Iterator getIterator()
Returns the Iterator over the Group of Topics

Specified by:
getIterator in interface TopicGroup
Returns:
the iterator over the group of topics

size

public int size()
Returns the number of topics in the Group

Specified by:
size in interface TopicGroup
Returns:
the number of topics in the group

addTopic

public void addTopic(Topic topic)
Adds a Topic to the group only if it is not already present in the group

Specified by:
addTopic in interface TopicGroup
Parameters:
topic - Specifies the topic to be added

containsTopic

public boolean containsTopic(Topic topic)
Tests whether the Group contains the Topic or not

Specified by:
containsTopic in interface TopicGroup
Parameters:
topic - Specifies the topic to be tested
Returns:
true if the topic is contained in the group

removeTopic

public boolean removeTopic(Topic topic)
Removes the Topic from the Group

Parameters:
topic - Specifies the topic to be removed
Returns:
true if the topic was successfully found and removed

removeAllTopics

public void removeAllTopics()
Removes all the Topics from the Group

Specified by:
removeAllTopics in interface TopicGroup

getRandomTopic

public Topic getRandomTopic()
Returns a Random Topic from the TopicGroup

Specified by:
getRandomTopic in interface TopicGroup
Returns:
a random topic from the topic group

getRandomTopics

public TopicGroup getRandomTopics(int num_elements)
Returns the specified number of different random Topics from the TopicGroup as a TopicGroup. If the specified number is larger than the size of the TopicGroup, the entire TopicGroup is returned.

Parameters:
num_elements - Specifies the number of topics required
Returns:
the topic group of different random topics

union

public void union(TopicGroup topic_group)
Modifies the TopicGroup to be the union of itself and the specified TopicGroup. It acts like the operation (a = a union b), where a is the current TopicGroup and b is the specified TopicGroup

Parameters:
topic_group - Specifies the topic group to be unioned with

union

public static TopicGroup union(TopicGroup topic_group1,
                               TopicGroup topic_group2)
Returns the union of two specified TopicGroups as a TopicGroup. Does not change any of the AuthroGroups.

Parameters:
topic_group1 - Specifies the first topic group
topic_group2 - Specifies the second topic group
Returns:
the topicgroup containing the union

intersection

public void intersection(TopicGroup topic_group)
Modifies the TopicGroup to be the intersection of the Group and the specified TopicGroup. It acts like the operation (a = a intersection b), where a is the current TopicGroup and b is the specified TopicGroup

Parameters:
topic_group - Specifies the topic group to be intersected with

intersection

public static TopicGroup intersection(TopicGroup topic_group1,
                                      TopicGroup topic_group2)
Returns the intersection of two specified TopicGroups. Does not change any of the TopicGroups.

Parameters:
topic_group1 - Specifies the first topic group
topic_group2 - Specifies the second topic group
Returns:
the topic group containing the intersection

difference

public void difference(TopicGroup topic_group)
Modifies the Group to be the difference of the current TopicGroup and the specified TopicGroup. It acts like the operation (a = a - b), where a is the current TopicGroup and b is the specified TopicGroup

Parameters:
topic_group - Specifies the topic group to be intersected with

difference

public static TopicGroup difference(TopicGroup topic_group1,
                                    TopicGroup topic_group2)
Returns the difference of the two specified TopicGroups. Does not change any of the TopicGroups. The operation can be expressed as (a - b), where a and b are the TopicGroups as defined by the first and second argument respectively.

Parameters:
topic_group1 - Specifies the first topic group
topic_group2 - Specifies the second topic group
Returns:
the topic group containing the difference

isSubset

public static boolean isSubset(TopicGroup topic_group1,
                               TopicGroup topic_group2)
Tests whether the TopicGroup specified by the second argument is a subset of the TopicGroup specified by the first argument

Parameters:
topic_group1 - Specifies the first topic group
topic_group2 - Specifies the second topic group
Returns:
true, if topic_group2 is a subset of topic_group1

areSetEqual

public static boolean areSetEqual(TopicGroup topic_group1,
                                  TopicGroup topic_group2)
Tests whether the two TopicGroups are equal or not in terms of Set Equality. Two topicgroups are Group Equal if first is the subgroup of the second and the second is a subgroup of the first.

Parameters:
topic_group1 - Specifies the first topic group
topic_group2 - Specifies the second topic group
Returns:
true, if the two topic groups are set equal

toString

public java.lang.String toString()
Returns the details of the TopicGroup as a String

Overrides:
toString in class java.lang.Object
Returns:
a string describing the topic group