Example usage for com.google.common.collect Iterables transform

List of usage examples for com.google.common.collect Iterables transform

Introduction

In this page you can find the example usage for com.google.common.collect Iterables transform.

Prototype

@CheckReturnValue
public static <F, T> Iterable<T> transform(final Iterable<F> fromIterable,
        final Function<? super F, ? extends T> function) 

Source Link

Document

Returns an iterable that applies function to each element of fromIterable .

Usage

From source file:org.axdt.avm.scoping.AvmPropertyScope.java

@Override
protected Iterable<IEObjectDescription> getCandidates() {
    AvmTypeAccess access = getQualifierType();
    if (access == null)
        return Collections.emptySet();
    Iterable<IEObjectDescription> dynDesc = null;
    if (access instanceof AvmTypeAccess.Builder) {
        AvmPackage pack = ((AvmTypeAccess.Builder) access).getPackage();
        if (pack instanceof AvmContainerPackage) {
            return ((AvmContainerPackage) pack).getChildren();
        }//from  ww  w  .  j a va  2s .com
        return Iterables.transform(Iterables.filter(pack.eContents(), AvmReferable.class), GetDesciption);
    } else if (access != AvmTypeAccess.NULL) {
        AvmType type = access.getType();
        type = resolveType(type, null);
        if (type.isDynamic()) {
            AvmReferable dynIdent = getDynamicIdentifiable(getReference());
            if (dynIdent != null)
                dynDesc = Collections.singleton(GetDesciption.apply(dynIdent));
        }
        if (type instanceof AvmDeclaredType) {
            AvmDeclaredType typeDec = (AvmDeclaredType) type;
            Iterable<IEObjectDescription> members = Iterables.transform(getAllMembers(typeDec, access),
                    GetDesciption);
            if (dynDesc != null)
                members = Iterables.concat(members, dynDesc);
            return members;
        }
    }
    if (dynDesc != null)
        return dynDesc;
    return Collections.emptySet();
}

From source file:org.isisaddons.module.security.shiro.PrincipalForApplicationUser.java

public static PrincipalForApplicationUser from(ApplicationUser applicationUser) {
    if (applicationUser == null) {
        return null;
    }// ww  w .  j  av a  2  s .  c o  m
    final String username = applicationUser.getName();
    final String encryptedPassword = applicationUser.getEncryptedPassword();
    final AccountType accountType = applicationUser.getAccountType();
    final Set<String> roles = Sets.newTreeSet(Lists
            .newArrayList(Iterables.transform(applicationUser.getRoles(), ApplicationRole.Functions.GET_NAME)));
    final ApplicationPermissionValueSet permissionSet = applicationUser.getPermissionSet();
    return new PrincipalForApplicationUser(username, encryptedPassword, accountType,
            applicationUser.getStatus(), roles, permissionSet);
}

From source file:com.facebook.presto.util.IterableTransformer.java

public <T> IterableTransformer<T> cast(final Class<T> clazz) {
    return new IterableTransformer<>(Iterables.transform(iterable, new Function<E, T>() {
        @Override/*from  w w  w  .  j a  va2 s . co m*/
        public T apply(E input) {
            return clazz.cast(input);
        }
    }));
}

From source file:es.usc.citius.hipster.thirdparty.graphs.jung.JUNGHipsterDirectedGraphAdapter.java

@Override
public Iterable<GraphEdge<V, E>> outgoingEdgesOf(V vertex) {
    try {//from w  w  w  .  j a  v  a2  s.c om
        // getOutEdges blueprints impl throws null pointer exception
        final Collection<E> outEdges = graph.getOutEdges(vertex);
        if (outEdges == null || outEdges.isEmpty()) {
            return Collections.emptyList();
        }
        return Iterables.transform(outEdges, new Function<E, GraphEdge<V, E>>() {
            @Override
            public GraphEdge<V, E> apply(E edge) {
                return new GraphEdge<V, E>(graph.getSource(edge), graph.getDest(edge), edge);
            }
        });
    } catch (NullPointerException e) {
        return Collections.emptyList();
    }
}

From source file:org.obiba.opal.web.system.permissions.DataShieldPermissionsResource.java

/**
 * Get DataShield permissions./*from  w w  w  . j  ava  2s  .  c om*/
 *
 * @param domain
 * @param type
 * @return
 */
@GET
public Iterable<Opal.Acl> getDataShieldPermissions(@QueryParam("type") SubjectType type) {
    Iterable<SubjectAclService.Permissions> permissions = subjectAclService.getNodePermissions(DOMAIN,
            getNode(), type);
    return Iterables.transform(permissions, PermissionsToAclFunction.INSTANCE);
}

From source file:org.isisaddons.app.kitchensink.dom.contrib.contributed.PreferenceContributions.java

@Action(semantics = SemanticsOf.SAFE)
@ActionLayout(contributed = Contributed.AS_ASSOCIATION)
public List<FoodStuff> likes(final Person person) {
    return Lists.newArrayList(Iterables.transform(
            Iterables.filter(preferences.listAllPreferences(), Preference.Predicates.preferenceOf(person)),
            Preference.Functions.food()));
}

From source file:brooklyn.entity.nosql.mongodb.sharding.MongoDBConfigServerClusterImpl.java

@Override
public void start(Collection<? extends Location> locs) {
    super.start(locs);

    // TODO this should be an enricher
    Iterable<String> memberHostNamesAndPorts = Iterables.transform(getMembers(),
            new Function<Entity, String>() {
                @Override//w  ww.  java  2 s  .  c  o m
                public String apply(Entity entity) {
                    return entity.getAttribute(MongoDBConfigServer.SUBNET_HOSTNAME) + ":"
                            + entity.getAttribute(MongoDBConfigServer.PORT);
                }
            });
    setAttribute(MongoDBConfigServerCluster.CONFIG_SERVER_ADDRESSES,
            ImmutableList.copyOf(memberHostNamesAndPorts));
}

From source file:com.google.devtools.build.lib.rules.platform.ConstraintSetting.java

/** Retrieves and casts the providers from the given targets. */
public static Iterable<ConstraintSettingInfo> constraintSettings(
        Iterable<? extends TransitiveInfoCollection> targets) {
    return Iterables.transform(targets, new Function<TransitiveInfoCollection, ConstraintSettingInfo>() {
        @Override/*  w  ww .  j a v  a 2  s  .co  m*/
        public ConstraintSettingInfo apply(TransitiveInfoCollection target) {
            return constraintSetting(target);
        }
    });
}

From source file:net.osgiliath.features.karaf.jaxrs.web.impl.HelloServiceImpl.java

/**
 * return instances.//from  ww w .j a  v  a 2s . c om
 * 
 * @return all elements
 */
@Override
public Hellos getHellos() {

    return new Hellos(Lists.newArrayList(Iterables.transform(this.objects, new Function<HelloObject, String>() {
        @Override
        public String apply(final HelloObject input) {
            return input.getHelloMessage();
        }
    })));
}

From source file:edu.harvard.med.screensaver.model.libraries.LibraryPlate.java

public LibraryPlate(Integer plateNumber, Library library, Set<AssayPlate> assayPlates) {
    super(plateNumber);

    _library = library;/*from   w  w  w.jav  a  2s.  c  o  m*/
    _assayPlateCount = assayPlates.size();
    Iterable<AssayPlate> assayPlatesUniqueAttempts = Iterables.filter(assayPlates, AssayPlate.IsFirstReplicate);
    _copiesScreened = Sets
            .newTreeSet(Iterables.transform(Iterables.filter(assayPlates, AssayPlate.HasLibraryScreening),
                    Functions.compose(Plate.ToCopy, AssayPlate.ToPlate)));
    _libraryScreenings = Sets.newTreeSet(
            Iterables.filter(Iterables.transform(assayPlatesUniqueAttempts, AssayPlate.ToLibraryScreening),
                    Predicates.notNull()));
    if (!_libraryScreenings.isEmpty()) {
        _firstDateScreened = _libraryScreenings.first().getDateOfActivity();
        _lastDateScreened = _libraryScreenings.last().getDateOfActivity();
    }
    SortedSet<AdministrativeActivity> dataLoadings = Sets.newTreeSet(Iterables.filter(
            Iterables.transform(assayPlatesUniqueAttempts, AssayPlate.ToScreenResultDataLoading),
            Predicates.notNull()));
    _dataLoadingCount = dataLoadings.size();
    if (_dataLoadingCount > 0) {
        _firstDateDataLoaded = dataLoadings.first().getDateOfActivity();
        _lastDateDataLoaded = dataLoadings.last().getDateOfActivity();
    }
}