/** * Filters the input enumeration to new one that should contain * each of the provided elements just once. * The elements are compared * using their default <code>equals</code> and <code>hashCode</code> methods. * * @param en enumeration to filter * @return enumeration without duplicated items */ public static <T> Enumeration<T> removeDuplicates(Enumeration<T> en) { class RDupls implements Processor<T,T> { private Set<T> set = new HashSet<T>(); public T process(T o, Collection<T> nothing) { return set.add(o) ? o : null; } } return filter(en, new RDupls()); }
/** * Create a typesafe filter of an unchecked enumeration. * @param rawEnum an unchecked enumeration * @param type the desired enumeration type * @param strict if false, elements which are not null but not assignable to the requested type are omitted; * if true, {@link ClassCastException} may be thrown from an enumeration operation * @return an enumeration guaranteed to contain only objects of the requested type (or null) */ public static <E> Enumeration<E> checkedEnumerationByFilter(Enumeration rawEnum, final Class<E> type, final boolean strict) { @SuppressWarnings("unchecked") Enumeration<Object> _rawEnum = rawEnum; return Enumerations.<Object,E>filter(_rawEnum, new Enumerations.Processor<Object,E>() { public E process(Object o, Collection<Object> ignore) { if (o == null) { return null; } else { try { return type.cast(o); } catch (ClassCastException x) { if (strict) { throw x; } else { return null; } } } } }); }
/** Get all available services that are assignable to the given superclass. * @param clazz the class that all services should be subclass of * @return an enumeration of all matching {@link ServiceType}s */ public <T extends ServiceType> Enumeration<T> services(final Class<T> clazz) { class IsInstance implements Enumerations.Processor<ServiceType,T> { public T process(ServiceType obj, Collection ignore) { return clazz.isInstance(obj) ? clazz.cast(obj) : null; } } return Enumerations.filter(services(), new IsInstance()); }
/** * Removes all <code>null</code>s from the input enumeration. * @param en enumeration that can contain nulls * @return new enumeration without null values */ public static <T> Enumeration<T> removeNulls(Enumeration<T> en) { return filter(en, new RNulls<T>()); }
/** Computes a list of FileObjects in the right order * that can represent this instance. * * @param name of resource to find * @return enumeration of FileObject */ Enumeration<FileObject> delegates(final String name) { Enumeration<FileSystem> en = Enumerations.array(systems); // XXX order (stably) by weight class Resources implements Enumerations.Processor<FileSystem, FileObject> { public @Override FileObject process(FileSystem fs, Collection<FileSystem> ignore) { if (fs == null) { return null; } else { return findResourceOn(fs, name); } } } return Enumerations.filter(en, new Resources()); }
/** Finds all hidden files on given filesystem. The methods scans all files for * ones with hidden extension and returns enumeration of names of files * that are hidden. * * @param folder folder to start at * @param rec proceed recursivelly * @return enumeration of String with names of hidden files */ protected static Enumeration<String> hiddenFiles(FileObject folder, boolean rec) { Enumeration<? extends FileObject> allFiles = folder.getChildren(rec); class OnlyHidden implements Enumerations.Processor<FileObject, String> { public @Override String process(FileObject obj, Collection<FileObject> ignore) { String sf = obj.getPath(); if (sf.endsWith(MASK)) { return sf.substring(0, sf.length() - MASK.length()); } else { return null; } } } return Enumerations.filter(allFiles, new OnlyHidden()); }
/** All filesystems that are capable of this capability. * @return enumeration of FileSystems that satifies this capability * @deprecated Please use the <a href="@org-netbeans-api-java-classpath@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead. */ @Deprecated public Enumeration<? extends FileSystem> fileSystems() { class FFS implements org.openide.util.Enumerations.Processor<FileSystem, FileSystem> { @Deprecated public FileSystem process(FileSystem fs, Collection<FileSystem> ignore) { return fs.getCapability().capableOf(FileSystemCapability.this) ? fs : null; } } return org.openide.util.Enumerations.filter(Repository.getDefault().fileSystems(), new FFS()); }
/** Enumerate the subfolders of this folder. * @param rec whether to recursively list subfolders * @return enumeration of type <code>FileObject</code> (satisfying {@link #isFolder}) */ public Enumeration<? extends FileObject> getFolders(boolean rec) { return Enumerations.filter(getChildren(rec), new OnlyFolders(true)); }
/** Enumerate all data files in this folder. * @param rec whether to recursively search subfolders * @return enumeration of type <code>FileObject</code> (satisfying {@link #isData}) */ public Enumeration<? extends FileObject> getData(boolean rec) { return Enumerations.filter(getChildren(rec), new OnlyFolders(false)); }
/** Get all available services that are assignable to the given superclass. * @param clazz the class that all services should be subclass of * @return an enumeration of all matching {@link ServiceType}s */ public <T extends ServiceType> Enumeration<T> services(final Class<T> clazz) { class IsInstance implements Enumerations.Processor<ServiceType,T> { public T process(ServiceType obj, Collection ignore) { return clazz.isInstance(obj) ? clazz.cast(obj) : null; } } return Enumerations.filter(services(), new IsInstance()); }
/** Get all available services that are assignable to the given superclass. * @param clazz the class that all services should be subclass of * @return an enumeration of all matching {@link ServiceType}s */ public <T extends ServiceType> Enumeration<T> services(final Class<T> clazz) { class IsInstance implements Enumerations.Processor<ServiceType,T> { public T process(ServiceType obj, Collection ignore) { return clazz.isInstance(obj) ? clazz.cast(obj) : null; } } return Enumerations.filter(services(), new IsInstance()); }
/** Get all available services that are assignable to the given superclass. * @param clazz the class that all services should be subclass of * @return an enumeration of all matching {@link ServiceType}s */ public <T extends ServiceType> Enumeration<T> services(final Class<T> clazz) { class IsInstance implements Enumerations.Processor<ServiceType,T> { public T process(ServiceType obj, Collection ignore) { return clazz.isInstance(obj) ? clazz.cast(obj) : null; } } return Enumerations.filter(services(), new IsInstance()); }
/** * Removes all <code>null</code>s from the input enumeration. * @param en enumeration that can contain nulls * @return new enumeration without null values */ public static Enumeration removeNulls (Enumeration en) { return filter (en, new RNulls()); }
/** * Removes all <code>null</code>s from the input enumeration. * @param en enumeration that can contain nulls * @return new enumeration without null values */ public static <T> Enumeration<T> removeNulls(Enumeration<T> en) { return filter(en, new RNulls<T>()); }
/** * Removes all <code>null</code>s from the input enumeration. * @param en enumeration that can contain nulls * @return new enumeration without null values */ public static <T> Enumeration<T> removeNulls(Enumeration<T> en) { return filter(en, new RNulls<T>()); }
/** Get all available services that are assignable to the given superclass. * @param clazz the class that all services should be subclass of * @return an enumeration of all matching {@link ServiceType}s */ public Enumeration services (final Class clazz) { class IsInstance implements org.openide.util.Enumerations.Processor { public Object process (Object obj, java.util.Collection ignore) { return clazz.isInstance (obj) ? obj : null; } } return org.openide.util.Enumerations.filter (services (), new IsInstance ()); }
/** Get all available services that are assignable to the given superclass. * @param clazz the class that all services should be subclass of * @return an enumeration of all matching {@link ServiceType}s */ public Enumeration services (final Class clazz) { class IsInstance implements org.openide.util.Enumerations.Processor { public Object process (Object obj, java.util.Collection ignore) { return clazz.isInstance (obj) ? obj : null; } } return org.openide.util.Enumerations.filter (services (), new IsInstance ()); }
/** Enumerate the subfolders of this folder. * @param rec whether to recursively list subfolders * @return enumeration of type <code>FileObject</code> (satisfying {@link #isFolder}) */ public Enumeration getFolders (boolean rec) { return Enumerations.filter( getChildren (rec), new OnlyFolders (true) ); }
/** Enumerate all data files in this folder. * @param rec whether to recursively search subfolders * @return enumeration of type <code>FileObject</code> (satisfying {@link #isData}) */ public Enumeration getData (boolean rec) { return Enumerations.filter( getChildren (rec), new OnlyFolders (false) ); }
/** Enumerate the subfolders of this folder. * @param rec whether to recursively list subfolders * @return enumeration of type <code>FileObject</code> (satisfying {@link #isFolder}) */ public Enumeration getFolders (boolean rec) { return Enumerations.filter( getChildren (rec), new OnlyFolders (true) ); }