List of usage examples for com.google.common.collect Iterables filter
@GwtIncompatible("Class.isInstance") @CheckReturnValue public static <T> Iterable<T> filter(final Iterable<?> unfiltered, final Class<T> desiredType)
From source file:com.pets.core.petstore.domain.mappers.PetModelMapper.java
public static PetModel transform(Pet pet) { if (pet == null) { return null; }//from w w w . ja va 2 s . c o m PetModel petModel = new PetModel(pet.getId()); petModel.setName(pet.getName()).setStatus(pet.getStatus() == null ? null : pet.getStatus().toString()) .setCategoryName(pet.getCategory() == null ? null : pet.getCategory().getName()); List<Tag> tags = pet.getTags(); if (tags != null) { final List<String> tagNames = Lists .newArrayList(Iterables.transform(pet.getTags(), new Function<Tag, String>() { @Override public String apply(final Tag tag) { return tag.getName(); } })); petModel.setTagNames(tagNames); } // Do some business logic (that should have been on the server side) // and filter out non-valid photo URLs List<String> urls = pet.getPhotoUrls(); if (urls != null) { final List<String> photoUrls = Lists.newArrayList(Iterables.filter(urls, new Predicate<String>() { @Override public boolean apply(String url) { return url.startsWith("http://") || url.startsWith("https://"); } })); petModel.setPhotoUrls(photoUrls); } return petModel; }
From source file:playground.michalm.poznan.demand.taxi.PoznanServedRequests.java
public static Iterable<ServedRequest> filterRequestsWithinAgglomeration(Iterable<ServedRequest> requests) { MultiPolygon area = PoznanZones.readAgglomerationArea(); return Iterables.filter(requests, ServedRequests.createWithinAreaPredicate(area)); }
From source file:ru.org.linux.site.tags.BoxListTag.java
@Override public int doStartTag() throws JspException { Template t = Template.getTemplate(pageContext.getRequest()); List<String> boxnames = ImmutableList .copyOf(Iterables.filter(t.getProf().getBoxlets(), DefaultProfile.boxPredicate())); pageContext.setAttribute(var, boxnames); return EVAL_BODY_INCLUDE; }
From source file:org.gradle.api.internal.artifacts.resolution.DefaultJvmLibrary.java
public Iterable<JvmLibrarySourcesArtifact> getSourcesArtifacts() { return Iterables.filter(getAllArtifacts(), JvmLibrarySourcesArtifact.class); }
From source file:io.druid.timeline.UnionTimeLineLookup.java
public UnionTimeLineLookup(Iterable<TimelineLookup<VersionType, ObjectType>> delegates) { // delegate can be null in case there is no segment loaded for the dataSource on this node this.delegates = Iterables.filter(delegates, Predicates.notNull()); }
From source file:brooklyn.rest.transform.SensorTransformer.java
public static SensorSummary sensorSummary(Entity entity, Sensor<?> sensor) { String applicationUri = "/v1/applications/" + entity.getApplicationId(); String entityUri = applicationUri + "/entities/" + entity.getId(); String selfUri = entityUri + "/sensors/" + URLParamEncoder.encode(sensor.getName()); MutableMap.Builder<String, URI> lb = MutableMap.<String, URI>builder().put("self", URI.create(selfUri)) .put("application", URI.create(applicationUri)).put("entity", URI.create(entityUri)) .put("action:json", URI.create(selfUri)); if (sensor instanceof AttributeSensor) { Iterable<RendererHints.NamedAction> hints = Iterables.filter( RendererHints.getHintsFor((AttributeSensor<?>) sensor), RendererHints.NamedAction.class); for (RendererHints.NamedAction na : hints) addNamedAction(lb, na, entity, sensor); }/*www . j av a2 s. c om*/ return new SensorSummary(sensor.getName(), sensor.getTypeName(), sensor.getDescription(), lb.build()); }
From source file:org.zalando.github.spring.pagination.LinkRelationExtractor.java
public Optional<LinkRelation> extractLinkRelation(String linkHeaderValue, String relation) { Iterable<String> splittedHeaderIterable = splitter.split(linkHeaderValue); Iterable<LinkRelation> linkRelations = Iterables.transform(splittedHeaderIterable, transformer); linkRelations = Iterables.filter(linkRelations, new RelationsPredicate(relation)); return Optional.fromNullable(Iterables.getFirst(linkRelations, null)); }
From source file:org.caleydo.vis.lineup.ui.RankTableKeyListener.java
@Override public void keyPressed(IKeyEvent e) { if (e.isKey(ESpecialKey.DOWN)) table.selectNextRow();//from w w w.j a va 2 s. co m else if (e.isKey(ESpecialKey.UP)) table.selectPreviousRow(); else if (e.isControlDown() && (e.isKey(TOGGLE_ALIGN_ALL))) { // short cut for align all for (StackedRankColumnModel stacked : Iterables.filter(table.getColumns(), StackedRankColumnModel.class)) { stacked.switchToNextAlignment(); } } else if (body != null) { if (e.isKey(ESpecialKey.PAGE_UP)) { body.scroll(-15); } else if (e.isKey(ESpecialKey.PAGE_DOWN)) { body.scroll(15); } else if (e.isKey(ESpecialKey.HOME)) { body.scrollFirst(); } else if (e.isKey(ESpecialKey.END)) { body.scrollLast(); } } }
From source file:org.sonar.api.batch.fs.internal.AbstractFilePredicate.java
@Override public Iterable<InputFile> filter(Iterable<InputFile> target) { return Iterables.filter(target, this::apply); }
From source file:uk.ac.stfc.isis.ibex.instrument.list.InstrumentListUtils.java
/** * Given an observable for a list of instruments, filter out invalid * instruments.//from ww w. ja v a 2s.co m * * @param instruments instruments to filter * @param logger a logger to log information and warnings about invalid * instruments * * @return the valid instruments extracted from the input observable */ public static Collection<InstrumentInfo> filterValidInstruments(Collection<InstrumentInfo> instruments, Logger logger) { if (instruments == null) { logger.warn("Error while parsing instrument list PV - no instrument could be read"); return new ArrayList<>(); } Iterable<InstrumentInfo> validInstruments = Iterables.filter(instruments, new Predicate<InstrumentInfo>() { @Override public boolean apply(InstrumentInfo item) { return item.name() != null; } }); Collection<InstrumentInfo> returnValue = Lists.newArrayList(validInstruments); if (returnValue.size() < instruments.size()) { logger.warn("Error while parsing instrument list PV - one or more instruments could not be read"); } else { logger.info("Instrument list PV was read successfully"); } return returnValue; }