📄 itemset.java
字号:
/**
* @(#)ItemSet.java
*
* This class represents a single candidate itemset and its support.
*
* @author Adrian Bright
*/
import java.util.*;
class ItemSet
{
/* The list of items contained in the itemset */
private LinkedList items;
/* The support count of the itemset */
private int support;
/**
* ItemSet Initialises the ItemSet.
*/
public ItemSet()
{
items = new LinkedList();
support = 0;
}
/**
* ItemSet Initialises the ItemSet with a list of new items.
* @param newItems List of new items.
*/
public ItemSet(LinkedList newItems)
{
items = newItems;
support = 0;
}
/**
* setOneItem Adds an item to the itemset.
* @param attribute The new item to be added.
*/
public void setOneItem(String attribute)
{
items.add(attribute);
}
/**
* setItems Adds multiple items to the itemset.
* @param attributes The new items to be added.
*/
public void setItems(LinkedList attributes)
{
items.addAll(attributes);
}
/**
* incrementSupport Increments the support count of the itemset.
*/
public void incrementSupport()
{
support++;
}
/**
* getItem Returns the item at the specified point in the itemset.
* @param index Identifies the position in the itemset.
* @return The item at the specified position in the itemset.
*/
public String getItem(int index)
{
return (String)items.get(index);
}
/**
* getItems Returns all the items in the itemset.
* @return The items in the itemset.
*/
public LinkedList getItems()
{
return items;
}
/**
* getSupport Returns the support count of the itemset.
* @return The support count of the itemset.
*/
public int getSupport()
{
return support;
}
/**
* size Returns the size of the itemset.
* @return The size of the itemset.
*/
public int size()
{
return items.size();
}
/**
* printItems Prints the itemset to screen.
*/
public void printItems()
{
ListIterator it = items.listIterator(0);
System.out.print("|itemset size" + items.size() + ": ");
while (it.hasNext())
{
System.out.print((String)it.next());
}
System.out.println(", support " + getSupport() + "|");
}
/**
* itemsString Returns the itemset in its name form (not id form) in
* the format of {a,b,c}.
* @param itemsRef The identifiers of each item.
* @return The itemset in name form.
*/
public String itemsString(LinkedList itemsRef)
{
String itemset = "{";
String currentItem;
ItemRef itemRef;
ListIterator it = items.listIterator(0);
ListIterator itRef;
while (it.hasNext())
{
currentItem = (String)it.next();
itRef = itemsRef.listIterator(0);
itemRef = new ItemRef();
while ((itRef.hasNext()) && (!(itemRef.getItemID().equals(currentItem))))
{
itemRef = (ItemRef)itRef.next();
}
itemset += itemRef.getItemName() + ",";
}
itemset = itemset.substring(0,itemset.length()-1);
itemset += "}";
return itemset;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -