本文整理匯總了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));
}
}