获取一个新的集合,该集合是所提供集合的交错并集。
/* * Copyright Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; /* from N o w J a v a . c o m - 时代Java */ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; public class Main{ public static void main(String[] argv) throws Exception{ List keySets = java.util.Arrays.asList("asdf","nowjava.com"); System.out.println(fanIn(keySets)); /* from 时代Java公众号 - nowjava.com*/ } /** * Entries for populating {@link org.ehcache.spi.cache.Store Store} and * {@link org.ehcache.spi.loader.CacheLoader CacheLoader} instances in the * unit tests. The entries used are generally subset using the key sets * {@link #KEY_SET_A}, {@link #KEY_SET_B}, {@link #KEY_SET_C}, and/or * {@link #KEY_SET_F}. * <p/> * Some tests are dependent on the order of the keys/entries. In general, * for each key set ('xxxXn'), the keys/entries must be ordered by 'n'. */ static final Map<String, String> TEST_ENTRIES; /** * Gets a new {@code Set} that is the interleaved union of the {@code Set}s provided. * * @param keySet1 the first {@code Set} of keys to appear in the result {@code Set} * @param keySet2 the second {@code Set} of keys to appear in the result {@code Set} * * @return a new, modifiable {@code Set} holding the designated keys * * @see #fanIn(java.util.List) */ static Set<String> fanIn(final Set<String> keySet1, final Set<String> keySet2) { final List<Set<String>> keySets = new ArrayList<Set<String>>(); keySets.add(keySet1); keySets.add(keySet2); return fanIn(keySets); } /** * Gets a new {@code Set} that is the interleaved union of the {@code Set}s provided. * * @param keySet1 the first {@code Set} of keys to appear in the result {@code Set} * @param keySet2 the second {@code Set} of keys to appear in the result {@code Set} * @param keySet3 the third {@code Set} of keys to appear in the result {@code Set} * * @return a new, modifiable {@code Set} holding the designated keys * * @see #fanIn(java.util.List) */ static Set<String> fanIn(final Set<String> keySet1, final Set<String> keySet2, final Set<String> keySet3) { final List<Set<String>> keySets = new ArrayList<Set<String>>(); keySets.add(keySet1); keySets.add(keySet2); keySets.add(keySet3); return fanIn(keySets); } /** * Gets a new {@code Set} that is the interleaved union of the {@code Set}s provided. * * @param keySet1 the first {@code Set} of keys to appear in the result {@code Set} * @param keySet2 the second {@code Set} of keys to appear in the result {@code Set} * @param keySet3 the third {@code Set} of keys to appear in the result {@code Set} * @param keySet4 the fourth {@code Set} of keys to appear in the result {@code Set} * * @return a new, modifiable {@code Set} holding the designated keys * * @see #fanIn(java.util.List) */ static Set<String> fanIn(final Set<String> keySet1, final Set<String> keySet2, final Set<String> keySet3, final Set<String> keySet4) { final List<Set<String>> keySets = new ArrayList<Set<String>>(); keySets.add(keySet1); keySets.add(keySet2); keySets.add(keySet3); keySets.add(keySet4); return fanIn(keySets); }