@Override protected NavigableMap<String, String> create(Entry<String, String>[] entries) { return Collections.emptyNavigableMap(); } })
classes.add(Collections.checkedList(nonRandomAccessList, Void.class).getClass()); classes.add(Collections.checkedMap(Collections.emptyMap(), Void.class, Void.class).getClass()); classes.add(Collections.checkedNavigableMap(Collections.emptyNavigableMap(), Void.class, Void.class).getClass()); classes.add(Collections.checkedNavigableSet(Collections.emptyNavigableSet(), Void.class).getClass()); classes.add(Collections.checkedQueue(new LinkedList<>(), Void.class).getClass()); classes.add(Collections.synchronizedList(nonRandomAccessList).getClass()); classes.add(Collections.synchronizedMap(Collections.emptyMap()).getClass()); classes.add(Collections.synchronizedNavigableMap(Collections.emptyNavigableMap()).getClass()); classes.add(Collections.synchronizedNavigableSet(Collections.emptyNavigableSet()).getClass()); classes.add(Collections.synchronizedSet(Collections.emptySet()).getClass()); classes.add(Collections.unmodifiableList(nonRandomAccessList).getClass()); classes.add(Collections.unmodifiableMap(Collections.emptyMap()).getClass()); classes.add(Collections.unmodifiableNavigableMap(Collections.emptyNavigableMap()).getClass()); classes.add(Collections.unmodifiableNavigableSet(Collections.emptyNavigableSet()).getClass()); classes.add(Collections.unmodifiableSet(Collections.emptySet()).getClass());
assertTrue(immutability.test(Collections.emptyListIterator())); assertTrue(immutability.test(Collections.emptyMap())); assertTrue(immutability.test(Collections.emptyNavigableMap())); assertTrue(immutability.test(Collections.emptyNavigableSet())); assertTrue(immutability.test(Collections.emptySet()));
@Override protected NavigableMap<String, String> create(Entry<String, String>[] entries) { return Collections.emptyNavigableMap(); } })
/** * @param <I> The {@link KeyTypeIndicator} * @param indicators The indicators to group * @return A {@link NavigableMap} where key=the case <U>insensitive</U> {@link #getKeyType() key type}, * value = the {@link List} of all indicators having the same key type */ static <I extends KeyTypeIndicator> NavigableMap<String, List<I>> groupByKeyType(Collection<? extends I> indicators) { return GenericUtils.isEmpty(indicators) ? Collections.emptyNavigableMap() : indicators.stream() .collect(Collectors.groupingBy( KeyTypeIndicator::getKeyType, () -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER), Collectors.toList())); } }
protected static NavigableMap<String, byte[]> getMapReadOnly(final MapDBTransaction tx, final String mapName) { checkNotNull(tx, "Precondition violation - argument 'tx' must not be NULL!"); checkNotNull(mapName, "Precondition violation - argument 'mapName' must not be NULL!"); if (tx.exists(mapName) == false) { return Collections.emptyNavigableMap(); } else { return tx.treeMap(mapName, Serializer.STRING, Serializer.BYTE_ARRAY); } }
protected static NavigableMap<String, Boolean> getMapInverseReadOnly(final MapDBTransaction tx, final String mapName) { checkNotNull(tx, "Precondition violation - argument 'tx' must not be NULL!"); checkNotNull(mapName, "Precondition violation - argument 'mapName' must not be NULL!"); String inverseMapName = mapName + INVERSE_MATRIX_SUFFIX; if (tx.exists(inverseMapName) == false) { return Collections.emptyNavigableMap(); } else { return tx.treeMap(inverseMapName, Serializer.STRING, Serializer.BOOLEAN); } }
public static NavigableMap<String, String> toStringExtensions(Map<String, ?> extensions) { if (GenericUtils.isEmpty(extensions)) { return Collections.emptyNavigableMap(); } // NOTE: even though extensions are probably case sensitive we do not allow duplicate name that differs only in case NavigableMap<String, String> map = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); extensions.forEach((key, value) -> { ValidateUtils.checkNotNull(value, "No value for extension=%s", key); String prev = map.put(key, (value instanceof byte[]) ? new String((byte[]) value, StandardCharsets.UTF_8) : value.toString()); ValidateUtils.checkTrue(prev == null, "Multiple values for extension=%s", key); }); return map; }
public static NavigableMap<String, byte[]> toBinaryExtensions(Map<String, String> extensions) { if (GenericUtils.isEmpty(extensions)) { return Collections.emptyNavigableMap(); } // NOTE: even though extensions are probably case sensitive we do not allow duplicate name that differs only in case NavigableMap<String, byte[]> map = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); extensions.forEach((key, value) -> { ValidateUtils.checkNotNull(value, "No value for extension=%s", key); byte[] prev = map.put(key, value.getBytes(StandardCharsets.UTF_8)); ValidateUtils.checkTrue(prev == null, "Multiple values for extension=%s", key); }); return map; }
/** * @return A snapshot of the currently registered specialized {@link PublicKeyEntryDataResolver}-s, * where key=the key-type value (case <U>insensitive</U>) - e.g., "ssh-rsa", * "pgp-sign-dss", etc., value=the associated {@link PublicKeyEntryDataResolver} * for the key type */ public static NavigableMap<String, PublicKeyEntryDataResolver> getRegisteredKeyDataEntryResolvers() { NavigableMap<String, PublicKeyEntryDataResolver> decoders; synchronized (KEY_DATA_RESOLVERS) { if (KEY_DATA_RESOLVERS.isEmpty()) { return Collections.emptyNavigableMap(); } decoders = new TreeMap<>(KEY_DATA_RESOLVERS.comparator()); decoders.putAll(KEY_DATA_RESOLVERS); } return decoders; }
protected NavigableMap<String, Object> readFileAttributes(Path file, String view, LinkOption... options) throws IOException { try { Map<String, ?> attrs = Files.readAttributes(file, view, options); if (GenericUtils.isEmpty(attrs)) { return Collections.emptyNavigableMap(); } NavigableMap<String, Object> sorted = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); sorted.putAll(attrs); return sorted; } catch (IOException e) { return handleReadFileAttributesException(file, view, options, e); } }
private NavigableMap<Long, byte[]> getMapForReading(final MapDBTransaction tx) { checkNotNull(tx, "Precondition violation - argument 'tx' must not be NULL!"); String mapName = this.getBranchName() + MAP_SUFFIX; if (tx.exists(mapName)) { return Collections.unmodifiableNavigableMap(tx.treeMap(mapName, Serializer.LONG, Serializer.BYTE_ARRAY)); } else { return Collections.emptyNavigableMap(); } }
@Override public NavigableMap<Long, ReceivedMessage> getMessages(MessageStatus status) { switch(status) { case CREATED: return Collections.unmodifiableNavigableMap(messages.unreadMessages); case READ: return Collections.unmodifiableNavigableMap(messages.readMessages); case DELETED: return Collections.unmodifiableNavigableMap(messages.deletedMessages); default: return Collections.emptyNavigableMap(); } }
/** * @param subKeys The {@link Subkey}-s to map - ignored if {@code null}/empty * @return A {@link NavigableMap} where key=the (case <U>insensitive</U>) fingerprint * value, value=the matching {@link Subkey} * @throws NullPointerException If key with {@code null} fingerprint encountered * @throws IllegalArgumentException If key with empty fingerprint encountered * @throws IllegalStateException If more than one key with same fingerprint found */ public static NavigableMap<String, Subkey> mapSubKeysByFingerprint(Collection<? extends Subkey> subKeys) { if (GenericUtils.isEmpty(subKeys)) { return Collections.emptyNavigableMap(); } NavigableMap<String, Subkey> keysMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); for (Subkey sk : subKeys) { String fp = ValidateUtils.checkNotNullAndNotEmpty(sk.getFingerprint(), "No fingerprint for %s", sk); Subkey prev = keysMap.put(fp, sk); ValidateUtils.checkState(prev == null, "Multiple sub-keys with fingerprint=%s: %s / %s", fp, sk, prev); } return keysMap; }
private NavigableMap<Long, ReceivedMessage> getMessages(long tm, MessageStatus status) { switch(status) { case SENT: return Collections.unmodifiableNavigableMap(messages.unreadMessages.tailMap(tm)); case READ: return Collections.unmodifiableNavigableMap(messages.readMessages.tailMap(tm)); case DELETED: return Collections.unmodifiableNavigableMap(messages.deletedMessages.tailMap(tm)); default: return Collections.emptyNavigableMap(); } }
@Test public void readPost111() throws IOException { String prefix = "post-1.1.1-"; assertCollectionEqualAndUsable(Collections.emptyList(), readFileAndDeserialize(prefix + "emptyList")); assertCollectionEqualAndUsable(Arrays.asList("test"), readFileAndDeserialize(prefix + "asList")); assertCollectionEqualAndUsable(Collections.emptyMap(), readFileAndDeserialize(prefix + "emptyMap")); assertCollectionEqualAndUsable(Collections.emptyNavigableMap(), readFileAndDeserialize(prefix + "emptyNavigableMap")); assertCollectionEqualAndUsable(Collections.emptySortedMap(), readFileAndDeserialize(prefix + "emptySortedMap")); assertCollectionEqualAndUsable(Collections.emptySet(), readFileAndDeserialize(prefix + "emptySet")); assertCollectionEqualAndUsable(Collections.emptyNavigableSet(), readFileAndDeserialize(prefix + "emptyNavigableSet")); assertCollectionEqualAndUsable(Collections.emptySortedSet(), readFileAndDeserialize(prefix + "emptySortedSet")); assertCollectionEqualAndUsable(Collections.singleton("test"), readFileAndDeserialize(prefix + "singletonSet")); assertCollectionEqualAndUsable(Collections.singletonList("test"), readFileAndDeserialize(prefix + "singletonList")); assertCollectionEqualAndUsable(Collections.singletonMap("k", "v"), readFileAndDeserialize(prefix + "singletonMap")); }
@Test public void testEmptyCollectionClone() { Object target; target = Collections.emptyList(); assertCollectionEqualAndUsable(target, cloneWithKryo(target)); target = Collections.emptySet(); assertCollectionEqualAndUsable(target, cloneWithKryo(target)); target = Collections.emptyMap(); assertCollectionEqualAndUsable(target, cloneWithKryo(target)); target = Collections.emptyNavigableMap(); assertCollectionEqualAndUsable(target, cloneWithKryo(target)); target = Collections.emptyNavigableSet(); assertCollectionEqualAndUsable(target, cloneWithKryo(target)); target = Collections.emptySortedMap(); assertCollectionEqualAndUsable(target, cloneWithKryo(target)); target = Collections.emptySortedSet(); assertCollectionEqualAndUsable(target, cloneWithKryo(target)); }
@Test public void testEmptyCollectionSerialization() { Object target; target = Collections.emptyList(); assertCollectionEqualAndUsable(target, serAndDeser(target)); target = Collections.emptySet(); assertCollectionEqualAndUsable(target, serAndDeser(target)); target = Collections.emptyMap(); assertCollectionEqualAndUsable(target, serAndDeser(target)); target = Collections.emptyNavigableMap(); assertCollectionEqualAndUsable(target, serAndDeser(target)); target = Collections.emptyNavigableSet(); assertCollectionEqualAndUsable(target, serAndDeser(target)); target = Collections.emptySortedMap(); assertCollectionEqualAndUsable(target, serAndDeser(target)); target = Collections.emptySortedSet(); assertCollectionEqualAndUsable(target, serAndDeser(target)); }
@Test public void testEmptyCollectionSerialization() { Object target; target = Collections.emptyList(); assertCollectionEqualAndUsable(target, serAndDeser(target)); target = Collections.emptySet(); assertCollectionEqualAndUsable(target, serAndDeser(target)); target = Collections.emptyMap(); assertCollectionEqualAndUsable(target, serAndDeser(target)); target = Collections.emptyNavigableMap(); assertCollectionEqualAndUsable(target, serAndDeser(target)); target = Collections.emptyNavigableSet(); assertCollectionEqualAndUsable(target, serAndDeser(target)); target = Collections.emptySortedMap(); assertCollectionEqualAndUsable(target, serAndDeser(target)); target = Collections.emptySortedSet(); assertCollectionEqualAndUsable(target, serAndDeser(target)); }
@Test public void testEmptyCollectionClone() { Object target; target = Collections.emptyList(); assertCollectionEqualAndUsable(target, cloneWithKryo(target)); target = Collections.emptySet(); assertCollectionEqualAndUsable(target, cloneWithKryo(target)); target = Collections.emptyMap(); assertCollectionEqualAndUsable(target, cloneWithKryo(target)); target = Collections.emptyNavigableMap(); assertCollectionEqualAndUsable(target, cloneWithKryo(target)); target = Collections.emptyNavigableSet(); assertCollectionEqualAndUsable(target, cloneWithKryo(target)); target = Collections.emptySortedMap(); assertCollectionEqualAndUsable(target, cloneWithKryo(target)); target = Collections.emptySortedSet(); assertCollectionEqualAndUsable(target, cloneWithKryo(target)); }