| java.lang.Object org.openide.util.NbCollections
NbCollections | public class NbCollections (Code) | | Utilities for working with generics.
Note that there is no checkedListByFilter method currently.
If constant-time operation is important (e.g. your raw list is large and
RandomAccess )
you can use
NbCollections.checkedListByCopy , assuming you do not need to modify the underlying list.
If you are only interested in an iterator anyway, try
NbCollections.checkedIteratorByFilter .
author: Jesse Glick since: org.openide.util 7.1 |
Method Summary | |
public static Enumeration<E> | checkedEnumerationByFilter(Enumeration rawEnum, Class<E> type, boolean strict) Create a typesafe filter of an unchecked enumeration. | public static Iterator<E> | checkedIteratorByFilter(Iterator rawIterator, Class<E> type, boolean strict) Create a typesafe filter of an unchecked iterator. | public static List<E> | checkedListByCopy(List rawList, Class<E> type, boolean strict) Create a typesafe copy of a raw list. | public static Map<K, V> | checkedMapByCopy(Map rawMap, Class<K> keyType, Class<V> valueType, boolean strict) Create a typesafe copy of a raw map. | public static Map<K, V> | checkedMapByFilter(Map rawMap, Class<K> keyType, Class<V> valueType, boolean strict) Create a typesafe view over an underlying raw map. | public static Set<E> | checkedSetByCopy(Set rawSet, Class<E> type, boolean strict) Create a typesafe copy of a raw set. | public static Set<E> | checkedSetByFilter(Set rawSet, Class<E> type, boolean strict) Create a typesafe view over an underlying raw set. | public static Iterable<E> | iterable(Iterator<E> iterator) Treat an
Iterator as an
Iterable so it can be used in an enhanced for-loop. | public static Iterable<E> | iterable(Enumeration<E> enumeration) Treat an
Enumeration as an
Iterable so it can be used in an enhanced for-loop. |
checkedEnumerationByFilter | public static Enumeration<E> checkedEnumerationByFilter(Enumeration rawEnum, Class<E> type, boolean strict)(Code) | | Create a typesafe filter of an unchecked enumeration.
Parameters: rawEnum - an unchecked enumeration Parameters: type - the desired enumeration type Parameters: strict - if false, elements which are not null but not assignable to the requested type are omitted;if true, ClassCastException may be thrown from an enumeration operation an enumeration guaranteed to contain only objects of the requested type (or null) |
checkedIteratorByFilter | public static Iterator<E> checkedIteratorByFilter(Iterator rawIterator, Class<E> type, boolean strict)(Code) | | Create a typesafe filter of an unchecked iterator.
Iterator.remove will work if it does in the unchecked iterator.
Parameters: rawIterator - an unchecked iterator Parameters: type - the desired enumeration type Parameters: strict - if false, elements which are not null but not assignable to the requested type are omitted;if true, ClassCastException may be thrown from an iterator operation an iterator guaranteed to contain only objects of the requested type (or null) |
checkedListByCopy | public static List<E> checkedListByCopy(List rawList, Class<E> type, boolean strict) throws ClassCastException(Code) | | Create a typesafe copy of a raw list.
Parameters: rawList - an unchecked list Parameters: type - the desired supertype of the entries Parameters: strict - true to throw a ClassCastException if the raw list has an invalid entry,false to skip over such entries (warnings may be logged) a typed list guaranteed to contain only entries assignableto the named type (or they may be null) throws: ClassCastException - if some entry in the raw list was not well-typed, and only if strict was true |
checkedMapByCopy | public static Map<K, V> checkedMapByCopy(Map rawMap, Class<K> keyType, Class<V> valueType, boolean strict) throws ClassCastException(Code) | | Create a typesafe copy of a raw map.
Parameters: rawMap - an unchecked map Parameters: keyType - the desired supertype of the keys Parameters: valueType - the desired supertype of the values Parameters: strict - true to throw a ClassCastException if the raw map has an invalid key or value,false to skip over such map entries (warnings may be logged) a typed map guaranteed to contain only keys and values assignableto the named types (or they may be null) throws: ClassCastException - if some key or value in the raw map was not well-typed, and only if strict was true |
checkedMapByFilter | public static Map<K, V> checkedMapByFilter(Map rawMap, Class<K> keyType, Class<V> valueType, boolean strict)(Code) | | Create a typesafe view over an underlying raw map.
Mutations affect the underlying map (this is not a copy).
Map.clear will make the view empty but may not clear the underlying map.
You may add entries only of the requested type pair.
Map.get ,
Map.containsKey , and
Map.containsValue also perform a type check
and will throw
ClassCastException for an illegal argument.
The view is serializable if the underlying map is.
Parameters: rawMap - an unchecked map Parameters: keyType - the desired entry key type Parameters: valueType - the desired entry value type Parameters: strict - if false, entries in the underlying map for which the key is not null but not assignableto the requested key type, and/or the value is not null but not assignable tothe requested value type, are omitted from the view;if true, a ClassCastException may arise during some map operation a view over the raw map guaranteed to match the specified type |
checkedSetByCopy | public static Set<E> checkedSetByCopy(Set rawSet, Class<E> type, boolean strict) throws ClassCastException(Code) | | Create a typesafe copy of a raw set.
Parameters: rawSet - an unchecked set Parameters: type - the desired supertype of the entries Parameters: strict - true to throw a ClassCastException if the raw set has an invalid entry,false to skip over such entries (warnings may be logged) a typed set guaranteed to contain only entries assignableto the named type (or they may be null) throws: ClassCastException - if some entry in the raw set was not well-typed, and only if strict was true |
checkedSetByFilter | public static Set<E> checkedSetByFilter(Set rawSet, Class<E> type, boolean strict)(Code) | | Create a typesafe view over an underlying raw set.
Mutations affect the underlying set (this is not a copy).
Set.clear will make the view empty but may not clear the underlying set.
You may add elements only of the requested type.
Set.contains also performs a type check and will throw
ClassCastException for an illegal argument.
The view is serializable if the underlying set is.
Parameters: rawSet - an unchecked set Parameters: type - the desired element type Parameters: strict - if false, elements in the underlying set which are not null and which are not assignableto the requested type are omitted from the view;if true, a ClassCastException may arise during some set operation a view over the raw set guaranteed to match the specified type |
iterable | public static Iterable<E> iterable(Iterator<E> iterator)(Code) | | Treat an
Iterator as an
Iterable so it can be used in an enhanced for-loop.
Bear in mind that the iterator is "consumed" by the loop and so should be used only once.
Generally it is best to put the code which obtains the iterator inside the loop header.
Example of correct usage:
String text = ...;
for (String token : NbCollections.iterable(new
java.util.Scanner (text))) {
// ...
}
Parameters: iterator - an iterator an iterable wrapper which will traverse the iterator once throws: NullPointerException - if the iterator is null See Also: Java bug #6312085 See Also: Java bug #6360734 See Also: Java bug #4988624 since: org.openide.util 7.5 |
iterable | public static Iterable<E> iterable(Enumeration<E> enumeration)(Code) | | Treat an
Enumeration as an
Iterable so it can be used in an enhanced for-loop.
Bear in mind that the enumeration is "consumed" by the loop and so should be used only once.
Generally it is best to put the code which obtains the enumeration inside the loop header.
Example of correct usage:
ClassLoader loader = ...;
String name = ...;
for (URL resource : NbCollections.iterable(loader.
ClassLoader.getResources getResources (name))) {
// ...
}
Parameters: enumeration - an enumeration an iterable wrapper which will traverse the enumeration once(Iterator.remove is not supported) throws: NullPointerException - if the enumeration is null See Also: Java bug #6349852 since: org.openide.util 7.5 |
|
|