/** * Wraps a {@link BinaryMatrix} instance with a {@link PairSet} instance. * * <p><b>NOTE:</b> the maximum item and transaction IDs are those existing in the binary matrix * when the wrapping take place * * @param b a {@link BinaryMatrix} instance to wrap * @return a new {@link PairSet} instance, indexed by the given matrix */ public static PairSet<Integer, Integer> createFromBinaryMatrix(BinaryMatrix b) { // TODO this is a little bit costly since PairSet will allocate an array // and a HashMap of Integers to map elements of BinaryMatrix... // Think about a IntegerPairSet class or to an "fake" IntegerIndexedSet // just for this purpose. IntegerSet t = new IntegerSet(b.emptyRow()); t.intSet().add(b.maxRow() + 1); t.intSet().complement(); IntegerSet i = new IntegerSet(b.emptyRow()); i.intSet().add(b.maxCol() + 1); i.intSet().complement(); return new PairSet<Integer, Integer>(b, t, i); }
/** * Initializes the set by specifying all possible transactions and items. * * @param matrix {@link BinaryMatrix} instance used to internally represent the matrix * @param transactions collection of <i>all</i> possible transactions. The specified order will be * preserved within when iterating over the {@link PairSet} instance. * @param items collection of <i>all</i> possible items. The specified order will be preserved * within each transaction {@link PairSet}. */ public PairSet(BinaryMatrix matrix, Collection<T> transactions, Collection<I> items) { if (transactions == null || items == null) throw new NullPointerException(); this.matrix = matrix; IntSet tmp = matrix.emptyRow(); if (transactions instanceof IndexedSet<?>) allTransactions = (IndexedSet<T>) transactions; else allTransactions = new IndexedSet<T>(tmp.empty(), transactions).universe(); // .unmodifiable(); if (items instanceof IndexedSet<?>) allItems = (IndexedSet<I>) items; else allItems = new IndexedSet<I>(tmp.empty(), items).universe(); // .unmodifiable(); }