本文整理汇总了Java中java.util.Collections.unmodifiableNavigableMap方法的典型用法代码示例。如果您正苦于以下问题:Java Collections.unmodifiableNavigableMap方法的具体用法?Java Collections.unmodifiableNavigableMap怎么用?Java Collections.unmodifiableNavigableMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Collections
的用法示例。
在下文中一共展示了Collections.unmodifiableNavigableMap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeUnmodifiable
import java.util.Collections; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes", "SuspiciousSystemArraycopy"})
@Nullable
public static <T> T makeUnmodifiable(Object collection)
{
if (collection.getClass().isArray())
{
int length = Array.getLength(collection);
if (length == 0)
{
return (T) DioriteArrayUtils.getEmptyObjectArray(collection.getClass().getComponentType());
}
Object copy = DioriteArrayUtils.newArray(collection.getClass().getComponentType(), length);
System.arraycopy(collection, 0, copy, 0, length);
return (T) copy;
}
Function function = unmodifiableWrappers.get(collection.getClass());
if (function == null)
{
for (Entry<Class<?>, Function<?, ?>> entry : unmodifiableWrappers.entrySet())
{
if (entry.getKey().isInstance(collection))
{
function = entry.getValue();
break;
}
}
if (function != null)
{
unmodifiableWrappers.put(collection.getClass(), function);
return (T) function.apply(collection);
}
if (collection instanceof Collection)
{
if (collection instanceof Set)
{
if (collection instanceof NavigableSet)
{
return (T) Collections.unmodifiableNavigableSet((NavigableSet<?>) collection);
}
if (collection instanceof SortedSet)
{
return (T) Collections.unmodifiableSortedSet((SortedSet<?>) collection);
}
return (T) Collections.unmodifiableSet((Set<?>) collection);
}
if (collection instanceof List)
{
return (T) Collections.unmodifiableList((List<?>) collection);
}
return (T) Collections.unmodifiableCollection((Collection<?>) collection);
}
else if (collection instanceof Map)
{
if (collection instanceof NavigableMap)
{
return (T) Collections.unmodifiableNavigableMap((NavigableMap<?, ?>) collection);
}
if (collection instanceof SortedMap)
{
return (T) Collections.unmodifiableSortedMap((SortedMap<?, ?>) collection);
}
return (T) Collections.unmodifiableMap((Map<?, ?>) collection);
}
else
{
new RuntimeException("Can't make this collection unmodifiable: " + collection.getClass().getName()).printStackTrace();
return (T) collection;
}
}
return (T) function.apply(collection);
}
示例2: convert
import java.util.Collections; //导入方法依赖的package包/类
@VisibleForTesting
NavigableMap<BigDecimal, BigDecimal> convert(BigDecimal[][] quotes, Comparator<BigDecimal> c) {
NavigableMap<BigDecimal, BigDecimal> map = new TreeMap<>(c);
if (ArrayUtils.isNotEmpty(quotes)) {
for (BigDecimal[] quote : quotes) {
if (quote.length != 2) {
continue;
}
if (quote[0] == null || quote[0].signum() == 0) {
continue;
}
if (quote[1] == null || quote[1].signum() == 0) {
continue;
}
map.put(quote[0], quote[1]);
}
}
return Collections.unmodifiableNavigableMap(map);
}