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.eason.common.collected.utils.test.LogbackListAppender.java

/**
 * ?append?log.//w w  w  .  j ava 2s.c  o m
 */
public ILoggingEvent getLastLog() {
    if (logs.isEmpty()) {
        return null;
    }
    return Iterables.getLast(logs);
}

From source file:org.glowroot.central.repo.Common.java

static int getNeedsRollupAdjustedTTL(int adjustedTTL, List<RollupConfig> rollupConfigs) {
    if (adjustedTTL == 0) {
        return 0;
    }// w  w  w. j a v a 2s. c o  m
    long maxRollupInterval = Iterables.getLast(rollupConfigs).intervalMillis();
    // reduced by an extra 1 hour to make sure that once needs rollup record is retrieved,
    // there is plenty of time to read the all of the data records in the interval before they
    // expire (reading partially expired interval can lead to non-idempotent rollups)
    int needsRollupAdjustedTTL = adjustedTTL - Ints.saturatedCast(MILLISECONDS.toSeconds(maxRollupInterval))
            - 3600;
    // max is a safety guard
    return Math.max(needsRollupAdjustedTTL, 60);
}

From source file:org.onos.yangtools.binding.data.codec.impl.InstanceIdentifierCodec.java

@Override
public InstanceIdentifier<?> deserialize(final YangInstanceIdentifier input) {
    final List<InstanceIdentifier.PathArgument> builder = new ArrayList<>();
    final NodeCodecContext<?> codec = context.getCodecContextNode(input, builder);
    if (codec == null) {
        return null;
    }//  w  w w  .  j  ava  2 s  . c o m
    if (codec instanceof ListNodeCodecContext
            && Iterables.getLast(builder) instanceof InstanceIdentifier.Item) {
        // We ended up in list, but without key, which means it represent list as a whole,
        // which is not binding representable.
        return null;
    }
    return InstanceIdentifier.create(builder);
}

From source file:com.google.security.zynamics.binnavi.debug.models.memoryexpressions.PlusExpression.java

@Override
public String toString() {
    final StringBuilder ret = new StringBuilder();
    for (final MemoryExpressionElement child : children) {
        ret.append(child.toString());//from  w ww  . j  a  v  a2 s  .c  o  m
        if (child != Iterables.getLast(children)) {
            ret.append('+');
        }
    }
    return ret.toString();
}

From source file:org.sonar.flex.checks.TooManyLinesInCaseCheck.java

@Override
public void visitNode(AstNode astNode) {
    AstNode lastLabelNode = Iterables.getLast(astNode.getChildren(FlexGrammar.CASE_LABEL));
    int lines = Math.max(astNode.getNextAstNode().getTokenLine() - lastLabelNode.getTokenLine(), 1);
    if (lines > max) {
        getContext().createLineViolation(this,
                "Reduce this switch case number of lines from {0} to at most {1}, for example by extracting code into methods.",
                lastLabelNode, lines, max);
    }//  ww  w . j a  v a 2s  .  c  o  m
}

From source file:org.obm.push.minig.imap.ImapTestUtils.java

private static long retrieveLastEmailUid(StoreClient client, String mailbox)
        throws MailException, MailboxNotFoundException, ImapTimeoutException {

    client.select(mailbox);/*w  ww . j  av a  2  s . c om*/
    SearchQuery query = SearchQuery.builder().after(DateUtils.getEpochCalendar().getTime()).build();
    MessageSet messages = client.uidSearch(query);
    return Iterables.getLast(messages.asDiscreteValues());
}

From source file:com.google.idea.blaze.android.sync.AndroidSdkPlatformSyncer.java

@Nullable
static AndroidSdkPlatform getAndroidSdkPlatform(Project project, BlazeContext context,
        File androidPlatformDirectory) {

    String androidSdk = null;//ww  w  .  ja v  a 2 s . c  o m

    String localSdkLocation = AswbGlobalSettings.getInstance().getLocalSdkLocation();
    if (localSdkLocation == null) {
        IssueOutput.error("Error: No android_sdk synced yet. Please sync SDK following go/aswb-sdk.")
                .submit(context);
    }

    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
    if (projectViewSet != null) {
        Collection<ScalarSection<String>> androidSdkPlatformSections = projectViewSet
                .getSections(AndroidSdkPlatformSection.KEY);
        if (!androidSdkPlatformSections.isEmpty()) {
            ScalarSection<String> androidSdkPlatformSection = Iterables.getLast(androidSdkPlatformSections);
            androidSdk = BlazeAndroidSdk.getAndroidSdkLevelFromLocalChannel(localSdkLocation,
                    androidSdkPlatformSection.getValue());

            if (androidSdk == null) {
                IssueOutput.error("No such android_sdk_platform: " + androidSdkPlatformSection.getValue())
                        .inFile(projectViewSet.getTopLevelProjectViewFile().projectViewFile).submit(context);
            }
        }
    }

    if (androidSdk == null) {
        androidSdk = BlazeAndroidSdk.getAndroidSdkLevelFromBlazeRc(androidPlatformDirectory);
    }

    if (androidSdk == null) {
        IssueOutput
                .error("Can't determine your SDK. Please sync your SDK by following go/aswb-sdk and try again.")
                .submit(context);
        return null;
    }

    Sdk sdk = AndroidSdkUtils.findSuitableAndroidSdk(androidSdk);
    if (sdk == null) {
        IssueOutput.error(
                "Can't find a matching SDK. Please sync your SDK by following go/aswb-sdk and try again.")
                .submit(context);
        return null;
    }

    int androidSdkApiLevel = getAndroidSdkApiLevel(androidSdk);
    return new AndroidSdkPlatform(androidSdk, androidSdkApiLevel);
}

From source file:com.google.security.zynamics.binnavi.debug.models.memoryexpressions.MultiplicationExpression.java

@Override
public String toString() {
    final StringBuilder ret = new StringBuilder();
    for (final MemoryExpressionElement child : children) {
        ret.append(child.toString());//w w w.  java 2 s .  com
        if (child != Iterables.getLast(children)) {
            ret.append('*');
        }
    }
    return ret.toString();
}

From source file:org.ambraproject.rhino.service.taxonomy.WeightedTerm.java

public String getLeafTerm() {
    return Iterables.getLast(TERM_SPLITTER.split(path));
}

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

@Override
public void visitNode(Tree tree) {
    ListTree<VariableTree> resources = ((TryStatementTree) tree).resources();
    // need only (resources.size - 1) separators
    if (!resources.isEmpty() && resources.separators().size() == resources.size()) {
        reportIssue(Iterables.getLast(resources.separators()), "Remove this extraneous semicolon.");
    }//from  w ww . j  av a2 s.  com
}