edu.iu.iv.modeling.tarl.publication.impl
Class DefaultPublicationGroup

java.lang.Object
  |
  +--edu.iu.iv.modeling.tarl.publication.impl.DefaultPublicationGroup
All Implemented Interfaces:
PublicationGroup

public class DefaultPublicationGroup
extends java.lang.Object
implements PublicationGroup

This class defines a default implementation of the PublicationGroupInterface. It stores the group of Publications using a DefaultPublicationGroup.

Author:
Jeegar T Maru
See Also:
ExtendedHashSet, PublicationGroup

Constructor Summary
DefaultPublicationGroup()
          Creates a new instance of an empty PublicationGroup
DefaultPublicationGroup(PublicationGroup publications)
          Creates a new instance for a PublicationGroup as an exact replica of the specified PublicationGroup object
 
Method Summary
 void addPublication(Publication publication)
          Adds a Publication to the group only if it is not already present in the group
static boolean areSetEqual(PublicationGroup publication_group1, PublicationGroup publication_group2)
          Tests whether the two PublicationGroups are equal or not in terms of Set Equality.
 boolean containsPublication(Publication publication)
          Tests whether the Group contains the Publication or not
 void difference(PublicationGroup publication_group)
          Modifies the Group to be the difference of the current PublicationGroup and the specified PublicationGroup.
static PublicationGroup difference(PublicationGroup publication_group1, PublicationGroup publication_group2)
          Returns the difference of the two specified PublicationGroups.
 java.util.Iterator getIterator()
          Returns the Iterator over the Group of Publications
 java.util.Collection getPublications()
          Returns the Group of Publications
 Publication getRandomPublication()
          Returns a Random Publication from the PublicationGroup
 PublicationGroup getRandomPublications(int num_elements)
          Returns the specified number of different random Publications from the PublicationGroup as a PublicationGroup.
 void initialize(java.util.Collection collection)
          Initializes the group of Publications with the specified Collection
 void intersection(PublicationGroup publication_group)
          Modifies the PublicationGroup to be the intersection of the Group and the specified PublicationGroup.
static PublicationGroup intersection(PublicationGroup publication_group1, PublicationGroup publication_group2)
          Returns the intersection of two specified PublicationGroups.
 boolean isSubset(PublicationGroup publication_group)
          Tests whether the specified PublicationGroup is a subset of the current one
static boolean isSubset(PublicationGroup publication_group1, PublicationGroup publication_group2)
          Tests whether the PublicationGroup specified by the second argument is a subset of the PublicationGroup specified by the first argument
 void removeAllPublications()
          Removes all the Publications from the Group
 boolean removePublication(Publication publication)
          Removes the Publication from the Group
 int size()
          Returns the number of publications in the Group
 java.lang.String toString()
          Returns the details of the PublicationGroup as a String
 void union(PublicationGroup publication_group)
          Modifies the PublicationGroup to be the union of itself and the specified PublicationGroup.
static PublicationGroup union(PublicationGroup publication_group1, PublicationGroup publication_group2)
          Returns the union of two specified PublicationGroups as a PublicationGroup.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultPublicationGroup

public DefaultPublicationGroup()
Creates a new instance of an empty PublicationGroup


DefaultPublicationGroup

public DefaultPublicationGroup(PublicationGroup publications)
                        throws java.lang.NullPointerException
Creates a new instance for a PublicationGroup as an exact replica of the specified PublicationGroup object

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

initialize

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

Specified by:
initialize in interface PublicationGroup
Parameters:
collection - Specifies the collection of publications

getPublications

public java.util.Collection getPublications()
Returns the Group of Publications

Specified by:
getPublications in interface PublicationGroup
Returns:
the group of publications

getIterator

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

Specified by:
getIterator in interface PublicationGroup
Returns:
the iterator over the group of publications

size

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

Specified by:
size in interface PublicationGroup
Returns:
the number of publications in the group

addPublication

public void addPublication(Publication publication)
Adds a Publication to the group only if it is not already present in the group

Specified by:
addPublication in interface PublicationGroup
Parameters:
publication - Specifies the publication to be added

containsPublication

public boolean containsPublication(Publication publication)
Tests whether the Group contains the Publication or not

Specified by:
containsPublication in interface PublicationGroup
Parameters:
publication - Specifies the publication to be tested
Returns:
true if the publication is contained in the group

removePublication

public boolean removePublication(Publication publication)
Removes the Publication from the Group

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

removeAllPublications

public void removeAllPublications()
Removes all the Publications from the Group

Specified by:
removeAllPublications in interface PublicationGroup

getRandomPublication

public Publication getRandomPublication()
Returns a Random Publication from the PublicationGroup

Specified by:
getRandomPublication in interface PublicationGroup
Returns:
a random publication from the publication group

getRandomPublications

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

Specified by:
getRandomPublications in interface PublicationGroup
Parameters:
num_elements - Specifies the number of publications required
Returns:
the publication group of different random publications

union

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

Specified by:
union in interface PublicationGroup
Parameters:
publication_group - Specifies the publication group to be unioned with

union

public static PublicationGroup union(PublicationGroup publication_group1,
                                     PublicationGroup publication_group2)
Returns the union of two specified PublicationGroups as a PublicationGroup. Does not change any of the PublicationGroups.

Parameters:
publication_group1 - Specifies the first publication group
publication_group2 - Specifies the second publication group
Returns:
the publication group containing the union

intersection

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

Parameters:
publication_group - Specifies the publication group to be intersected with

intersection

public static PublicationGroup intersection(PublicationGroup publication_group1,
                                            PublicationGroup publication_group2)
Returns the intersection of two specified PublicationGroups. Does not change any of the PublicationGroups.

Parameters:
publication_group1 - Specifies the first publicationgroup
publication_group2 - Specifies the second publicationgroup
Returns:
the publication group containing the intersection

difference

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

Parameters:
publication_group - Specifies the publication group to be intersected with

difference

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

Parameters:
publication_group1 - Specifies the first publication group
publication_group2 - Specifies the second publication group
Returns:
the publication group containing the difference

isSubset

public boolean isSubset(PublicationGroup publication_group)
Tests whether the specified PublicationGroup is a subset of the current one

Specified by:
isSubset in interface PublicationGroup
Parameters:
publication_group - Specifies the publication group to be tested
Returns:
true, if publication_group is a subset of the current publication

isSubset

public static boolean isSubset(PublicationGroup publication_group1,
                               PublicationGroup publication_group2)
Tests whether the PublicationGroup specified by the second argument is a subset of the PublicationGroup specified by the first argument

Parameters:
publication_group1 - Specifies the first publication group
publication_group2 - Specifies the second publication group
Returns:
true, if publication_group2 is a subset of publication_group1

areSetEqual

public static boolean areSetEqual(PublicationGroup publication_group1,
                                  PublicationGroup publication_group2)
Tests whether the two PublicationGroups are equal or not in terms of Set Equality. Two publicationgroups are Set Equal if first is the subset of the second and the second is a subset of the first.

Parameters:
publication_group1 - Specifies the first publication group
publication_group2 - Specifies the second publication group
Returns:
true, if the two publication groups are set equal

toString

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

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