/** * 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; }
/** {@inheritDoc} */ @Override public PairSet<T, I> empty() { return createFromIndices(matrix.empty()); }