edu.iu.iv.modeling.tarl.author.impl
Class DefaultAuthorGroup

java.lang.Object
  |
  +--edu.iu.iv.modeling.tarl.author.impl.DefaultAuthorGroup
All Implemented Interfaces:
AuthorGroup

public class DefaultAuthorGroup
extends java.lang.Object
implements AuthorGroup

This class defines a default implementation of AuthorGroupInterface using the ExtendedHashSet.

Author:
Jeegar T Maru
See Also:
ExtendedHashSet, AuthorGroup

Constructor Summary
DefaultAuthorGroup()
          Creates a new instance of an empty AuthorGroup
DefaultAuthorGroup(AuthorGroup authors)
          Creates a new instance for a AuthorGroup as an exact replica of the specified AuthorGroup object
 
Method Summary
 void addAuthor(Author author)
          Adds an Author to the group only if it is not already present in the group
static boolean areSetEqual(AuthorGroup author_group1, AuthorGroup author_group2)
          Tests whether the two AuthorGroups are equal or not in terms of Set Equality.
 boolean containsAuthor(Author author)
          Tests whether the Group contains the Author or not
 void difference(AuthorGroup author_group)
          Modifies the Group to be the difference of the current AuthorGroup and the specified AuthorGroup.
static AuthorGroup difference(AuthorGroup author_group1, AuthorGroup author_group2)
          Returns the difference of the two specified AuthorGroups.
 java.util.Collection getAuthors()
          Returns the Group of Authors
 java.util.Iterator getIterator()
          Returns the Iterator over the Group of Authors
 Author getRandomAuthor()
          Returns a Random Author from the AuthorGroup
 AuthorGroup getRandomAuthors(int num_elements)
          Returns the specified number of different random Authors from the AuthorGroup as an AuthorGroup.
 void initialize(java.util.Collection collection)
          Initializes the group of Authors with the specified Collection
 void intersection(AuthorGroup author_group)
          Modifies the AuthorGroup to be the intersection of the Group and the specified AuthorGroup.
static AuthorGroup intersection(AuthorGroup author_group1, AuthorGroup author_group2)
          Returns the intersection of two specified AuthorGroups.
static boolean isSubset(AuthorGroup author_group1, AuthorGroup author_group2)
          Tests whether the AuthorGroup specified by the second argument is a subset of the AuthorGroup specified by the first argument
 void removeAllAuthors()
          Removes all the Authors from the Group
 boolean removeAuthor(Author author)
          Removes the Author from the Group
 int size()
          Returns the number of authors in the Group
 java.lang.String toString()
          Returns the details of the AuthorGroup as a String
 void union(AuthorGroup author_group)
          Modifies the AuthorGroup to be the union of itself and the specified AuthorGroup.
static AuthorGroup union(AuthorGroup author_group1, AuthorGroup author_group2)
          Returns the union of two specified AuthorGroups as an AuthorGroup.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultAuthorGroup

public DefaultAuthorGroup()
Creates a new instance of an empty AuthorGroup


DefaultAuthorGroup

public DefaultAuthorGroup(AuthorGroup authors)
                   throws java.lang.NullPointerException
Creates a new instance for a AuthorGroup as an exact replica of the specified AuthorGroup object

Parameters:
authors - Specifies the author set to be replicated
Throws:
java.lang.NullPointerException - if the parameter authors is null
Method Detail

initialize

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

Specified by:
initialize in interface AuthorGroup
Parameters:
collection - Specifies the collection of authors

getAuthors

public java.util.Collection getAuthors()
Returns the Group of Authors

Specified by:
getAuthors in interface AuthorGroup
Returns:
the group of authors

getIterator

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

Specified by:
getIterator in interface AuthorGroup
Returns:
the iterator over the group of authors

size

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

Specified by:
size in interface AuthorGroup
Returns:
the number of authors in the group

addAuthor

public void addAuthor(Author author)
Adds an Author to the group only if it is not already present in the group

Specified by:
addAuthor in interface AuthorGroup
Parameters:
author - Specifies the author to be added

containsAuthor

public boolean containsAuthor(Author author)
Tests whether the Group contains the Author or not

Specified by:
containsAuthor in interface AuthorGroup
Parameters:
author - Specifies the author to be tested
Returns:
true if the author is contained in the set

removeAuthor

public boolean removeAuthor(Author author)
Removes the Author from the Group

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

removeAllAuthors

public void removeAllAuthors()
Removes all the Authors from the Group

Specified by:
removeAllAuthors in interface AuthorGroup

getRandomAuthor

public Author getRandomAuthor()
Returns a Random Author from the AuthorGroup

Specified by:
getRandomAuthor in interface AuthorGroup
Returns:
a random author from the author group

getRandomAuthors

public AuthorGroup getRandomAuthors(int num_elements)
Returns the specified number of different random Authors from the AuthorGroup as an AuthorGroup. If the specified number is larger than the size of the AuthorGroup, the entire AuthorGroup is returned.

Parameters:
num_elements - Specifies the number of authors required
Returns:
the author group of different random authors

union

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

Parameters:
author_group - Specifies the author group to be unioned with

union

public static AuthorGroup union(AuthorGroup author_group1,
                                AuthorGroup author_group2)
Returns the union of two specified AuthorGroups as an AuthorGroup. Does not change any of the AuthroGroups.

Parameters:
author_group1 - Specifies the first author group
author_group2 - Specifies the second author group
Returns:
the author group containing the union

intersection

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

Parameters:
author_group - Specifies the author group to be intersected with

intersection

public static AuthorGroup intersection(AuthorGroup author_group1,
                                       AuthorGroup author_group2)
Returns the intersection of two specified AuthorGroups. Does not change any of the AuthorGroups.

Parameters:
author_group1 - Specifies the first author group
author_group2 - Specifies the second author group
Returns:
the author group containing the intersection

difference

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

Parameters:
author_group - Specifies the author group to be intersected with

difference

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

Parameters:
author_group1 - Specifies the first author group
author_group2 - Specifies the second author group
Returns:
the author group containing the difference

isSubset

public static boolean isSubset(AuthorGroup author_group1,
                               AuthorGroup author_group2)
Tests whether the AuthorGroup specified by the second argument is a subset of the AuthorGroup specified by the first argument

Parameters:
author_group1 - Specifies the first author group
author_group2 - Specifies the second author group
Returns:
true, if author_group2 is a subset of author_group1

areSetEqual

public static boolean areSetEqual(AuthorGroup author_group1,
                                  AuthorGroup author_group2)
Tests whether the two AuthorGroups are equal or not in terms of Set Equality. Two authorgroups are Set Equal if first is the subset of the second and the second is a subset of the first.

Parameters:
author_group1 - Specifies the first author group
author_group2 - Specifies the second author group
Returns:
true, if the two author groups are Set equal

toString

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

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