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

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

Introduction

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

Prototype

public static <T> T getLast(Iterable<T> iterable) 

Source Link

Document

Returns the last element of iterable .

Usage

From source file:org.apache.metron.enrichment.utils.EnrichmentUtils.java

public static String toTopLevelField(String field) {
    if (field == null) {
        return null;
    }//from w  w w  . ja  v  a  2  s  .  c o  m
    return Iterables.getLast(Splitter.on('.').split(field));
}

From source file:org.sonar.pickbasic.checks.NonEmptyCaseWithoutBreakCheck.java

private boolean endsWithJump(List<StatementTree> statements) {
    if (statements.isEmpty()) {
        return false;
    }//from   www .  ja  v a2s. co  m
    if (statements.size() == 1 && statements.get(0).is(Kind.BLOCK)) {
        BlockTree block = (BlockTree) statements.get(0);
        return endsWithJump(block.statements());
    }
    return Iterables.getLast(statements).is(Kind.BREAK_STATEMENT, Kind.RETURN_STATEMENT, Kind.THROW_STATEMENT,
            Kind.CONTINUE_STATEMENT);
}

From source file:org.obm.push.mail.mime.MimeAddress.java

public int getLastIndex() {
    String lastIdx = Iterables.getLast(Splitter.on('.').split(address));
    if (Strings.isNullOrEmpty(lastIdx)) {
        return -1;
    }//w  w  w. j  a va 2 s.  c o  m
    return Integer.valueOf(lastIdx);
}

From source file:io.crate.planner.node.dql.MergePhase.java

public MergePhase(UUID jobId, int executionNodeId, String name, int numUpstreams,
        Collection<String> executionNodes, Collection<? extends DataType> inputTypes,
        List<Projection> projections, DistributionInfo distributionInfo,
        @Nullable PositionalOrderBy positionalOrderBy) {
    super(jobId, executionNodeId, name, projections);
    this.inputTypes = inputTypes;
    this.numUpstreams = numUpstreams;
    this.distributionInfo = distributionInfo;
    if (projections.isEmpty()) {
        outputTypes = Lists.newArrayList(inputTypes);
    } else {//from   w  w w . j  a v a  2s.  c om
        outputTypes = Symbols.extractTypes(Iterables.getLast(projections).outputs());
    }
    this.positionalOrderBy = positionalOrderBy;
    this.executionNodes = executionNodes;
}

From source file:org.jbb.frontend.impl.acp.install.AcpPermissionInstallAction.java

@Override
public void install(InstallationData installationData) {

    List<AcpCategoryEntity> categories = acpCategoryRepository.findByOrderByOrdering();
    AcpCategoryEntity lastCategory = Iterables.getLast(categories);
    Integer newCategoryPosition = lastCategory.getOrdering();
    lastCategory.setOrdering(newCategoryPosition + 1);
    acpCategoryRepository.save(lastCategory);

    AcpCategoryEntity permissionsCategory = acpCategoryFactory.createWithSubcategories(
            new AcpCategoryTuple(PERMISSIONS_CATEGORY, PERMISSIONS_VIEW),
            acpSubcategoryFactory.createWithElements(GLOBAL_PERMISSIONS_SUBCATEGORY,
                    new AcpElementTuple(GLOBAL_PERMISSIONS_MEMBERS_ELEMENT, GLOBAL_PERMISSIONS_MEMBERS_VIEW),
                    new AcpElementTuple(GLOBAL_PERMISSIONS_ADMINISTRATORS_ELEMENT,
                            GLOBAL_PERMISSIONS_ADMINISTRATORS_VIEW)),
            acpSubcategoryFactory.createWithElements(PERMISSION_ROLES_SUBCATEGORY,
                    new AcpElementTuple(PERMISSION_ROLE_MEMBERS_ELEMENT, PERMISSION_ROLE_MEMBERS_VIEW),
                    new AcpElementTuple(PERMISSION_ROLE_ADMINISTRATORS_ELEMENT,
                            PERMISSION_ROLE_ADMINISTRATORS_VIEW)),
            acpSubcategoryFactory.createWithElements(EFFECTIVE_PERMISSIONS_SUBCATEGORY,
                    new AcpElementTuple(EFFECTIVE_PERMISSIONS_MEMBERS_ELEMENT,
                            EFFECTIVE_PERMISSIONS_MEMBERS_VIEW),
                    new AcpElementTuple(EFFECTIVE_PERMISSIONS_ADMINISTRATORS_ELEMENT,
                            EFFECTIVE_PERMISSIONS_ADMINISTRATORS_VIEW)));
    permissionsCategory.setOrdering(newCategoryPosition);

    acpCategoryRepository.save(permissionsCategory);

}

From source file:org.splevo.ui.workflow.VPMRefinementWorkflowDelegate.java

/**
 * {@inheritDoc}//from  w ww.j  a v a  2s  .  c om
 */
@Override
protected IJob createWorkflowJob(VPMRefinementWorkflowConfiguration config) {

    // initialize the basic elements
    SPLevoProject splevoProject = config.getSplevoProjectEditor().getSplevoProject();
    SequentialBlackboardInteractingJob<SPLevoBlackBoard> jobSequence = new SequentialBlackboardInteractingJob<SPLevoBlackBoard>();
    jobSequence.setBlackboard(new SPLevoBlackBoard());

    SetVPMJob setVpmJob = new SetVPMJob(config.getVariationPointModel());
    jobSequence.add(setVpmJob);

    // set the refinements to perform and variation point model in the blackboard
    SetRefinementsJob setRefinementsJob = new SetRefinementsJob(config.getRefinements());
    jobSequence.add(setRefinementsJob);

    // perform the refinements automatically
    VPMApplyRefinementsJob vpmApplyRefinementsJob = new VPMApplyRefinementsJob();
    jobSequence.add(vpmApplyRefinementsJob);

    // save the latest vpm model
    String modelNamePrefix = "" + splevoProject.getVpmModelReferences().size();
    String targetPath = splevoProject.getWorkspace() + "models/vpms/" + modelNamePrefix + "-vpm.vpm";
    boolean refactoringStarted = Iterables.getLast(splevoProject.getVpmModelReferences())
            .isRefactoringStarted();
    SaveVPMJob saveVPMJob = new SaveVPMJob(splevoProject, targetPath, refactoringStarted);
    jobSequence.add(saveVPMJob);

    // open the model
    jobSequence.add(new OpenVPMJob(splevoProject, null));

    // return the prepared workflow
    return jobSequence;
}

From source file:org.jboss.hal.client.deployment.ContentParser.java

private ContentEntry contentEntry(ModelNode node) {
    String path = node.get(PATH).asString();
    Iterable<String> segments = Splitter.on('/').omitEmptyStrings().split(path);

    ContentEntry contentEntry = new ContentEntry();
    contentEntry.name = Iterables.getLast(segments);
    contentEntry.path = path;//from w ww . j ava2  s .com
    contentEntry.depth = Iterables.size(segments);
    contentEntry.directory = node.hasDefined(DIRECTORY) && node.get(DIRECTORY).asBoolean();
    contentEntry.fileSize = node.hasDefined(FILE_SIZE) ? node.get(FILE_SIZE).asLong() : 0;
    return contentEntry;
}

From source file:com.google.api.tools.framework.aspects.http.model.CollectionAttribute.java

/** Returns the methods associated with this collection. */
public Iterable<RestMethod> getMethods() {
    List<RestMethod> result = Lists.newArrayList();
    // Only return the last RestMethod object for each rest method name,
    // since the last one will override all the other RestMethods with
    // the same name.
    for (Collection<RestMethod> values : methods.asMap().values()) {
        result.add(Iterables.getLast(values));
    }//from  w  w w  .j  a v  a  2 s  .  co  m
    Collections.sort(result, new Comparator<RestMethod>() {

        @Override
        public int compare(RestMethod o1, RestMethod o2) {
            return o1.getFullName().compareTo(o2.getFullName());
        }
    });
    return result;
}

From source file:org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule.java

@Provides
@Org//from  w ww.  j  av  a2s .  co  m
@Singleton
protected URI provideOrg(Supplier<VCloudSession> cache, @Named(PROPERTY_VCLOUD_USER) String user) {
    return Iterables.getLast(cache.get().getOrgs().values()).getLocation();
}

From source file:com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r10e.ApiLevel.java

/**
 * Translates the given API level to the equivalent API level in the NDK.
 *///from w w  w.  j av  a  2 s  . com
private static String getCorrectedApiLevel(EventHandler eventHandler, String repositoryName, String apiLevel) {

    String correctedApiLevel = API_EQUIVALENCIES.get(apiLevel);
    if (correctedApiLevel == null) {
        // The user specified an API level we don't know about. Default to the most recent API level.
        // This relies on the entries being added in sorted order.
        String latestApiLevel = Iterables.getLast(API_EQUIVALENCIES.keySet());
        correctedApiLevel = API_EQUIVALENCIES.get(latestApiLevel);

        eventHandler
                .handle(Event.warn(String.format(
                        "API level %s specified by android_ndk_repository '%s' is not available. "
                                + "Using latest known API level %s",
                        apiLevel, repositoryName, latestApiLevel)));
    }
    return correctedApiLevel;
}