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

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

Introduction

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

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

Usage

From source file:org.openqa.selenium.build.BuckBuild.java

private Path findOutput(Path projectRoot) throws IOException {
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    findBuck(projectRoot, builder);//from   w w  w  .  j ava2 s.  c  o m
    builder.add("targets", "--show-full-output", "--config", "color.ui=never", target);

    ImmutableList<String> command = builder.build();
    CommandLine commandLine = new CommandLine(command.toArray(new String[command.size()]));
    commandLine.setWorkingDirectory(projectRoot.toAbsolutePath().toString());
    commandLine.copyOutputTo(System.err);
    commandLine.execute();

    if (!commandLine.isSuccessful()) {
        throw new WebDriverException("Unable to find output! " + target);
    }

    String stdOut = commandLine.getStdOut();
    String[] allLines = stdOut.split(LINE_SEPARATOR.value());
    String lastLine = null;
    for (String line : allLines) {
        if (line.startsWith(target)) {
            lastLine = line;
            break;
        }
    }
    Preconditions.checkNotNull(lastLine, "Value read: %s", stdOut);

    List<String> outputs = Splitter.on(' ').limit(2).splitToList(lastLine);
    if (outputs.size() != 2) {
        throw new WebDriverException(String.format("Unable to find output! %s, %s", target, lastLine));
    }

    Path output = projectRoot.resolve(outputs.get(1));

    if (!Files.exists(output)) {
        throw new WebDriverException(
                String.format("Found output, but it does not exist: %s, %s", target, output));
    }

    return output;
}

From source file:org.openqa.selenium.BuckBuild.java

private Path findOutput(Path projectRoot) throws IOException {
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    findBuck(projectRoot, builder);//from w  ww . j a  v  a2s .  c  om
    builder.add("targets", "--show-output", target);

    ImmutableList<String> command = builder.build();
    CommandLine commandLine = new CommandLine(command.toArray(new String[command.size()]));
    commandLine.copyOutputTo(System.err);
    commandLine.execute();

    if (!commandLine.isSuccessful()) {
        throw new WebDriverException("Unable to find output! " + target);
    }

    String[] allLines = commandLine.getStdOut().split(LINE_SEPARATOR.value());
    String lastLine = null;
    for (String line : allLines) {
        if (line.startsWith(target)) {
            lastLine = line;
            break;
        }
    }
    Preconditions.checkNotNull(lastLine);

    List<String> outputs = Splitter.on(' ').limit(2).splitToList(lastLine);
    if (outputs.size() != 2) {
        throw new WebDriverException(String.format("Unable to find output! %s, %s", target, lastLine));
    }

    Path output = projectRoot.resolve(outputs.get(1));

    if (!Files.exists(output)) {
        throw new WebDriverException(
                String.format("Found output, but it does not exist: %s, %s", target, output));
    }

    return output;
}

From source file:org.lanternpowered.server.text.gson.JsonTextTranslatableSerializer.java

@SuppressWarnings("deprecation")
@Override//from  w w w.  java2  s.  c  om
public JsonElement serialize(TranslatableText src, Type typeOfSrc, JsonSerializationContext context) {
    final Translation translation = src.getTranslation();
    if (this.networkingFormat && !(translation instanceof MinecraftTranslation)) {
        final ImmutableList<Object> arguments = src.getArguments();
        final Object[] rawArguments = arguments.toArray(new Object[arguments.size()]);
        final Locale locale = currentLocale.get();
        for (int i = 0; i < rawArguments.length; i++) {
            Object object = rawArguments[i];
            if (object instanceof TextRepresentable) {
                if (!(object instanceof Text)) {
                    object = ((TextRepresentable) object).toText();
                }
                rawArguments[i] = ((LanternTextSerializer) TextSerializers.LEGACY_FORMATTING_CODE)
                        .serialize((Text) object, locale);
            } else {
                rawArguments[i] = object.toString();
            }
        }
        final String content = src.getTranslation().get(locale, rawArguments);
        return JsonTextLiteralSerializer.serializeLiteralText(src, content, context, this.removeComplexity);
    }
    final JsonObject obj = new JsonObject();
    obj.addProperty(TRANSLATABLE, src.getTranslation().getId());
    final ImmutableList<Object> arguments = src.getArguments();
    if (!arguments.isEmpty()) {
        final JsonArray argumentsArray = new JsonArray();
        for (Object object : arguments) {
            // Only primitive strings and text json is allowed,
            // so we need to convert the objects if possible
            if (object instanceof TextRepresentable) {
                if (!(object instanceof Text)) {
                    object = ((TextRepresentable) object).toText();
                }
                argumentsArray.add(context.serialize(object, Text.class));
            } else {
                argumentsArray.add(new JsonPrimitive(object.toString()));
            }
        }
        obj.add(TRANSLATABLE_ARGS, argumentsArray);
    }
    serialize(obj, src, context);
    return obj;
}

From source file:net.tzolov.geode.jmx.JmxInfluxLoader.java

private String[] attributeNames(MBeanServerConnection connection, String objectName,
        MBeanAttributeInfoFilter attributeFilter) {

    try {//from  w  w w . ja  va2 s  .co  m
        ImmutableList.Builder<String> builder = ImmutableList.builder();
        for (MBeanAttributeInfo attr : connection.getMBeanInfo(new ObjectName(objectName)).getAttributes()) {
            if (!attributeFilter.filter(attr)) {
                builder.add(attr.getName());
            }
        }
        ImmutableList<String> names = builder.build();
        return names.toArray(new String[names.size()]);
    } catch (Exception ex) {
        throw new RuntimeException((ex));
    }
}

From source file:org.fcrepo.auth.xacml.XACMLWorkspaceInitializer.java

private void registerNodeTypes() {
    Session session = null;//w  ww . j av a 2  s.  c om
    try {
        session = getJcrSession(sessionFactory.getInternalSession());
        final NodeTypeManager mgr = (NodeTypeManager) session.getWorkspace().getNodeTypeManager();
        final URL cnd = XACMLWorkspaceInitializer.class.getResource("/cnd/xacml-policy.cnd");
        final NodeTypeIterator nti = mgr.registerNodeTypes(cnd, true);
        while (nti.hasNext()) {
            final NodeType nt = nti.nextNodeType();
            LOGGER.debug("registered node type: {}", nt.getName());
        }

        // Add "authz:xacmlAssignable" mixin to "fedora:Resource" type
        final NodeType nodeType = mgr.getNodeType("fedora:Resource");
        final NodeTypeTemplate nodeTypeTemplate = mgr.createNodeTypeTemplate(nodeType);
        final String[] superTypes = nodeType.getDeclaredSupertypeNames();
        final ImmutableList.Builder<String> listBuilder = ImmutableList.builder();
        listBuilder.add(superTypes);
        listBuilder.add("authz:xacmlAssignable");
        final ImmutableList<String> newSuperTypes = listBuilder.build();
        nodeTypeTemplate.setDeclaredSuperTypeNames(newSuperTypes.toArray(new String[newSuperTypes.size()]));

        mgr.registerNodeType(nodeTypeTemplate, true);

        session.save();
        LOGGER.debug("Registered XACML policy node types");
    } catch (final RepositoryException | IOException e) {
        throw new Error("Cannot register XACML policy node types", e);
    } finally {
        if (session != null) {
            session.logout();
        }
    }
}

From source file:com.google.devtools.build.benchmark.BazelBuilder.java

private ImmutableList<String> getListOfOutputFromCommandWithAdditionalParam(
        ImmutableList<String> additionalParam, String... command) throws CommandException {
    ImmutableList<String> commandList = ImmutableList.<String>builder().add(command).addAll(additionalParam)
            .build();/*from   ww  w  .j av a 2 s.c o m*/
    String[] finalCommand = commandList.toArray(new String[0]);

    return getListOfOutputFromCommand(finalCommand);
}

From source file:com.facebook.buck.util.ClassLoaderCache.java

public synchronized ClassLoader getClassLoaderForClassPath(@Nullable ClassLoader parentClassLoader,
        ImmutableList<URL> classPath) {

    Map<ImmutableList<URL>, ClassLoader> cacheForParent = getCacheForParent(parentClassLoader);

    ClassLoader classLoader = cacheForParent.get(classPath);
    if (classLoader == null) {
        URL[] urls = classPath.toArray(new URL[classPath.size()]);
        classLoader = new URLClassLoader(urls, parentClassLoader);
        cacheForParent.put(classPath, classLoader);
    }/*  w  w w .  ja va 2 s.  c  o m*/

    return classLoader;
}

From source file:com.qubole.presto.udfs.sqlFunction.hiveUdfs.Nvl.java

@Override
public ScalarFunctionImplementation specialize(Map<String, Type> types, int arity, TypeManager typeManager,
        FunctionRegistry functionRegistry) {
    if (arity != 2) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "There must be two arguments");
    }//from w  w  w  . j  av a2s.  c  o m
    Type type = types.get("T");
    ImmutableList.Builder<Class<?>> builder = ImmutableList.builder();
    if (type.getJavaType() == long.class) {
        builder.add(Long.class);
        builder.add(Long.class);
    } else if (type.getJavaType() == double.class) {
        builder.add(Double.class);
        builder.add(Double.class);
    } else if (type.getJavaType() == boolean.class) {
        builder.add(Boolean.class);
        builder.add(Boolean.class);
    } else {
        builder.add(type.getJavaType());
        builder.add(type.getJavaType());
    }

    ImmutableList<Class<?>> stackTypes = builder.build();
    Class<?> clazz = ifNull(stackTypes);
    MethodHandle nvlMethodHandle = methodHandle(clazz, "nvl",
            stackTypes.toArray(new Class<?>[stackTypes.size()]));

    return new ScalarFunctionImplementation(true, ImmutableList.of(true, true), nvlMethodHandle,
            isDeterministic());
}

From source file:com.qubole.presto.udfs.sqlFunction.hiveUdfs.Hash.java

@Override
public ScalarFunctionImplementation specialize(Map<String, Type> types, int arity, TypeManager typeManager,
        FunctionRegistry functionRegistry) {
    Type type = types.get("E");

    // the argument need not be orderable, so no orderable check
    ImmutableList.Builder<Class<?>> builder = ImmutableList.builder();
    for (int i = 0; i < arity; i++) {
        builder.add(type.getJavaType());
    }//from   w  w  w  .j a  v  a2s .co  m

    ImmutableList<Class<?>> stackTypes = builder.build();
    Class<?> clazz = generateHash(stackTypes, type);
    MethodHandle methodHandle = methodHandle(clazz, "hash",
            stackTypes.toArray(new Class<?>[stackTypes.size()]));
    List<Boolean> nullableParameters = ImmutableList.copyOf(Collections.nCopies(stackTypes.size(), false));

    return new ScalarFunctionImplementation(false, nullableParameters, methodHandle, isDeterministic());
}

From source file:com.facebook.presto.operator.scalar.Least.java

@Override
public FunctionInfo specialize(Map<String, Type> types, int arity, TypeManager typeManager,
        FunctionRegistry functionRegistry) {
    Type type = types.get("E");
    checkArgument(type.isOrderable(), "Type must be orderable");

    ImmutableList.Builder<Class<?>> builder = ImmutableList.builder();
    for (int i = 0; i < arity; i++) {
        builder.add(type.getJavaType());
    }/*from w  ww  .ja  v a 2 s.co  m*/
    ImmutableList<Class<?>> stackTypes = builder.build();

    Class<?> clazz = generateLeast(stackTypes, type);
    MethodHandle methodHandle = methodHandle(clazz, "least",
            stackTypes.toArray(new Class<?>[stackTypes.size()]));
    List<Boolean> nullableParameters = ImmutableList.copyOf(Collections.nCopies(stackTypes.size(), false));

    Signature specializedSignature = internalFunction(SIGNATURE.getName(), type.getTypeSignature(),
            Collections.nCopies(arity, type.getTypeSignature()));
    return new FunctionInfo(specializedSignature, getDescription(), isHidden(), methodHandle, isDeterministic(),
            false, nullableParameters);
}