本文整理汇总了Java中java.util.Collections.unmodifiableNavigableSet方法的典型用法代码示例。如果您正苦于以下问题:Java Collections.unmodifiableNavigableSet方法的具体用法?Java Collections.unmodifiableNavigableSet怎么用?Java Collections.unmodifiableNavigableSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Collections
的用法示例。
在下文中一共展示了Collections.unmodifiableNavigableSet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ParameterBinderWithCollectionSupport
import java.util.Collections; //导入方法依赖的package包/类
ParameterBinderWithCollectionSupport(Set<Integer> templateSizes, Function<Object, Collection<?>> collectionFunction,
Function<Collection<?>, ?> fillerFunction) {
this.templateSizes = Collections.unmodifiableNavigableSet(requireNonNull(templateSizes, "templateSizes is null")
.stream().filter(s -> s != null && s > 0).collect(Collectors.toCollection(TreeSet::new)));
this.collectionFunction = requireNonNull(collectionFunction);
this.fillerFunction = requireNonNull(fillerFunction);
if (this.templateSizes.isEmpty()) {
throw new IllegalArgumentException("Template sizes has to contain at least one positive integer!");
}
}
示例2: 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);
}