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

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

Introduction

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

Prototype

@CheckReturnValue
public static <F, T> List<T> transform(List<F> fromList, Function<? super F, ? extends T> function) 

Source Link

Document

Returns a list that applies function to each element of fromList .

Usage

From source file:org.eclipse.wb.internal.swt.model.layout.LayoutAssistantSupport.java

/**
 * Converts {@link IControlInfo}s into their {@link ILayoutDataInfo}s.
 *//*from  w  w w  .  ja v  a 2 s.  co  m*/
protected final List<ILayoutDataInfo> getDataList(List<ObjectInfo> objects) {
    List<ILayoutDataInfo> dataList = Lists.transform(objects, new Function<ObjectInfo, ILayoutDataInfo>() {
        public ILayoutDataInfo apply(ObjectInfo from) {
            return m_layout.getLayoutData2((IControlInfo) from);
        }
    });
    return dataList;
}

From source file:com.cloudera.whirr.cm.handler.CmBalancerHandler.java

@Override
protected void beforeStart(ClusterActionEvent event) throws IOException, InterruptedException {
    super.beforeStart(event);
    final String portBalancerImpala = CmServerClusterInstance.getConfiguration(event.getClusterSpec())
            .getString(CmConstants.CONFIG_WHIRR_INTERNAL_PORT_BALANCER_IMPALA);
    addStatement(event, call("retry_helpers"));
    addStatement(event, call("configure_cm_balancer", "-b", portBalancerImpala, "-h",
            Joiner.on(',')
                    .join(Lists.transform(
                            Lists.newArrayList(event.getCluster()
                                    .getInstancesMatching(RolePredicates.role(CmCdhImpalaDaemonHandler.ROLE))),
                            new Function<Cluster.Instance, String>() {
                                @Override
                                public String apply(Cluster.Instance input) {
                                    return input.getPrivateIp() + ":" + portBalancerImpala;
                                }//ww w  .  j a va2 s  .  co m
                            }))));
    if (CmServerClusterInstance.getConfiguration(event.getClusterSpec())
            .getBoolean(CONFIG_WHIRR_FIREWALL_ENABLE, true)) {
        event.getFirewallManager().addRules(
                Rule.create().destination(role(getRole())).ports(Integer.parseInt(portBalancerImpala)));
        for (Statement portIngressStatement : event.getFirewallManager().getRulesAsStatements()) {
            addStatement(event, portIngressStatement);
        }
    }
}

From source file:org.jpmml.converter.ValueUtil.java

static public List<Integer> asIntegers(List<? extends Number> numbers) {

    if (numbers == null) {
        return null;
    }/*w w  w .  j  av a2 s . com*/

    Function<Number, Integer> function = new Function<Number, Integer>() {

        @Override
        public Integer apply(Number number) {
            return asInteger(number);
        }
    };

    return Lists.transform(numbers, function);
}

From source file:org.fao.geonet.services.ownership.OwnershipUtils.java

public static List<Element> getUsers(ServiceContext context, UserSession us, List<User> users)
        throws SQLException {

    int id = us.getUserIdAsInt();

    if (us.getProfile() == Profile.Administrator) {
        final List<Element> userXml = Lists.transform(users, new Function<User, Element>() {
            @Override/*from ww w .j  ava2  s .  com*/
            @Nonnull
            public Element apply(@Nonnull User input) {
                return input.asXml();

            }
        });
        return userXml;
    }

    //--- we have a user admin

    Set<String> hsMyGroups = getUserGroups(context, id);

    Set<Profile> profileSet = us.getProfile().getAll();

    //--- now filter them

    List<Element> newList = new ArrayList<Element>();

    for (User elRec : users) {
        int userId = elRec.getId();
        Profile profile = elRec.getProfile();

        if (profileSet.contains(profile)) {
            if (hsMyGroups.containsAll(getUserGroups(context, userId))) {
                newList.add(elRec.asXml());
            }
        }
    }

    //--- return result

    return newList;
}

From source file:com.cloudera.science.ml.core.records.avro.AvroSpec.java

@Override
public List<String> getFieldNames() {
    return Lists.transform(getFields(), new Function<Field, String>() {
        @Override//from   www  . ja v  a  2s  .co  m
        public String apply(Field input) {
            return input.name();
        }
    });
}

From source file:org.geogig.geoserver.rest.RepositoryResource.java

@Override
public Variant getPreferredVariant() {
    Optional<Variant> byExtension = Variants.getVariantByExtension(getRequest(), getVariants());
    if (byExtension.isPresent()) {
        return byExtension.get();
    }//from   w  w  w  .  j a va2 s.c  om
    List<MediaType> acceptedMediaTypes = Lists.transform(getRequest().getClientInfo().getAcceptedMediaTypes(),
            new Function<Preference<MediaType>, MediaType>() {
                @Override
                public MediaType apply(Preference<MediaType> input) {
                    return input.getMetadata();
                }
            });
    if (acceptedMediaTypes.contains(MediaType.TEXT_HTML)) {
        return HTML;
    }
    if (acceptedMediaTypes.contains(MediaType.TEXT_XML)) {
        return XML;
    }
    if (acceptedMediaTypes.contains(MediaType.APPLICATION_JSON)) {
        return JSON;
    }

    return XML;
}

From source file:ninja.leaping.permissionsex.util.command.args.CommandArgs.java

public List<String> getAll() {
    return Lists.transform(args, SingleArg::getValue);
}

From source file:com.google.cloud.genomics.dataflow.readers.bam.ReadConverter.java

/**
 * Generates a Read from a SAMRecord. //from w ww .  j  av a 2  s  . co m
 */
public static final Read makeRead(final SAMRecord record) {
    Read read = new Read();
    read.setId(record.getReadName()); // TODO: make more unique
    read.setFragmentName(record.getReadName());
    read.setReadGroupId(getAttr(record, "RG"));
    read.setNumberReads(record.getReadPairedFlag() ? 2 : 1);
    read.setProperPlacement(record.getReadPairedFlag() && record.getProperPairFlag());
    if (!record.getReadUnmappedFlag() && record.getAlignmentStart() > 0) {
        LinearAlignment alignment = new LinearAlignment();

        Position position = new Position();
        position.setPosition((long) record.getAlignmentStart() - 1);
        position.setReferenceName(record.getReferenceName());
        position.setReverseStrand(record.getReadNegativeStrandFlag());
        alignment.setPosition(position);

        alignment.setMappingQuality(record.getMappingQuality());

        final String referenceSequence = (record.getAttribute("MD") != null)
                ? new String(SequenceUtil.makeReferenceFromAlignment(record, true))
                : null;
        List<CigarUnit> cigar = Lists.transform(record.getCigar().getCigarElements(),
                new Function<CigarElement, CigarUnit>() {
                    @Override
                    public CigarUnit apply(CigarElement c) {
                        CigarUnit u = new CigarUnit();
                        CigarOperator o = c.getOperator();
                        u.setOperation(CIGAR_OPERATIONS_INV.get(o.toString()));
                        u.setOperationLength((long) c.getLength());
                        if (referenceSequence != null && (u.getOperation().equals("SEQUENCE_MISMATCH")
                                || u.getOperation().equals("DELETE"))) {
                            u.setReferenceSequence(referenceSequence);
                        }
                        return u;
                    }
                });
        alignment.setCigar(cigar);
        read.setAlignment(alignment);
    }
    read.setDuplicateFragment(record.getDuplicateReadFlag());
    read.setFragmentLength(record.getInferredInsertSize());
    if (record.getReadPairedFlag()) {
        if (record.getFirstOfPairFlag()) {
            read.setReadNumber(0);
        } else if (record.getSecondOfPairFlag()) {
            read.setReadNumber(1);
        }

        if (!record.getMateUnmappedFlag()) {
            Position matePosition = new Position();
            matePosition.setPosition((long) record.getMateAlignmentStart() - 1);
            matePosition.setReferenceName(record.getMateReferenceName());
            matePosition.setReverseStrand(record.getMateNegativeStrandFlag());
            read.setNextMatePosition(matePosition);
        }
    }
    read.setFailedVendorQualityChecks(record.getReadFailsVendorQualityCheckFlag());
    read.setSecondaryAlignment(record.getNotPrimaryAlignmentFlag());
    read.setSupplementaryAlignment(record.getSupplementaryAlignmentFlag());
    read.setAlignedSequence(record.getReadString());
    byte[] baseQualities = record.getBaseQualities();
    if (baseQualities.length > 0) {
        List<Integer> readBaseQualities = new ArrayList<Integer>(baseQualities.length);
        for (byte b : baseQualities) {
            readBaseQualities.add(new Integer(b));
        }
        read.setAlignedQuality(readBaseQualities);
    }

    Map<String, List<String>> attributes = Maps.newHashMap();
    for (SAMRecord.SAMTagAndValue tagAndValue : record.getAttributes()) {
        attributes.put(tagAndValue.tag, Lists.newArrayList(tagAndValue.value.toString()));
    }
    read.setInfo(attributes);

    return read;
}

From source file:eu.itesla_project.computation.GroupCommandImpl.java

@Override
public String toString(final String executionNumber) {
    return Lists.transform(subCommands, new Function<SubCommand, String>() {
        @Override/*w  w w .j  ava 2 s  . com*/
        public String apply(SubCommand subCommand) {
            return subCommand.toString(executionNumber);
        }
    }).toString();
}

From source file:com.prealpha.xylophone.server.filter.BatchActionHandler.java

@Override
public BatchResult execute(BatchAction action) throws ActionException {
    List<BatchedActionResult<?>> results = Lists.transform(action.getActions(),
            new Function<Action<?>, BatchedActionResult<?>>() {
                @Override//from   w  w  w  .ja v  a 2s.c om
                public BatchedActionResult<?> apply(Action<?> action) {
                    return executeBatched(action);
                }
            });
    return new BatchResult(results);
}