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.eigenbase.reltype.RelDataTypeImpl.java

public RelDataTypeField getField(String fieldName, boolean caseSensitive) {
    for (RelDataTypeField field : fieldList) {
        if (Util.match(caseSensitive, field.getName(), fieldName)) {
            return field;
        }// ww  w .ja  va 2 s .c  o m
    }
    // Extra field
    if (fieldList.size() > 0) {
        final RelDataTypeField lastField = Iterables.getLast(fieldList);
        if (lastField.getName().equals("_extra")) {
            return new RelDataTypeFieldImpl(fieldName, -1, lastField.getType());
        }
    }
    return null;
}

From source file:org.eclipse.xtend.ide.hover.XtendHoverSignatureProvider.java

@Override
protected String getDeclaratorName(JvmMember member) {
    JvmDeclaredType declaringType = member.getDeclaringType();
    if (declaringType.isLocal()) {
        String rawName = Iterables.getLast(declaringType.getSuperTypes()).getType().getSimpleName();
        return "new " + rawName + "(){}";
    } else {/*  ww w.j a v  a 2 s  .  com*/
        return super.getDeclaratorName(member);
    }
}

From source file:de.monticore.utils.Link.java

/**
 * @return the topmost Link in the tree to which this Link belongs
 *///from   w w  w.  j a  va 2 s. c o  m
public Link<?, ?> rootLink() {
    List<Link<?, ?>> parents = Util.listTillNull(this, Link::parent);
    return Iterables.getLast(parents);
}

From source file:google.registry.bigquery.BigqueryJobFailureException.java

/**
 * Returns a short error code describing why this job failed.
 *
 * <h3>Sample Reasons</h3>/*from  w  ww  .j a  va 2 s . c o m*/
 *
 * <ul>
 *   <li>{@code "duplicate"}: The table you're trying to create already exists.
 *   <li>{@code "invalidQuery"}: Query syntax error of some sort.
 *   <li>{@code "unknown"}: Non-Bigquery errors.
 * </ul>
 *
 * @see <a href="https://cloud.google.com/bigquery/troubleshooting-errors">
 *     Troubleshooting Errors</a>
 */
public String getReason() {
    if (jobStatus != null) {
        return jobStatus.getErrorResult().getReason();
    } else if (jsonError != null) {
        return Iterables.getLast(jsonError.getErrors()).getReason();
    } else {
        return "unknown";
    }
}

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

/**
 * Translates the given API level to the equivalent API level in the NDK.
 *//*from   w w w. j  ava2s. c  o  m*/
private String getCorrectedApiLevel(EventHandler eventHandler, String repositoryName, String apiLevel) {

    String correctedApiLevel = apiEquivalencies.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(apiEquivalencies.keySet());
        correctedApiLevel = apiEquivalencies.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;
}

From source file:org.zmlx.hg4idea.action.HgCompareWithBranchAction.java

@Nullable
private static Hash getHeavyBranchMainHash(@NotNull HgRepository repository, @NotNull String branchName) {
    // null for new branch or not heavy ref
    final LinkedHashSet<Hash> branchHashes = repository.getBranches().get(branchName);
    return branchHashes != null ? ObjectUtils.assertNotNull(Iterables.getLast(branchHashes)) : null;
}

From source file:org.jclouds.samples.googleappengine.functions.BlobStoreContextToContainerResult.java

public ContainerResult apply(final String contextName) {
    final BlobStoreContext<?, ?> context = contexts.get(contextName);
    final String host = context.getEndPoint().getHost();
    try {/*from www.ja  va2 s .co m*/
        ResourceMetadata md = Iterables.getLast(Sets
                .newTreeSet(Iterables.filter(context.getBlobStore().list(), new Predicate<ResourceMetadata>() {

                    public boolean apply(ResourceMetadata input) {
                        return input.getType() == ResourceType.CONTAINER;
                    }

                })));
        return new BuildContainerResult(host, context, contextName).apply(md);
    } catch (Exception e) {
        ContainerResult result = new ContainerResult(contextName, host, null, e.getMessage());
        logger.error(e, "Error listing service %s", contextName);
        return result;
    }

}

From source file:com.github.fge.jsonschema.expand.SchemaExpander.java

private static String getLastToken(final JsonPointer ptr) {
    return Iterables.getLast(ptr).getToken().getRaw();
}

From source file:org.lttng.scope.lttng.ust.core.analysis.debuginfo.internal.FileOffsetMapper.java

/**
 * Generate the callsite from a given binary file and address offset.
 *
 * Due to function inlining, it is possible for one offset to actually have
 * multiple call sites. We will return the most precise one (inner-most) we
 * have available./*from   www  .  j  a va  2 s.  c om*/
 *
 * @param file
 *            The binary file to look at
 * @param buildId
 *            The expected buildId of the binary file (is not verified at
 *            the moment)
 * @param offset
 *            The memory offset in the file
 * @return The corresponding call site
 */
public static @Nullable TmfCallsite getCallsiteFromOffset(File file, @Nullable String buildId, long offset) {
    Iterable<Addr2lineInfo> output = getAddr2lineInfo(file, buildId, offset);
    if (output == null || Iterables.isEmpty(output)) {
        return null;
    }
    Addr2lineInfo info = Iterables.getLast(output);
    String sourceFile = info.fSourceFileName;
    Long sourceLine = info.fSourceLineNumber;

    if (sourceFile == null) {
        /* Not enough information to provide a callsite */
        return null;
    }
    return new TmfCallsite(sourceFile, sourceLine);
}

From source file:net.freifunk.autodeploy.selenium.HeadlessDriver.java

@Override
protected void get(final URL url) {
    final String userInfo = url.getUserInfo();
    if (userInfo != null) {
        final Iterable<String> parts = Splitter.on(':').split(userInfo);
        Preconditions.checkState(Iterables.size(parts) == 2, "Expecting format user:password for userinfo.");
        final String username = Iterables.get(parts, 0);
        final String password = Iterables.getLast(parts);
        _headlessDriverCredentialsProvider.set(username, password);
    } else {//from   w ww.  j a  v  a 2 s. c om
        _headlessDriverCredentialsProvider.reset();
    }
    super.get(url);
}