本文整理汇总了Java中java.util.Collections.emptySortedMap方法的典型用法代码示例。如果您正苦于以下问题:Java Collections.emptySortedMap方法的具体用法?Java Collections.emptySortedMap怎么用?Java Collections.emptySortedMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Collections
的用法示例。
在下文中一共展示了Collections.emptySortedMap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deepCopy
import java.util.Collections; //导入方法依赖的package包/类
/**
* 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;
}
示例2: Index
import java.util.Collections; //导入方法依赖的package包/类
/**
* 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));
}
}