laur.dm.ar
Class Itemset

java.lang.Object
  |
  +--laur.dm.ar.Itemset
All Implemented Interfaces:
CriteriaComparable, java.io.Serializable

public class Itemset
extends java.lang.Object
implements java.io.Serializable, CriteriaComparable

An itemset is an ordered list of integers that identify items coupled with a double value representing the support of the itemset as a percentage.

See Also:
Serialized Form

Field Summary
static int BY_SIZE
          Specifies sorting should be performed according to itemset size.
static int BY_SUPPORT
          Specifies sorting should be performed according to itemset support.
 
Constructor Summary
Itemset()
          Creates a new empty itemset.
Itemset(int c)
          Create a new empty itemset of specified capacity.
Itemset(Itemset itemset)
          Create a new itemset by copying a given one.
 
Method Summary
 boolean add(int item)
          Add a new item to the itemset.
 boolean canCombineWith(Itemset itemset)
          Check whether two itemsets can be combined.
 Itemset combineWith(Itemset itemset)
          Combine two itemsets into a new one that will contain all the items in the first itemset plus the last item in the second itemset.
 int compareTo(java.lang.Object obj, int criteria)
          Compare two Itemset objects on one of several criteria.
 boolean equals(java.lang.Object o)
          Checks equality with another object.
 int get(int i)
          Return i-th item in itemset.
 double getSupport()
          Return support of itemset.
 long getWeight()
          Return weight of itemset.
 void incrementWeight()
          Increment the weight of the itemset.
 boolean intersects(Itemset itemset)
          Return true if this itemset has items in common with itemset.
 boolean isIncludedIn(Itemset itemset)
          Checks inclusion in a given itemset.
 boolean isMarked()
          Return itemset mark.
static void main(java.lang.String[] args)
          sample usage and testing
 boolean mark()
          Mark the itemset.
static void pruneDuplicates(java.util.ArrayList v)
          Remove all duplicate itemsets from the vector v
static void pruneNonMaximal(java.util.ArrayList v)
          Remove all non-maximal itemsets from the vector v
 boolean remove(int item)
          Removes a given item from the itemset.
 boolean removeLast()
          Removes last item (which has the greatest value) from the itemset.
 void setSupport(double newSupport)
          Set the support of the itemset.
 void setWeight(long newWeight)
          Set the weight of the itemset.
 int size()
          Return size of itemset.
static Itemset subtraction(Itemset is1, Itemset is2)
          Return a new Itemset that contains only those items from is1 that do not appear in is2.
 java.lang.String toString()
          Return a String representation of the Itemset.
static Itemset union(Itemset is1, Itemset is2)
          Return a new Itemset that contains all those items that appear in is1 and in is2.
 boolean unmark()
          Unmark the itemset.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BY_SIZE

public static final int BY_SIZE
Specifies sorting should be performed according to itemset size.

BY_SUPPORT

public static final int BY_SUPPORT
Specifies sorting should be performed according to itemset support.
Constructor Detail

Itemset

public Itemset(int c)
Create a new empty itemset of specified capacity.
Parameters:
c - the capacity of the itemset
Throws:
java.lang.IllegalArgumentException - c is negative or zero

Itemset

public Itemset()
Creates a new empty itemset.

Itemset

public Itemset(Itemset itemset)
Create a new itemset by copying a given one.
Parameters:
itemset - the itemset to be copied
Throws:
java.lang.IllegalArgumentException - itemset is null
Method Detail

getSupport

public double getSupport()
Return support of itemset.

setSupport

public void setSupport(double newSupport)
Set the support of the itemset.
Parameters:
newSupport - the support of the itemset
Throws:
java.lang.IllegalArgumentException - newSupport is < 0 or > 100

getWeight

public long getWeight()
Return weight of itemset.

setWeight

public void setWeight(long newWeight)
Set the weight of the itemset.
Parameters:
newWeight - the weight of the itemset
Throws:
java.lang.IllegalArgumentException - newWeight is < 0

incrementWeight

public void incrementWeight()
Increment the weight of the itemset.

size

public int size()
Return size of itemset.
Returns:
size of itemset

get

public int get(int i)
Return i-th item in itemset. The count starts from 0.
Parameters:
i - the index of the item to get
Returns:
the i-th item
Throws:
IndexOutOfBoundsException - i is an invalid index

add

public boolean add(int item)
Add a new item to the itemset.
Parameters:
item - the item to be added
Returns:
true if item was added, false if it wasn't added (was already there!)
Throws:
java.lang.IllegalArgumentException - item is <= 0

remove

public boolean remove(int item)
Removes a given item from the itemset.
Parameters:
item - the item to remove
Returns:
true if item was removed, false if it wasn't removed (was not found in itemset!)
Throws:
java.lang.IllegalArgumentException - item is <= 0

removeLast

public boolean removeLast()
Removes last item (which has the greatest value) from the itemset.
Returns:
true if item was removed, false if it wasn't removed (the itemset was empty)

compareTo

public int compareTo(java.lang.Object obj,
                     int criteria)
Compare two Itemset objects on one of several criteria.
Specified by:
compareTo in interface CriteriaComparable
Parameters:
is - the Itemset object with which we want to compare this object
criteria - the criteria on which we want to compare, can be one of SIZE or SUPPORT.
Returns:
a negative value if this object is smaller than is, 0 if they are equal, and a positive value if this object is greater.
Throws:
java.lang.IllegalArgumentException - obj is not an Itemset or criteria is invalid

equals

public boolean equals(java.lang.Object o)
Checks equality with another object.
Overrides:
equals in class java.lang.Object
Parameters:
o - the object against which we test for equality
Returns:
true if object is equal to our itemset, false otherwise

isIncludedIn

public boolean isIncludedIn(Itemset itemset)
Checks inclusion in a given itemset.
Parameters:
itemset - the itemset against which we test for inclusion
Throws:
java.lang.IllegalArgumentException - itemset is null

intersects

public boolean intersects(Itemset itemset)
Return true if this itemset has items in common with itemset.
Parameters:
itemset - the itemset with which we compare
Returns:
true if itemset contains items of this itemset, false otherwise.
Throws:
java.lang.IllegalArgumentException - itemset is null

subtraction

public static Itemset subtraction(Itemset is1,
                                  Itemset is2)
Return a new Itemset that contains only those items from is1 that do not appear in is2.
Parameters:
is1 - the itemset from which we want to subtract
is2 - the itemset whose items we want to subtract
Returns:
an Itemset containing only those items of is1 that do not appear in is2.
Throws:
java.lang.IllegalArgumentException - is1 or is2 is null

union

public static Itemset union(Itemset is1,
                            Itemset is2)
Return a new Itemset that contains all those items that appear in is1 and in is2.
Parameters:
is1 - the first itemset participating to the union
is2 - the second itemset participating to the union
Returns:
an Itemset containing all those items that appear in is1 and in is2.
Throws:
java.lang.IllegalArgumentException - is1 or is2 is null

canCombineWith

public boolean canCombineWith(Itemset itemset)
Check whether two itemsets can be combined. Two itemsets can be combined if they differ only in the last item.
Parameters:
itemset - itemset with which to combine
Returns:
true if the itemsets can be combined, false otherwise
Throws:
java.lang.IllegalArgumentException - itemset is null

combineWith

public Itemset combineWith(Itemset itemset)
Combine two itemsets into a new one that will contain all the items in the first itemset plus the last item in the second itemset.
Parameters:
itemset - itemset with which to combine
Returns:
an itemset that combines the two itemsets as described above
Throws:
java.lang.IllegalArgumentException - itemset is null

mark

public boolean mark()
Mark the itemset.
Returns:
true if itemset was already marked, false otherwise

unmark

public boolean unmark()
Unmark the itemset.
Returns:
true if itemset was marked, false otherwise

isMarked

public boolean isMarked()
Return itemset mark.
Returns:
true if itemset is marked, false otherwise

toString

public java.lang.String toString()
Return a String representation of the Itemset.
Overrides:
toString in class java.lang.Object
Returns:
String representation of Itemset

pruneNonMaximal

public static void pruneNonMaximal(java.util.ArrayList v)
Remove all non-maximal itemsets from the vector v
Parameters:
v - the collection of itemsets

pruneDuplicates

public static void pruneDuplicates(java.util.ArrayList v)
Remove all duplicate itemsets from the vector v
Parameters:
v - the collection of itemsets

main

public static void main(java.lang.String[] args)
sample usage and testing