/** * Check if the items from this itemset are all the same as those of another itemset * except the last item * and that itemset2 is lexically smaller than this itemset. If all these conditions are satisfied, * this method return the last item of itemset2. Otherwise it returns null. * @return the last item of itemset2, otherwise, null. * */ public int allTheSameExceptLastItem(AbstractOrderedItemset itemset2) { // if these itemsets do not have the same size, return null if (itemset2.size() != this.size()) { return(0); } // We will compare all items one by one starting from position i =0 to size -1 for (int i = 0; i < this.size(); i++) { // if this is the last position if (i == this.size() - 1) { // We check if the item from this itemset is be smaller (lexical order) // and different from the one of itemset2. // If not, return null. if (this.get(i) >= itemset2.get(i)) { return(0); } } // If this is not the last position, we check if items are the same else if (!this.get(i).Equals(itemset2.get(i))) { // if not, return null return(0); } } // otherwise, we return the position of the last item return(itemset2.get(itemset2.size() - 1)); }
/** * This method compare this itemset with another itemset to see if they are * equal. The method assume that the two itemsets are lexically ordered. * * @return true or false */ public bool isEqualTo(AbstractOrderedItemset itemset2) { // If they don't contain the same number of items, we return false if (this.size() != itemset2.size()) { return(false); } // We compare each item one by one from i to size - 1. for (int i = 0; i < itemset2.size(); i++) { // if different, return false if (!itemset2.get(i).Equals(this.get(i))) { return(false); } } // All the items are the same, we return true. return(true); }
/** * This method checks if this itemset is the same as another itemset * except for the last item. * @param itemset2 the second itemset * @return true if they are the same except for the last item */ public bool allTheSameExceptLastItemV2(AbstractOrderedItemset itemset2) { // if they don't contain the same number of item, return false if (itemset2.size() != this.size()) { return(false); } // Otherwise, we have to compare item by item for (int i = 0; i < this.size() - 1; i++) { // if they are not the last items, they should be the same // otherwise return false if (!this.get(i).Equals(itemset2.get(i))) { return(false); } } // All items are the same. We return true. return(true); }
/** * This methods checks if another itemset is contained in this one. * The method assumed that items are lexically ordered in itemsets. * * @param itemset2 the other itemset * @return true if it is contained */ /** * This methods checks if another itemset is contained in this one. * @param itemset2 the other itemset * @return true if it is contained */ public bool containsAll(AbstractOrderedItemset itemset2) { // first we check the size if (size() < itemset2.size()) { return(false); } // we will use this variable to remember where we are in this itemset int i = 0; // for each item in itemset2, we will try to find it in this itemset for (int j = 0; j < itemset2.size(); j++) { bool found = false; // flag to remember if we have find the item at position j // we search in this itemset starting from the current position i while (found == false && i < size()) { // if we found the current item from itemset2, we stop searching if (get(i).Equals(itemset2.get(j))) { found = true; } // if the current item in this itemset is larger than // the current item from itemset2, we return false // because the itemsets are assumed to be lexically ordered. else if (get(i) > itemset2.get(j)) { return(false); } i++; // continue searching from position i++ } // if the item was not found in the previous loop, return false if (!found) { return(false); } } return(true); // if all items were found, return true }