Ejemplo n.º 1
0
  /**
   * Creates a new {@link PairSet} instance with the union of all possible transactions and items as
   * result for {@link #allTransactions()} and {@link #allItems()}, respectively, and the union of
   * pairs.
   *
   * @param other the other {@link PairSet} instance to merge
   * @return the merged {@link PairSet} instance
   */
  public PairSet<T, I> merged(PairSet<T, I> other) {
    if (other == null) return clone();

    // compute the new universe
    Set<T> newAllTransactions = new LinkedHashSet<T>(allTransactions);
    Set<I> newAllItems = new LinkedHashSet<I>(allItems);
    newAllTransactions.addAll(other.allTransactions);
    newAllItems.addAll(other.allItems);

    // compute the union of pairs
    PairSet<T, I> res = new PairSet<T, I>(matrix.clone(), newAllTransactions, newAllItems);
    if (!other.isEmpty()) res.addAll(other);
    return res;
  }
Ejemplo n.º 2
0
  /**
   * Creates a new {@link PairSet} instance with only non-empty transactions and items.
   *
   * @return the compacted {@link PairSet} instance
   */
  public PairSet<T, I> compacted() {
    // trivial case
    if (isEmpty()) return empty();

    // compute the new universe
    final Set<T> newAllTransactions = new LinkedHashSet<T>(involvedTransactions());
    final Set<I> newAllItems = new LinkedHashSet<I>(involvedItems());
    if (newAllTransactions.size() == allTransactions.size()
        && newAllItems.size() == allItems.size()) return clone();

    // compute the union of pairs
    PairSet<T, I> res = new PairSet<T, I>(matrix.empty(), newAllTransactions, newAllItems);
    res.addAll(this);
    return res;
  }