List of usage examples for org.apache.commons.collections CollectionUtils select
public static Collection select(Collection inputCollection, Predicate predicate)
From source file:tds.student.services.AccommodationsService.java
private List<Accommodations> getTestSegments(TestProperties testProps, boolean isGuestSession) throws ReturnStatusException { long startTime = System.currentTimeMillis(); List<Accommodations> accommodationsList = new ArrayList<Accommodations>(); // FW Performance - changed from _ibRepository to ItemBankService to utilize caching AccList accList = itemBankService.getTestAccommodations(testProps.getTestKey()); // if this is PT then remove all acc's that are disabled for guest sessions try {// w w w. j av a 2s . com if (isGuestSession) { accList.getData().removeAll(CollectionUtils.select(accList.getData(), object -> ((Data) object).isDisableOnGuestSession())); } // first create the test accommodations Accommodations testAccs = null; testAccs = accList.createAccommodations(0, testProps.getTestID(), testProps.getDisplayName()); accommodationsList.add(testAccs); // then create the segments accommodations for (TestSegment testSegment : testProps.getSegments()) { Accommodations segmentAccs = null; try { segmentAccs = accList.createAccommodations(testSegment.getPosition(), testSegment.getId(), testSegment.getLabel()); } catch (ReadOnlyException e) { e.printStackTrace(); } accommodationsList.add(segmentAccs); } } catch (ReadOnlyException e1) { _logger.error(e1.getMessage()); throw new ReturnStatusException(e1); } return accommodationsList; }
From source file:ubic.gemma.web.controller.expression.experiment.ExpressionExperimentSetController.java
/** * @param limit to return only up to a given number of experiments, e.g. for a preview of the set. */// w w w .ja v a 2 s .c o m public Collection<ExpressionExperimentDetailsValueObject> getExperimentsInSet(Long groupId, final Integer limit) { Collection<ExpressionExperimentDetailsValueObject> experimentInSet = expressionExperimentSetService .getExperimentValueObjectsInSet(groupId); if (limit != null && limit > 0 && limit < experimentInSet.size()) { //noinspection unchecked return CollectionUtils.select(experimentInSet, new Predicate() { int i = 0; @Override public boolean evaluate(Object object) { return i++ < limit; } }); } return experimentInSet; }
From source file:ubic.gemma.web.controller.genome.gene.GeneSetController.java
/** * AJAX If the current user has access to given gene group, will return the gene value objects in the gene group * * @param groupId group id//from ww w.j a va 2s .c o m * @param limit if greater than zero, limit to how many genes are returned (for previews) * @return gene vos */ public Collection<GeneValueObject> getGenesInGroup(Long groupId, final Integer limit) { if (groupId == null || groupId < 0) throw new IllegalArgumentException("Must be a persistent gene group"); // FIXME inefficient way to implement the limit Collection<GeneValueObject> genesInGroup = geneSetService.getGenesInGroup(new GeneSetValueObject(groupId)); if (limit != null && limit > 0 && limit < genesInGroup.size()) { return CollectionUtils.select(genesInGroup, new Predicate() { int i = 0; @Override public boolean evaluate(Object object) { return i++ < limit; } }); } return genesInGroup; }
From source file:uk.ac.ebi.bioinvindex.model.HasReferences.java
/** * @return the xrefs having a source with a given accession. An empty list if none available. *///w ww . j a v a2s . c o m @SuppressWarnings("unchecked") public List<Xref> getXrefs(final String sourceAcc) { return (List<Xref>) CollectionUtils.select(refs, new Predicate() { public boolean evaluate(Object xref) { ReferenceSource source = ((Xref) xref).getSource(); if (source == null) return false; if (sourceAcc == null) return source.getAcc() == null; return sourceAcc.equals(source.getAcc()); } }); }
From source file:uk.ac.ebi.bioinvindex.model.HasReferences.java
/** * It's like {@link #getXrefs(String)}, but uses a containment criterion * /*w ww .j a v a 2 s . co m*/ */ @SuppressWarnings("unchecked") public List<Xref> getXrefsContaining(final String sourceAcc) { return (List<Xref>) CollectionUtils.select(refs, new Predicate() { public boolean evaluate(Object xref) { ReferenceSource source = ((Xref) xref).getSource(); if (source == null) return false; if (sourceAcc == null) return source.getAcc() == null; return StringUtils.containsIgnoreCase(source.getAcc(), sourceAcc); } }); }