private Map<byte[], ? extends Collection<byte[]>> makeFamilyMap(byte[] family, byte[] qualifier) { if (family == null) { return null; } Map<byte[], Collection<byte[]>> familyMap = new TreeMap<>(Bytes.BYTES_COMPARATOR); familyMap.put(family, qualifier != null ? ImmutableSet.of(qualifier) : null); return familyMap; }
@Test public void testUserGroupNames() throws Exception { final String username = "testuser"; final ImmutableSet<String> singleGroups = ImmutableSet.of("group"); final Configuration conf = HBaseConfiguration.create(); User user = User.createUserForTesting(conf, username, singleGroups.toArray(new String[singleGroups.size()])); assertUserGroup(user, singleGroups); final ImmutableSet<String> multiGroups = ImmutableSet.of("group", "group1", "group2"); user = User.createUserForTesting(conf, username, multiGroups.toArray(new String[multiGroups.size()])); assertUserGroup(user, multiGroups); }
private void assertUserGroup(User user, ImmutableSet<String> groups) { assertNotNull("GroupNames should be not null", user.getGroupNames()); assertTrue("UserGroupNames length should be == " + groups.size(), user.getGroupNames().length == groups.size()); for (String group : user.getGroupNames()) { assertTrue("groupName should be in set ", groups.contains(group)); } }
@Override public void reduce(ImmutableBytesWritable key, Iterator<Put> values, OutputCollector<ImmutableBytesWritable, Put> output, Reporter reporter) throws IOException { String strKey = Bytes.toString(key.get()); List<Put> result = new ArrayList<>(); while (values.hasNext()) result.add(values.next()); if (relation.keySet().contains(strKey)) { Set<String> set = relation.get(strKey); if (set != null) { assertEquals(set.size(), result.size()); } else { throwAccertionError("Test infrastructure error: set is null"); } } else { throwAccertionError("Test infrastructure error: key not found in map"); } }
private boolean requestedQopContainsPrivacy() { Set<String> requestedQop = ImmutableSet.copyOf(Arrays.asList(saslProps.get(Sasl.QOP).split(","))); return requestedQop.contains("auth-conf"); }
static <E> Set<List<E>> create(List<? extends Set<? extends E>> sets) { ImmutableList.Builder<ImmutableSet<E>> axesBuilder = new ImmutableList.Builder<ImmutableSet<E>>(sets.size()); for (Set<? extends E> set : sets) { ImmutableSet<E> copy = ImmutableSet.copyOf(set); if (copy.isEmpty()) { return ImmutableSet.of(); } axesBuilder.add(copy); } final ImmutableList<ImmutableSet<E>> axes = axesBuilder.build(); ImmutableList<List<E>> listAxes = new ImmutableList<List<E>>() { @Override public int size() { return axes.size(); } @Override public List<E> get(int index) { return axes.get(index).asList(); } @Override boolean isPartialView() { return true; } }; return new CartesianSet<E>(axes, new CartesianList<E>(listAxes)); }
switch (n) { case 0: return of(); case 1: @SuppressWarnings("unchecked") // safe; elements contains only E's E elem = (E) elements[0]; return of(elem); default: int tableSize = chooseTableSize(n); Object[] table = new Object[tableSize]; int mask = tableSize - 1; E element = (E) elements[0]; return new SingletonImmutableSet<E>(element, hashCode); } else if (tableSize != chooseTableSize(uniques)) { return construct(uniques, elements); } else { Object[] uniqueElements =
/** * Returns a newly-created {@code ImmutableSet} based on the contents of * the {@code Builder}. */ @Override public ImmutableSet<E> build() { ImmutableSet<E> result = construct(size, contents); // construct has the side effect of deduping contents, so we update size // accordingly. size = result.size(); return result; } }
/** * Returns an immutable set containing each of {@code elements}, minus duplicates, in the order * each appears first in the source array. * * @throws NullPointerException if any of {@code elements} is null * @since 3.0 */ public static <E> ImmutableSet<E> copyOf(E[] elements) { switch (elements.length) { case 0: return of(); case 1: return of(elements[0]); default: return construct(elements.length, elements.clone()); } }
static ImmutableSet<File> getClassPathFromManifest(File jarFile, @Nullable Manifest manifest) { if (manifest == null) { return ImmutableSet.of(); ImmutableSet.Builder<File> builder = ImmutableSet.builder(); String classpathAttribute = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH.toString());
@Override public ImmutableList<V> asList() { final ImmutableList<Entry<K, V>> entryList = map.entrySet().asList(); return new ImmutableAsList<V>() { @Override public V get(int index) { return entryList.get(index).getValue(); } @Override ImmutableCollection<V> delegateCollection() { return ImmutableMapValues.this; } }; }
@Override Object writeReplace() { return new SerializedForm(toArray()); }
private static <K, V> ImmutableSetMultimap<K, V> copyOf( Multimap<? extends K, ? extends V> multimap, Comparator<? super V> valueComparator) { checkNotNull(multimap); // eager for GWT if (multimap.isEmpty() && valueComparator == null) { return of(); } if (multimap instanceof ImmutableSetMultimap) { @SuppressWarnings("unchecked") // safe since multimap is not writable ImmutableSetMultimap<K, V> kvMultimap = (ImmutableSetMultimap<K, V>) multimap; if (!kvMultimap.isPartialView()) { return kvMultimap; } } ImmutableMap.Builder<K, ImmutableSet<V>> builder = new ImmutableMap.Builder<K, ImmutableSet<V>>(multimap.asMap().size()); int size = 0; for (Entry<? extends K, ? extends Collection<? extends V>> entry : multimap.asMap().entrySet()) { K key = entry.getKey(); Collection<? extends V> values = entry.getValue(); ImmutableSet<V> set = valueSet(valueComparator, values); if (!set.isEmpty()) { builder.put(key, set); size += set.size(); } } return new ImmutableSetMultimap<K, V>(builder.build(), size, valueComparator); }
@Override public FileOutputStream openStream() throws IOException { return new FileOutputStream(file, modes.contains(APPEND)); }
private void checkSaslComplete() throws IOException { if (!saslClient.isComplete()) { throw new IOException("Failed to complete SASL handshake"); } Set<String> requestedQop = ImmutableSet.copyOf(Arrays.asList(saslProps.get(Sasl.QOP).split(","))); String negotiatedQop = getNegotiatedQop(); LOG.debug( "Verifying QOP, requested QOP = " + requestedQop + ", negotiated QOP = " + negotiatedQop); if (!requestedQop.contains(negotiatedQop)) { throw new IOException(String.format("SASL handshake completed, but " + "channel does not have acceptable quality of protection, " + "requested = %s, negotiated = %s", requestedQop, negotiatedQop)); } }
private void assertUserGroup(User user, ImmutableSet<String> groups) { assertNotNull("GroupNames should be not null", user.getGroupNames()); assertTrue("UserGroupNames length should be == " + groups.size(), user.getGroupNames().length == groups.size()); for (String group : user.getGroupNames()) { assertTrue("groupName should be in set ", groups.contains(group)); } }