/** * Create a CompositeSet with just <code>set</code> composited. * * @param set the initial set in the composite */ public CompositeSet(final Set<E> set) { super(); addComposited(set); }
/** * Create a composite set with sets as the initial set of composited Sets. * * @param sets the initial sets in the composite */ public CompositeSet(final Set<E>... sets) { super(); addComposited(sets); }
/** * Add these Sets to the list of sets in this composite * * @param sets the Sets to be appended to the composite */ public void addComposited(final Set<E>... sets) { for (final Set<E> set : sets) { addComposited(set); } }
/** * Add these Sets to the list of sets in this composite. * * @param set1 the first Set to be appended to the composite * @param set2 the second Set to be appended to the composite */ public void addComposited(final Set<E> set1, final Set<E> set2) { addComposited(set1); addComposited(set2); }
/** * Returns a set view of the keys contained in this map. The set is * backed by the map, so changes to the map are reflected in the set, and * vice-versa. If the map is modified while an iteration over the set is * in progress, the results of the iteration are undefined. The set * supports element removal, which removes the corresponding mapping from * the map, via the {@code Iterator.remove}, {@code Set.remove}, * {@code removeAll} {@code retainAll}, and {@code clear} operations. * It does not support the add or {@code addAll} operations. * <p> * This implementation returns a <code>CompositeSet</code> which * composites the key sets from all of the composited maps. * * @return a set view of the keys contained in this map. */ @Override public Set<K> keySet() { final CompositeSet<K> keys = new CompositeSet<>(); for (int i = this.composite.length - 1; i >= 0; --i) { keys.addComposited(this.composite[i].keySet()); } return keys; }
/** * Returns a set view of the mappings contained in this map. Each element * in the returned set is a <code>Map.Entry</code>. The set is backed by the * map, so changes to the map are reflected in the set, and vice-versa. * If the map is modified while an iteration over the set is in progress, * the results of the iteration are undefined. The set supports element * removal, which removes the corresponding mapping from the map, via the * {@code Iterator.remove}, {@code Set.remove}, {@code removeAll}, * {@code retainAll} and {@code clear} operations. It does not support * the {@code add} or {@code addAll} operations. * <p> * This implementation returns a <code>CompositeSet</code> which * composites the entry sets from all of the composited maps. * * @see CompositeSet * @return a set view of the mappings contained in this map. */ @Override public Set<Map.Entry<K, V>> entrySet() { final CompositeSet<Map.Entry<K, V>> entries = new CompositeSet<>(); for (int i = composite.length - 1; i >= 0; --i) { entries.addComposited(composite[i].entrySet()); } return entries; }