List of usage examples for org.apache.commons.collections CollectionUtils filter
public static void filter(Collection collection, Predicate predicate)
From source file:org.isatools.isatab_v1.GelMappingTest.java
/** * Tests correct mapping of Gel Assay/*from w ww . java 2s . co m*/ */ @Test @SuppressWarnings("static-access") public void testLoadingAndMapping() throws Exception { out.println("\n\n__________ Gel Electrophoresis Mapping Test __________\n\n"); String baseDir = System.getProperty("basedir"); String filesPath = baseDir + "/target/test-classes/test-data/isatab/gel_foo"; ISATABLoader loader = new ISATABLoader(filesPath); FormatSetInstance isatabInstance = loader.load(); out.println("\n\n_____ Loaded, now mapping"); BIIObjectStore store = new BIIObjectStore(); ISATABMapper isatabMapper = new ISATABMapper(store, isatabInstance); isatabMapper.map(); assertTrue("Oh no! No mapped object! ", store.size() > 0); Study study = store.getType(Study.class, "bii:study:3"); assertNotNull("Oh no! Study bii:study:3 not found in the results!", study); Collection<AssayResult> ars = new ArrayList<AssayResult>(study.getAssayResults()); final Collection<FactorValue> fvs = new ArrayList<FactorValue>(); CollectionUtils.filter(ars, new Predicate() { public boolean evaluate(Object object) { AssayResult ar = (AssayResult) object; if ("bii:gel_normalized_data".equals(ar.getData().getType().getAcc())) { fvs.addAll(ar.getFactorValues()); return true; } return false; } }); assertEquals("Ouch! Wrong no of assay results from the gel assay file!", 24, ars.size()); assertEquals("Ouch! Wrong no of factor values from the gel assay file!", 48, fvs.size()); assertEquals("Ouch! Wrong no of unique factor values from the gel assay file!", 3, AssayResult.filterRepeatedPropertyValues(fvs).size()); out.println("\n\n__ RESULTS: __ "); out.println(store.toStringVerbose()); Collection<Identifiable> objects = new ArrayList<Identifiable>(); objects.addAll(store.values(Processing.class)); DotGraphGenerator dotter = new DotGraphGenerator(objects); String dotFileName = baseDir + "/target/gel_assay.dot"; dotter.createGraph(dotFileName); out.println("\n\nExperimental Graph written in " + dotFileName); out.println("\n\n__________ /end: Gel Electrophoresis Mapping Test __________\n\n"); }
From source file:org.isatools.isatab_v1.GenericAssayMappingTest.java
/** * Tests correct mapping of generic assay *//* w ww .j a va 2 s .c om*/ @Test @SuppressWarnings("static-access") public void testLoadingAndMapping() throws Exception { out.println("\n\n__________ Generic Case Mapping Test __________\n\n"); String baseDir = System.getProperty("basedir"); String filesPath = baseDir + "/target/test-classes/test-data/isatab/generic_assay"; ISATABLoader loader = new ISATABLoader(filesPath); FormatSetInstance isatabInstance = loader.load(); out.println("\n\n_____ Loaded, now mapping"); BIIObjectStore store = new BIIObjectStore(); ISATABMapper isatabMapper = new ISATABMapper(store, isatabInstance); isatabMapper.map(); assertTrue("Oh no! No mapped object! ", store.size() > 0); Study study = store.getType(Study.class, "bii:study:3"); assertNotNull("Oh no! Study bii:study:3 not found in the results!", study); Collection<AssayResult> ars = new ArrayList<AssayResult>(study.getAssayResults()); final Collection<FactorValue> fvs = new ArrayList<FactorValue>(); CollectionUtils.filter(ars, new Predicate() { public boolean evaluate(Object object) { AssayResult ar = (AssayResult) object; if ("bii:generic_assay_derived_data".equals(ar.getData().getType().getAcc())) { fvs.addAll(ar.getFactorValues()); return true; } return false; } }); assertEquals("Ouch! Wrong no of assay results from the generic assay file!", 12, ars.size()); assertEquals("Ouch! Wrong no of factor values from the generic assay file!", 24, fvs.size()); assertEquals("Ouch! Wrong no of unique factor values from the generic assay file!", 3, AssayResult.filterRepeatedPropertyValues(fvs).size()); out.println("\n\n__ RESULTS: __ "); out.println(store.toStringVerbose()); Collection<Identifiable> objects = new ArrayList<Identifiable>(); objects.addAll(store.values(Processing.class)); DotGraphGenerator dotter = new DotGraphGenerator(objects); String dotFileName = baseDir + "/target/generic_assay.dot"; dotter.createGraph(dotFileName); out.println("\n\nExperimental Graph written in " + dotFileName); out.println("\n\n__________ /end: Generic Case Mapping Test __________\n\n\n\n"); }
From source file:org.itracker.services.implementations.ConfigurationServiceImpl.java
public Map<String, List<String>> getAvailableLanguages() { final TreeMap<String, List<String>> languages = new TreeMap<>(); final List<Configuration> locales = getConfigurationItemsByType(Configuration.Type.locale); for (int i = 0; i < locales.size(); i++) { String baselocalestring = locales.get(i).getValue(); if (baselocalestring.length() == 2) { List<String> languageList = new ArrayList<>(); final String l = baselocalestring; languageList.addAll(CollectionUtils.collect(locales, new Transformer() { @Override//from w w w . j a v a 2 s . com public Object transform(Object input) { String val = ((Configuration) input).getValue(); if (val.length() > 2 && val.startsWith(l + "_")) { return val; } return null; } })); CollectionUtils.filter(languageList, NotNullPredicate.getInstance()); languages.put(baselocalestring, languageList); } } return languages; }
From source file:org.jahia.modules.external.modules.ModulesDataSource.java
/** * Return the children of the specified path. * * @param path path of which we want to know the children * @return the children of the specified path *///from w ww . j a v a 2 s.c om @Override public List<String> getChildren(String path) throws RepositoryException { String pathLowerCase = path.toLowerCase(); if (pathLowerCase.endsWith(CND) || pathLowerCase.contains(CND_SLASH)) { return getCndChildrenNames(path, pathLowerCase); } else { List<String> children = super.getChildren(path); if (!children.isEmpty()) { CollectionUtils.filter(children, FILTER_OUT_FILES_WITH_STARTING_DOT); } return children; } }
From source file:org.jahia.modules.external.modules.ModulesDataSource.java
/** * Return the children of the specified path. * * @param path path of which we want to know the children * @return the children of the specified path *//*w ww .ja va 2 s.c o m*/ @Override public List<ExternalData> getChildrenNodes(String path) throws RepositoryException { String pathLowerCase = path.toLowerCase(); if (pathLowerCase.endsWith(CND) || pathLowerCase.contains(CND_SLASH)) { return getCndChildren(path, pathLowerCase); } else { List<ExternalData> children = super.getChildrenNodes(path); if (!children.isEmpty()) { CollectionUtils.filter(children, FILTER_OUT_FILES_WITH_STARTING_DOT); CollectionUtils.forAllDo(children, ENHANCE); } return children; } }
From source file:org.jajuk.base.FileManager.java
/** * Gets the ready files./*from w w w . ja v a 2 s . c o m*/ * * @return All accessible files of the collection */ public List<File> getReadyFiles() { List<File> files = getFiles(); CollectionUtils.filter(files, new JajukPredicates.ReadyFilePredicate()); return files; }
From source file:org.jajuk.base.FileManager.java
/** * Return a shuffle mounted and unbaned file from the entire collection or * null if none available using these criterias. * * @return the file//from ww w.jav a 2 s . com */ public File getShuffleFile() { List<File> alEligibleFiles = getReadyFiles(); // filter banned files CollectionUtils.filter(alEligibleFiles, new JajukPredicates.BannedFilePredicate()); if (alEligibleFiles.size() > 0) { int index = UtilSystem.getRandom().nextInt(alEligibleFiles.size() - 1); return alEligibleFiles.get(index); } else { return null; } }
From source file:org.jajuk.base.FileManager.java
/** * Return an ordered playlist with the entire accessible shuffle collection. * * @return The entire accessible shuffle collection (can return a void * collection)/*from w w w . j a va2 s. co m*/ */ public List<File> getGlobalShufflePlaylist() { List<File> alEligibleFiles = getReadyFiles(); // filter banned files CollectionUtils.filter(alEligibleFiles, new JajukPredicates.BannedFilePredicate()); // We filter recently played tracks to improve the quality of the randomness filterRecentlyPlayedTracks(alEligibleFiles); // shuffle Collections.shuffle(alEligibleFiles, UtilSystem.getRandom()); // song level, just shuffle full collection if (Conf.getString(Const.CONF_GLOBAL_RANDOM_MODE).equals(Const.MODE_TRACK)) { return alEligibleFiles; } // (not shuffle) Album / album else if (Conf.getString(Const.CONF_GLOBAL_RANDOM_MODE).equals(Const.MODE_ALBUM2)) { final List<Album> albums = AlbumManager.getInstance().getAlbums(); Collections.shuffle(albums, UtilSystem.getRandom()); // We need an index (bench: 45* faster) final Map<Album, Integer> index = new HashMap<Album, Integer>(); for (Album album : albums) { index.put(album, albums.indexOf(album)); } Collections.sort(alEligibleFiles, new Comparator<File>() { @Override public int compare(File f1, File f2) { if (f1.getTrack().getAlbum().equals(f2.getTrack().getAlbum())) { int comp = (int) (f1.getTrack().getOrder() - f2.getTrack().getOrder()); if (comp == 0) { // If no track number is given, try to sort by // filename than can contain the track return f1.getName().compareTo(f2.getName()); } return comp; } return index.get(f1.getTrack().getAlbum()) - index.get(f2.getTrack().getAlbum()); } }); return alEligibleFiles; // else return shuffle albums } else { return getShuffledFilesByAlbum(alEligibleFiles); } }
From source file:org.jajuk.base.FileManager.java
/** * Return an ordered playlist with the accessible novelties collection The * number of returned items is limited to NB_TRACKS_ON_ACTION for performance * reasons.//from ww w. ja v a2 s . co m * * @param bHideUnmounted * * @return The entire accessible novelties collection */ List<File> getGlobalNoveltiesPlaylist(boolean bHideUnmounted) { List<File> alEligibleFiles = new ArrayList<File>(1000); List<Track> tracks = TrackManager.getInstance().getTracks(); // Filter by age CollectionUtils.filter(tracks, new JajukPredicates.AgePredicate(Conf.getInt(Const.CONF_OPTIONS_NOVELTIES_AGE))); // filter banned tracks CollectionUtils.filter(tracks, new JajukPredicates.BannedTrackPredicate()); for (Track track : tracks) { if (alEligibleFiles.size() > Const.NB_TRACKS_ON_ACTION) { break; } File file = track.getBestFile(bHideUnmounted); // try to get a mounted file // (can return null) if (file == null) {// none mounted file, take first file we find continue; } alEligibleFiles.add(file); } // sort alphabetically and by date, newest first Collections.sort(alEligibleFiles, new Comparator<File>() { @Override public int compare(File file1, File file2) { String sCompared1 = file1.getTrack().getDiscoveryDate().getTime() + file1.getAbsolutePath(); String sCompared2 = file2.getTrack().getDiscoveryDate().getTime() + file2.getAbsolutePath(); return sCompared2.compareTo(sCompared1); } }); return alEligibleFiles; }
From source file:org.jajuk.base.FileManager.java
/** * Return a shuffled playlist with the entire accessible bestof collection, * best first./* w w w . j av a 2 s . c om*/ * * @return Shuffled best tracks (n% of favorite) */ public List<File> getGlobalBestofPlaylist() { List<File> al = getSortedByRate(); // Filter banned files CollectionUtils.filter(al, new JajukPredicates.BannedFilePredicate()); List<File> alBest = null; if (al.size() > 0) { // find superior interval value int sup = (int) ((Const.BESTOF_PROPORTION) * al.size()); if (sup < 2) { sup = al.size(); } alBest = al.subList(0, sup - 1); Collections.shuffle(alBest, UtilSystem.getRandom()); } return alBest; }