Java Code Examples for org.openide.util.Enumerations#filter()
The following examples show how to use
org.openide.util.Enumerations#filter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiFileSystem.java From netbeans with Apache License 2.0 | 6 votes |
/** 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()); }
Example 2
Source File: MultiFileSystem.java From netbeans with Apache License 2.0 | 6 votes |
/** 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()); }
Example 3
Source File: NbCollections.java From netbeans with Apache License 2.0 | 6 votes |
/** * 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<?> _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; } } } } }); }
Example 4
Source File: ServiceType.java From netbeans with Apache License 2.0 | 5 votes |
/** 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()); }
Example 5
Source File: FileObjectArchive.java From netbeans with Apache License 2.0 | 4 votes |
@NonNull @Override public Iterable<JavaFileObject> getFiles( @NonNull final String folderName, @NullAllowed final ClassPath.Entry entry, @NullAllowed final Set<JavaFileObject.Kind> kinds, @NullAllowed final JavaFileFilterImplementation filter, final boolean recursive) throws IOException { final FileObject folder = root.getFileObject(folderName); if (folder == null || !(entry == null || entry.includes(folder))) { return Collections.<JavaFileObject>emptySet(); } final Enumeration<? extends FileObject> children; final List<JavaFileObject> result; if (recursive) { children = Enumerations.filter( folder.getChildren(recursive), (p,x)->{ return !p.isFolder() && isInJavaPackage(folder,p) ? p : null; }); result = new ArrayList<>(/*unknown size*/); } else { final FileObject[] chlds = folder.getChildren(); children = Enumerations.array(chlds); result = new ArrayList<>(chlds.length); } while (children.hasMoreElements()) { final FileObject fo = children.nextElement(); if (fo.isData() && (entry == null || entry.includes(fo))) { final Kind kind = FileObjects.getKind(fo.getExt()); if (kinds == null || kinds.contains (kind)) { JavaFileObject file; if (kind == Kind.CLASS) { file = FileObjects.fileObjectFileObject(fo, root, filter, null); } else { file = FileObjects.sourceFileObject(fo, root, filter,false); } result.add(file); } } } return result; }
Example 6
Source File: I18nPanel.java From netbeans with Apache License 2.0 | 4 votes |
public void setDefaultResource(DataObject dataObject) { if (dataObject != null) { // look for peer Bundle.properties FileObject fo = dataObject.getPrimaryFile(); ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE); if (cp != null) { FileObject folder = cp.findResource(cp.getResourceName(fo.getParent())); while (folder != null && cp.contains(folder)) { String rn = cp.getResourceName(folder) + "/Bundle.properties"; // NOI18N FileObject peer = cp.findResource(rn); if (peer == null) { //Try to find any properties file Enumeration<? extends FileObject> data = Enumerations.filter(folder.getData(false), new Enumerations.Processor(){ public Object process(Object obj, Collection alwaysNull) { if (obj instanceof FileObject && "properties".equals( ((FileObject)obj).getExt())){ //NOI18N return obj; } else { return null; } } }); if (data.hasMoreElements()) { peer = data.nextElement(); } } if (peer != null) { try { DataObject peerDataObject = DataObject.find(peer); // ((ResourcePanel)resourcePanel).setResource(peerDataObject); propertyPanel.setResource(peerDataObject); return; } catch (IOException ex) { // no default resource } } folder = folder.getParent(); } } } }
Example 7
Source File: FileObject.java From netbeans with Apache License 2.0 | 2 votes |
/** 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)); }
Example 8
Source File: FileObject.java From netbeans with Apache License 2.0 | 2 votes |
/** 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)); }