Example usage for com.google.common.collect ImmutableList get

List of usage examples for com.google.common.collect ImmutableList get

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList get.

Prototype

E get(int index);

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:com.spectralogic.ds3autogen.test.helpers.RemoveDollarSignConverterHelper.java

/**
 * Checks if a list of Ds3Params generated by the createPopulatedParams function
 * has successfully changed all type names to remove the '$' symbol. Assumes
 * that the specified variation matches the variation used during the param
 * list generation.//w w  w . ja va2  s.  co m
 */
public static void checkAutoPopulatedParams(final ImmutableList<Ds3Param> params, final String variation) {
    assertThat(params.size(), is(2));
    assertThat(params.get(0).getType(), is("com.test.package.TypeOne" + variation));
    assertThat(params.get(1).getType(), is("com.test.package.TypeTwo" + variation));
}

From source file:net.awairo.mcmod.common.v1.client.gui.ToggleButton.java

private static ButtonContext getFirstFrom(Handler handler) {
    final ImmutableList<ButtonContext> context = handler.contexts();
    checkElementIndex(0, context.size());

    final int selected = handler.firstSelectedIndex();
    checkPositionIndex(selected, context.size());

    return context.get(selected);
}

From source file:com.spectralogic.ds3autogen.test.helpers.ResponseTypeConverterHelper.java

/**
 * Verifies that a list of ResponseTypes that were generated by this utility have been
 * properly updated./* w  ww  .  j ava 2  s . com*/
 * @param updatedResponseTypes The list of updated Response Types
 * @param originalResponseTypes The list of original Response Types that needed updating
 * @param variation The name variation used to auto populate unique Response Type names
 */
public static void verifyPopulatedResponseTypeList(final ImmutableList<Ds3ResponseType> updatedResponseTypes,
        final ImmutableList<Ds3ResponseType> originalResponseTypes, final String variation) {
    assertThat(updatedResponseTypes.size(), is(4));
    assertThat(updatedResponseTypes.get(0), is(originalResponseTypes.get(0)));
    assertThat(updatedResponseTypes.get(2), is(originalResponseTypes.get(2)));

    assertThat(updatedResponseTypes.get(1).getType(), is("SimpleComponentType" + variation + "List"));
    assertThat(updatedResponseTypes.get(1).getComponentType(), is(nullValue()));
    assertThat(updatedResponseTypes.get(3).getType(),
            is("com.spectralogic.s3.common.dao.domain.ds3.BucketAcl" + variation + "List"));
    assertThat(updatedResponseTypes.get(3).getComponentType(), is(nullValue()));
}

From source file:eu.eidas.auth.commons.io.MapSerializationHelper.java

public static <K, V> void writeKeyValueList(@Nonnull ObjectOutputStream oos,
        @Nonnull ImmutableList<KeyValue<K, V>> keyValueList) throws IOException {
    int kvSize = keyValueList.size();
    oos.writeInt(kvSize);/*from   w  ww  .j  a v a2 s .c  om*/
    for (int i = 0; i < kvSize; i++) {
        KeyValue<K, V> keyValue = keyValueList.get(i);
        oos.writeObject(keyValue.getKey());
        oos.writeObject(keyValue.getValue());
    }
}

From source file:uk.bl.wa.extract.LinkExtractor.java

public static String extractPublicSuffixFromHost(String host) {
    if (host == null)
        return null;
    // Parse out the public suffix:
    InternetDomainName domainName;//from   ww  w . jav  a2  s  .c  om
    try {
        domainName = InternetDomainName.from(host);
    } catch (Exception e) {
        return null;
    }
    InternetDomainName suffix = null;
    if (host.endsWith(".uk")) {
        ImmutableList<String> parts = domainName.parts();
        if (parts.size() >= 2) {
            suffix = InternetDomainName.from(parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1));
        }
    } else {
        suffix = domainName.publicSuffix();
    }
    // Return a value:
    if (suffix == null)
        return null;
    return suffix.toString();
}

From source file:com.google.template.soy.incrementaldomsrc.RemoveUnnecessaryEscapingDirectives.java

private static ImmutableList<SoyPrintDirective> filterEscapingDirectives(
        ImmutableList<SoyPrintDirective> escapingDirectives) {
    for (int i = 0; i < escapingDirectives.size(); i++) {
        SoyPrintDirective directive = escapingDirectives.get(i);
        if (canSkip(directive)) {
            ImmutableList.Builder<SoyPrintDirective> builder = ImmutableList.builder();
            builder.addAll(escapingDirectives.subList(0, i));
            for (; i < escapingDirectives.size(); i++) {
                directive = escapingDirectives.get(i);
                if (!canSkip(directive)) {
                    builder.add(directive);
                }//from ww w. ja va 2  s.  co m
            }
            return builder.build();
        }
    }
    return escapingDirectives;
}

From source file:com.facebook.buck.lua.LuaInPlaceBinary.java

private static Supplier<String> getScript(final SourcePathResolver pathResolver, final Tool lua,
        final String mainModule, final Path relativeLinkTreeRoot) {
    final String relativeLinkTreeRootStr = Escaper.escapeAsPythonString(relativeLinkTreeRoot.toString());
    return new Supplier<String>() {
        @Override/*from   w  w w.  j  a  va 2  s .  c om*/
        public String get() {
            ImmutableList<String> luaCommand = lua.getCommandPrefix(pathResolver);
            Preconditions.checkArgument(luaCommand.size() == 1);
            return new ST(getRunInplaceResource()).add("SHEBANG", luaCommand.get(0))
                    .add("LUA", Escaper.escapeAsPythonString(luaCommand.get(0)))
                    .add("MAIN_MODULE", Escaper.escapeAsPythonString(mainModule))
                    .add("MODULES_DIR", relativeLinkTreeRootStr).render();
        }
    };
}

From source file:uk.bl.wa.extract.LinkExtractor.java

/**
 * Attempt to parse out the private domain. Fall back on host if things go
 * awry./*from w ww  .  ja  v a 2s.co  m*/
 * 
 * @param host
 * @return
 */
public static String extractPrivateSuffixFromHost(String host) {
    if (host == null)
        return null;
    // Parse out the public suffix:
    InternetDomainName domainName;
    try {
        domainName = InternetDomainName.from(host);
    } catch (Exception e) {
        return host;
    }
    InternetDomainName suffix = null;
    // It appears the IDN class does not know about the various UK
    // second-level domains.
    // If it's a UK host, override the result by assuming three levels:
    if (host.endsWith(".uk")) {
        ImmutableList<String> parts = domainName.parts();
        if (parts.size() >= 3) {
            suffix = InternetDomainName.from(parts.get(parts.size() - 3) + "." + parts.get(parts.size() - 2)
                    + "." + parts.get(parts.size() - 1));
        }
    } else {
        if (domainName.isTopPrivateDomain() || domainName.isUnderPublicSuffix()) {
            suffix = domainName.topPrivateDomain();
        } else {
            suffix = domainName;
        }
    }

    // If it all failed for some reason, fall back on the host value:
    if (suffix == null)
        suffix = domainName;

    return suffix.toString();
}

From source file:com.facebook.buck.features.rust.RustAssumptions.java

public static void assumeVersion(ProjectWorkspace workspace, String version)
        throws IOException, InterruptedException {
    BuildRuleResolver resolver = new TestActionGraphBuilder();
    SourcePathResolver pathResolver = DefaultSourcePathResolver.from(new SourcePathRuleFinder(resolver));
    RustPlatform rustPlatform = RustPlatformFactory.of(FakeBuckConfig.builder().build(), new ExecutableFinder())
            .getPlatform("rust", CxxPlatformUtils.DEFAULT_PLATFORM);
    ImmutableList<String> rustc = rustPlatform.getRustCompiler().resolve(resolver)
            .getCommandPrefix(pathResolver);

    String[] versionParts = version.split("\\.");

    Result res = workspace.runCommand(rustc.get(0), "--version");
    String stdout = res.getStdout().get();

    // rustc 1.32.0 (9fda7c223 2019-01-16)
    String[] rustOut = stdout.split(" +", 3);
    assumeTrue("rustc --version produced wrong output", rustOut.length == 3 && rustOut[0].equals("rustc"));

    String[] rustVersionParts = rustOut[1].split("\\.");

    for (int i = 0; i < versionParts.length && i < rustVersionParts.length; i++) {
        Integer rustcVer = Integer.parseInt(rustVersionParts[i]);
        Integer wantVer = Integer.parseInt(versionParts[i]);

        assumeTrue(String.format("rustc version %s doesn't meet %s", rustOut[1], version), rustcVer >= wantVer);

        // No need to check the less significant parts if this one is larger than required.
        if (rustcVer > wantVer) {
            break;
        }/*from   w  w w .j  a v a 2 s.com*/
    }
}

From source file:com.spectralogic.ds3autogen.utils.Ds3ElementUtil.java

/**
 * Gets the Xml tag name for an element from its list of Ds3Annotations, if one
 * exists. If multiple Xml tag names are found, an exception is thrown.
 */// w  ww.j  a v a 2  s . c  o m
protected static String getXmlTagFromAllAnnotations(final ImmutableList<Ds3Annotation> annotations,
        final String elementName) {
    if (isEmpty(annotations)) {
        return "";
    }
    final ImmutableList.Builder<String> builder = ImmutableList.builder();
    for (final Ds3Annotation annotation : annotations) {
        final String curXmlName = getXmlTagFromAnnotation(annotation);
        if (hasContent(curXmlName)) {
            builder.add(curXmlName);
        }
    }
    final ImmutableList<String> xmlNames = builder.build();
    switch (xmlNames.size()) {
    case 0:
        return "";
    case 1:
        return xmlNames.get(0);
    default:
        throw new IllegalArgumentException(
                "There are multiple xml tag names described within the annotations for the element "
                        + elementName + ": " + xmlNames.toString());
    }
}