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.sonar.pickbasic.checks.DuplicateBranchImplementationCheck.java

private boolean isCaseEndingWithoutJumpStmt(SwitchClauseTree caseTree) {
    return caseTree.is(Kind.CASE_CLAUSE) && !isJumpStatement(Iterables.getLast(caseTree.statements()));
}

From source file:org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramContainerEditPart.java

/**
 * {@inheritDoc}/*from   ww  w. j  av  a 2s  . c o m*/
 * 
 * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getCommand(org.eclipse.gef.Request)
 */
@Override
public Command getCommand(final Request request) {
    Command result = null;
    if (request.getType() != null && RequestConstants.REQ_PASTE.equals(request.getType())) {
        Iterable<ShapeCompartmentEditPart> shapeCompartmentChildren = Iterables.filter(children,
                ShapeCompartmentEditPart.class);
        if (shapeCompartmentChildren.iterator().hasNext()) {
            ShapeCompartmentEditPart lastShapeCompartmentEditPart = Iterables.getLast(shapeCompartmentChildren);
            result = lastShapeCompartmentEditPart.getCommand(request);
        }
        if (result == null) {
            result = super.getCommand(request);
        }
    } else {
        Command cmd = super.getCommand(request);
        result = CommonEditPartOperation.handleAutoPinOnInteractiveMove(this, request, cmd);
    }
    return result;
}

From source file:org.sonar.java.checks.IndentationCheck.java

private void checkCaseGroup(CaseGroupTree tree) {
    List<CaseLabelTree> labels = tree.labels();
    if (labels.size() >= 2) {
        CaseLabelTree previousCaseLabelTree = labels.get(labels.size() - 2);
        excludeIssueAtLine = previousCaseLabelTree.lastToken().line();
    }//  w w w. ja v a2 s  .  c  om
    List<StatementTree> body = tree.body();
    List<StatementTree> newBody = body;
    int bodySize = body.size();
    if (bodySize > 0 && body.get(0).is(Kind.BLOCK)) {
        expectedLevel -= indentationLevel;
        checkIndentation(body.get(0), Iterables.getLast(labels).colonToken().column() + 2);
        newBody = body.subList(1, bodySize);
    }
    checkIndentation(newBody);
    if (bodySize > 0 && body.get(0).is(Kind.BLOCK)) {
        expectedLevel += indentationLevel;
    }
}

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

String getCpuCorrectedApiLevel(String targetCpu) {

    // Check that this API level supports the given cpu architecture (eg 64 bit is supported on only
    // 21+).//from ww  w .  java  2s .c o m
    if (!API_LEVEL_TO_ARCHITECTURES.containsEntry(correctedApiLevel, targetCpu)) {
        // If the given API level does not support the given architecture, find an API level that
        // does support this architecture. A warning isn't printed because the crosstools for
        // architectures that aren't supported by this API level are generated anyway, even if the
        // user doesn't intend to use them (eg, if they're building for only 32 bit archs, the
        // crosstools for the 64 bit toolchains are generated regardless).
        // API_LEVEL_TO_ARCHITECTURES.inverse() returns a map of architectures to the APIs that
        // support that architecture.
        return Iterables.getLast(API_LEVEL_TO_ARCHITECTURES.inverse().get(targetCpu));
    }

    return correctedApiLevel;
}

From source file:com.twitter.aurora.scheduler.async.HistoryPruner.java

/**
 * When triggered, iterates through inactive tasks in the system and prunes tasks that
 * exceed the history goal for a job or are beyond the time threshold.
 *
 * @param event A new StorageStarted event.
 *//*from  ww  w  .j av a  2 s.co  m*/
@Subscribe
public void storageStarted(StorageStarted event) {
    for (IScheduledTask task : LATEST_ACTIVITY
            .sortedCopy(Storage.Util.consistentFetchTasks(storage, INACTIVE_QUERY))) {

        registerInactiveTask(Tasks.SCHEDULED_TO_JOB_KEY.apply(task), Tasks.id(task),
                calculateTimeout(Iterables.getLast(task.getTaskEvents()).getTimestamp()));
    }
}

From source file:com.google.api.codegen.discovery.transformer.py.PythonSampleMethodToViewTransformer.java

private SampleView createSampleView(SampleTransformerContext context) {
    SampleConfig config = context.getSampleConfig();
    MethodInfo methodInfo = config.methods().get(context.getMethodName());
    SampleNamer namer = context.getSampleNamer();
    SampleTypeTable typeTable = context.getSampleTypeTable();
    SymbolTable symbolTable = SymbolTable.fromSeed(PythonTypeTable.RESERVED_IDENTIFIER_SET);

    SampleView.Builder builder = SampleView.newBuilder();

    String serviceVarName = symbolTable.getNewSymbol(namer.getServiceVarName(config.apiTypeName()));

    if (methodInfo.isPageStreaming()) {
        builder.pageStreaming(createSamplePageStreamingView(context, symbolTable));
    }// w  w  w .j  a  va  2 s  .  c  om

    // Created before the fields in case there are naming conflicts in the symbol table.
    SampleAuthView sampleAuthView = createSampleAuthView(context);

    List<SampleFieldView> requiredFields = new ArrayList<>();
    List<String> methodParamAssignments = new ArrayList<>();
    for (FieldInfo field : methodInfo.fields().values()) {
        String name = namer.localVarName(Name.lowerCamel(field.name()));
        SampleFieldView sampleFieldView = SampleFieldView.newBuilder().name(name)
                .defaultValue(typeTable.getZeroValueAndSaveNicknameFor(field.type())).example(field.example())
                .description(field.description()).build();
        requiredFields.add(sampleFieldView);
        // Ex: "fooBar=foo_bar"
        methodParamAssignments.add(field.name() + "=" + name);
    }

    boolean hasRequestBody = methodInfo.requestBodyType() != null;
    if (hasRequestBody) {
        String requestBodyVarName = symbolTable
                .getNewSymbol(namer.getRequestBodyVarName(methodInfo.requestBodyType().message().typeName()));
        builder.requestBodyVarName(requestBodyVarName);
        methodParamAssignments.add("body=" + requestBodyVarName);
    }

    boolean hasResponse = methodInfo.responseType() != null;
    if (hasResponse) {
        builder.responseVarName(symbolTable.getNewSymbol(namer.getResponseVarName()));
    }

    String credentialsVarName = config.authType() == AuthType.API_KEY ? "developerKey" : "credentials";

    return builder.templateFileName(TEMPLATE_FILENAME).outputPath(context.getMethodName() + ".frag.py")
            .apiTitle(config.apiTitle()).apiName(config.apiName()).apiVersion(config.apiVersion())
            .auth(sampleAuthView).serviceVarName(serviceVarName).methodVerb(methodInfo.verb())
            .methodNameComponents(methodInfo.nameComponents()).requestVarName(namer.getRequestVarName())
            .hasRequestBody(hasRequestBody).hasResponse(hasResponse).requiredFields(requiredFields)
            .isPageStreaming(methodInfo.isPageStreaming()).hasMediaUpload(methodInfo.hasMediaUpload())
            .hasMediaDownload(methodInfo.hasMediaDownload()).credentialsVarName(credentialsVarName)
            .lastMethodNameComponent(Iterables.getLast(methodInfo.nameComponents()))
            .methodParamAssigments(methodParamAssignments).build();
}

From source file:org.killbill.billing.plugin.payment.retries.OSGIKillbillAPIWrapper.java

@VisibleForTesting
PaymentTransaction getLastAuthorizationIfFailed(final Collection<Payment> payments,
        final UUID paymentMethodId) {
    if (payments.isEmpty()) {
        // First payment for this account
        return null;
    }/*from w  ww  . java  2s  .c om*/

    final Collection<Payment> paymentsForCurrentPaymentMethod = Collections2.<Payment>filter(payments,
            new Predicate<Payment>() {
                @Override
                public boolean apply(final Payment payment) {
                    return paymentMethodId.equals(payment.getPaymentMethodId());
                }
            });
    if (paymentsForCurrentPaymentMethod.isEmpty()) {
        // First payment for this payment method
        return null;
    }

    final Payment lastPayment = Iterables.getLast(paymentsForCurrentPaymentMethod);
    // Non-zero auth or auth voided means the authorization was successful
    if ((lastPayment.getAuthAmount() != null && BigDecimal.ZERO.compareTo(lastPayment.getAuthAmount()) != 0)
            || lastPayment.isAuthVoided()) {
        return null;
    }

    final Collection<PaymentTransaction> failedAuthorizations = Collections2
            .<PaymentTransaction>filter(lastPayment.getTransactions(), new Predicate<PaymentTransaction>() {
                @Override
                public boolean apply(final PaymentTransaction paymentTransaction) {
                    return paymentTransaction.getTransactionType() == TransactionType.AUTHORIZE
                            || paymentTransaction.getTransactionStatus() == TransactionStatus.PAYMENT_FAILURE;
                }
            });
    if (failedAuthorizations.isEmpty()) {
        return null;
    } else {
        return Iterables.getLast(failedAuthorizations);
    }
}

From source file:io.opencensus.stats.StatsTestUtil.java

private static List<Long> removeTrailingZeros(List<Long> longs) {
    if (longs == null) {
        return null;
    }/* w  ww. java  2s  .  com*/
    List<Long> truncated = new ArrayList<Long>(longs);
    while (!truncated.isEmpty() && Iterables.getLast(truncated) == 0) {
        truncated.remove(truncated.size() - 1);
    }
    return truncated;
}

From source file:com.linagora.obm.ui.page.CreateUserPage.java

private void doCreateUser(UIUser userToCreate) {
    if (userToCreate.hasKindDefined()) {
        userKind.sendKeys(userToCreate.getKind().getUiFrenchText());
    }/*from   www .java  2  s .  com*/
    userLogin.sendKeys(userToCreate.getLogin());
    userFirstname.sendKeys(userToCreate.getFirstName());
    userLastname.sendKeys(userToCreate.getLastName());
    userCommonname.sendKeys(userToCreate.getCommonName());
    passwd.sendKeys(userToCreate.getPassword());
    userTitle.sendKeys(userToCreate.getTitle());
    clickCheckbox(cba_hidden, userToCreate.isMailboxHidden());
    clickCheckbox(cba_archive, userToCreate.isMailboxArchive());
    delegationTargetField.sendKeys(userToCreate.getDelegation());
    clickCheckbox(noexperie, !userToCreate.isNoExpire());
    userPhone.sendKeys(userToCreate.getPhone());
    userPhone2.sendKeys(userToCreate.getPhone2());
    userMobile.sendKeys(userToCreate.getPhoneMobile());
    userFax.sendKeys(userToCreate.getPhoneFax());
    userFax2.sendKeys(userToCreate.getPhoneFax2());
    userCompany.sendKeys(userToCreate.getCompany());
    userDirection.sendKeys(userToCreate.getDirection());
    userService.sendKeys(userToCreate.getService());
    userAd1.sendKeys(userToCreate.getAddress1());
    userAd2.sendKeys(userToCreate.getAddress2());
    userAd3.sendKeys(userToCreate.getAddress3());
    userZip.sendKeys(userToCreate.getAddressZip());
    userTown.sendKeys(userToCreate.getAddressTown());
    userCdx.sendKeys(userToCreate.getAddressCedex());
    userDesc.sendKeys(userToCreate.getDescription());

    if (clickCheckbox(userMailActive, userToCreate.isEmailInternalEnabled())) {
        WebElement firstInternalEmail = Iterables.getLast(internalEmailFields);
        firstInternalEmail.sendKeys(userToCreate.getEmailAddress());
    } else {
        externalEmailField.sendKeys(userToCreate.getEmailAddress());
    }

    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    if (userToCreate.getDateBegin() != null) {
        userDatebegin.sendKeys(sdf.format(userToCreate.getDateBegin()));
    }
    if (userToCreate.getDateExpire() != null) {
        userDateexp.sendKeys(sdf.format(userToCreate.getDateExpire()));
    }

    for (WebElement domainOption : sel_profile.findElements(By.tagName("option"))) {
        if (domainOption.getAttribute("value").equals(String.valueOf(userToCreate.getProfile().getUiValue()))) {
            domainOption.click();
        }
    }

    createUserSubmit.click();
}

From source file:com.google.api.explorer.client.embedded.EmbeddedParameterFormPresenter.java

/**
 * Returns the request body specified by the "resource" key of the parameters block specified.
 *//*  w  w  w.  j  a  v  a 2 s.  co m*/
private String getRequestBodyParam(Multimap<String, String> params) {
    Collection<String> body = params.get(UrlBuilder.BODY_QUERY_PARAM_KEY);
    return body.isEmpty() ? null : Iterables.getLast(body);
}