Java Code Examples for java.util.Collections.emptySortedMap()

The following are Jave code examples for showing how to use emptySortedMap() of the java.util.Collections class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: microbean-helm   File: ChartRepository.java   View Source Code Vote up 6 votes
/**
 * Performs a deep copy of the supplied {@link Map} such that the
 * {@link SortedMap} returned has copies of the supplied {@link
 * Map}'s {@linkplain Map#values() values}.
 *
 * <p>This method may return {@code null} if {@code source} is
 * {@code null}.</p>
 *
 * <p>The {@link SortedMap} returned by this method is
 * mutable.</p>
 *
 * @param source the {@link Map} to copy; may be {@code null} in
 * which case {@code null} will be returned
 *
 * @return a mutable {@link SortedMap}, or {@code null}
 */
private static final SortedMap<String, SortedSet<Entry>> deepCopy(final Map<? extends String, ? extends SortedSet<Entry>> source) {
  final SortedMap<String, SortedSet<Entry>> returnValue;
  if (source == null) {
    returnValue = null;
  } else if (source.isEmpty()) {
    returnValue = Collections.emptySortedMap();
  } else {
    returnValue = new TreeMap<>();
    final Collection<? extends Map.Entry<? extends String, ? extends SortedSet<Entry>>> entrySet = source.entrySet();
    if (entrySet != null && !entrySet.isEmpty()) {
      for (final Map.Entry<? extends String, ? extends SortedSet<Entry>> entry : entrySet) {
        final String key = entry.getKey();
        final SortedSet<Entry> value = entry.getValue();
        if (value == null) {
          returnValue.put(key, null);
        } else {
          final SortedSet<Entry> newValue = new TreeSet<>(value.comparator());
          newValue.addAll(value);
          returnValue.put(key, newValue);
        }
      }
    }
  }
  return returnValue;
}
 
Example 2
Project: microbean-helm   File: ChartRepository.java   View Source Code Vote up 5 votes
/**
 * Creates a new {@link Index}.
 *
 * @param entries a {@link Map} of {@link SortedSet}s of {@link
 * Entry} objects indexed by the name of the Helm chart they
 * describe; may be {@code null}; copied by value
 */
Index(final Map<? extends String, ? extends SortedSet<Entry>> entries) {
  super();
  if (entries == null || entries.isEmpty()) {
    this.entries = Collections.emptySortedMap();
  } else {
    this.entries = Collections.unmodifiableSortedMap(deepCopy(entries));
  }
}