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