// <editor-fold defaultstate="collapsed" desc="named()"> public FunctionSetHelper named(final String name) { if (name == null) throw new IllegalArgumentException("name==null"); if (mem == null) return new FunctionSetHelper(Iterators.<Function>empty()); Object o = mem.get(name); if (o instanceof Function) { FunctionSetHelper fs = new FunctionSetHelper(Iterators.<Function>single((Function) o)); fs.mem = mem; return fs; } if (o instanceof FunctionSet) { FunctionSetHelper fs = new FunctionSetHelper(((FunctionSet) o).getFunctions()); fs.mem = mem; return fs; } return new FunctionSetHelper(Iterators.<Function>empty()); }
// <editor-fold defaultstate="collapsed" desc="export"> protected void zip( ByteArrayOutputStream zipDataFile, File directoryRoot, boolean includeRoot, String fileNameSplitter) throws IOException { ZipOutputStream zip = new ZipOutputStream(zipDataFile); for (TreeWalk<File> twf : FileUtil.Iterators.walkTW(directoryRoot)) { File f = twf.currentNode(); if (!f.isFile()) continue; List<File> path = Iterators.asList(twf.nodePath()); if (!includeRoot && path.size() == 1) { continue; } ArrayList<String> name = new ArrayList<String>(); int fpi = -1; for (File fp : path) { fpi++; if (fpi == 0) { if (!includeRoot) continue; } name.add(fp.getName()); } ZipEntry ze = new ZipEntry(Text.join(name, fileNameSplitter)); zip.putNextEntry(ze); FileInputStream fin = new FileInputStream(f); FileUtil.copyAllData(fin, zip); fin.close(); zip.closeEntry(); } zip.finish(); zip.close(); }
// <editor-fold defaultstate="collapsed" desc="count()"> public int count() { Iterable<Function> itrf = functions(); long c = Iterators.count(itrf); return new Long(c).intValue(); }
// <editor-fold defaultstate="collapsed" desc="filter"> public Iterable<Function> filter(Iterable<Function> src, Predicate<Function> f) { if (src == null) throw new IllegalArgumentException("src==null"); if (f == null) throw new IllegalArgumentException("f==null"); return Iterators.predicate(src, f); }
// <editor-fold defaultstate="collapsed" desc="functions()"> public Iterable<Function> functions() { if (fset != null) return fset.getFunctions(); if (funitr != null) return funitr; return Iterators.empty(); }