List of usage examples for com.google.common.collect ImmutableList toArray
<T> T[] toArray(T[] a);
From source file:com.facebook.presto.operator.scalar.ArrayConstructor.java
@Override public ScalarFunctionImplementation specialize(Map<String, Type> types, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { checkArgument(types.size() == 1, "Can only construct arrays from exactly matching types"); ImmutableList.Builder<Class<?>> builder = ImmutableList.builder(); Type type = types.get("E"); for (int i = 0; i < arity; i++) { if (type.getJavaType().isPrimitive()) { builder.add(Primitives.wrap(type.getJavaType())); } else {/*from ww w .ja v a 2 s . c o m*/ builder.add(type.getJavaType()); } } ImmutableList<Class<?>> stackTypes = builder.build(); Class<?> clazz = generateArrayConstructor(stackTypes, type); MethodHandle methodHandle; try { Method method = clazz.getMethod("arrayConstructor", stackTypes.toArray(new Class<?>[stackTypes.size()])); methodHandle = lookup().unreflect(method); } catch (ReflectiveOperationException e) { throw Throwables.propagate(e); } List<Boolean> nullableParameters = ImmutableList.copyOf(Collections.nCopies(stackTypes.size(), true)); return new ScalarFunctionImplementation(false, nullableParameters, methodHandle, isDeterministic()); }
From source file:com.google.devtools.build.lib.analysis.mock.BazelAnalysisMock.java
@Override public void setupMockClient(MockToolsConfig config) throws IOException { String bazelToolWorkspace = config.getPath("/bazel_tools_workspace").getPathString(); ArrayList<String> workspaceContents = new ArrayList<>( ImmutableList.of("local_repository(name = 'bazel_tools', path = '" + bazelToolWorkspace + "')", "local_repository(name = 'local_config_xcode', path = '/local_config_xcode')", "bind(", " name = 'objc_proto_lib',", " actual = '//objcproto:ProtocolBuffers_lib',", ")", "bind(", " name = 'objc_protobuf_lib',", " actual = '//objcproto:protobuf_lib',", ")", "bind(name = 'android/sdk', actual='@bazel_tools//tools/android:sdk')", "bind(name = 'tools/python', actual='//tools/python')")); config.create("/local_config_xcode/BUILD", "xcode_config(name = 'host_xcodes')"); config.overwrite("WORKSPACE", workspaceContents.toArray(new String[workspaceContents.size()])); config.create("/bazel_tools_workspace/WORKSPACE", "workspace(name = 'bazel_tools')"); config.create("/bazel_tools_workspace/tools/jdk/BUILD", "package(default_visibility=['//visibility:public'])", "java_toolchain(", " name = 'toolchain',", " encoding = 'UTF-8',", " source_version = '8',", " target_version = '8',", " bootclasspath = [':bootclasspath'],", " extclasspath = [':extclasspath'],", " javac = [':langtools'],", " javabuilder = ['JavaBuilder_deploy.jar'],", " header_compiler = ['turbine_deploy.jar'],", " singlejar = ['SingleJar_deploy.jar'],", " genclass = ['GenClass_deploy.jar'],", " ijar = ['ijar'],", ")", "filegroup(name = 'jdk-null')", "filegroup(name = 'jdk-default', srcs = [':java'], path = 'jdk/jre')", "filegroup(name = 'jdk', srcs = [':jdk-default', ':jdk-null'])", "filegroup(name='langtools', srcs=['jdk/lib/tools.jar'])", "filegroup(name='bootclasspath', srcs=['jdk/jre/lib/rt.jar'])", "filegroup(name='extdir', srcs=glob(['jdk/jre/lib/ext/*']))", // "dummy" is needed so that RedirectChaser stops here "filegroup(name='java', srcs = ['jdk/jre/bin/java', 'dummy'])", "filegroup(name='JacocoCoverage', srcs = [])", "filegroup(name='jacoco-blaze-agent', srcs = [])", "exports_files(['JavaBuilder_deploy.jar','SingleJar_deploy.jar','TestRunner_deploy.jar',", " 'JavaBuilderCanary_deploy.jar', 'ijar', 'GenClass_deploy.jar',", " 'turbine_deploy.jar'])"); ImmutableList<String> androidBuildContents = createAndroidBuildContents(); config.create("/bazel_tools_workspace/tools/android/BUILD", androidBuildContents.toArray(new String[androidBuildContents.size()])); config.create("/bazel_tools_workspace/tools/genrule/BUILD", "exports_files(['genrule-setup.sh'])"); config.create("/bazel_tools_workspace/third_party/java/jarjar/BUILD", "package(default_visibility=['//visibility:public'])", "licenses(['notice'])", "java_binary(name = 'jarjar_bin',", " runtime_deps = [ ':jarjar_import' ],", " main_class = 'com.tonicsystems.jarjar.Main')", "java_import(name = 'jarjar_import',", " jars = [ 'jarjar.jar' ])"); config.create("/bazel_tools_workspace/tools/test/BUILD", "filegroup(name = 'runtime', srcs = ['test-setup.sh'],)", "filegroup(name='coverage_support', srcs=['collect_coverage.sh',':LcovMerger_deploy.jar'])", "filegroup(name = 'coverage_report_generator', srcs = ['coverage_report_generator.sh'])"); config.create("/bazel_tools_workspace/tools/python/BUILD", "package(default_visibility=['//visibility:public'])", "exports_files(['precompile.py'])", "sh_binary(name='2to3', srcs=['2to3.sh'])"); config.create("/bazel_tools_workspace/tools/zip/BUILD", "package(default_visibility=['//visibility:public'])", "exports_files(['precompile.py'])", "cc_binary(name='zipper', srcs=['zip_main.cc'])"); ccSupport().setup(config);//ww w . j av a2s.co m }
From source file:io.prestosql.operator.scalar.ArrayConstructor.java
@Override public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Map<String, Type> types = boundVariables.getTypeVariables(); checkArgument(types.size() == 1, "Can only construct arrays from exactly matching types"); ImmutableList.Builder<Class<?>> builder = ImmutableList.builder(); Type type = types.get("E"); for (int i = 0; i < arity; i++) { if (type.getJavaType().isPrimitive()) { builder.add(Primitives.wrap(type.getJavaType())); } else {/* ww w . j a va 2 s . c o m*/ builder.add(type.getJavaType()); } } ImmutableList<Class<?>> stackTypes = builder.build(); Class<?> clazz = generateArrayConstructor(stackTypes, type); MethodHandle methodHandle; try { Method method = clazz.getMethod("arrayConstructor", stackTypes.toArray(new Class<?>[stackTypes.size()])); methodHandle = lookup().unreflect(method); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } return new ScalarFunctionImplementation(false, nCopies(stackTypes.size(), valueTypeArgumentProperty(USE_BOXED_TYPE)), methodHandle, isDeterministic()); }
From source file:com.palantir.docker.compose.execution.DefaultDockerCompose.java
private String[] constructFullDockerComposeRunArguments(DockerComposeRunOption dockerComposeRunOption, String containerName, DockerComposeRunArgument dockerComposeRunArgument) { ImmutableList<String> fullArgs = new ImmutableList.Builder<String>().add("run") .addAll(dockerComposeRunOption.options()).add(containerName) .addAll(dockerComposeRunArgument.arguments()).build(); return fullArgs.toArray(new String[fullArgs.size()]); }
From source file:com.palantir.docker.compose.execution.DefaultDockerCompose.java
private String[] constructFullDockerComposeExecArguments(DockerComposeExecOption dockerComposeExecOption, String containerName, DockerComposeExecArgument dockerComposeExecArgument) { ImmutableList<String> fullArgs = new ImmutableList.Builder<String>().add("exec") .addAll(dockerComposeExecOption.options()).add(containerName) .addAll(dockerComposeExecArgument.arguments()).build(); return fullArgs.toArray(new String[fullArgs.size()]); }
From source file:de.gfelbing.microservice.core.http.jetty.server.JettyServer.java
/** * Constructor creating a jetty server and initializes a ContextHandlerCollection, * which can be filled by addHandler()./*ww w . j av a2 s .c om*/ * * @param hosts IPs / Hostnames jetty will bind itself to. * @param port Port to which the jetty server will bind itself. */ public JettyServer(final ImmutableList<String> hosts, final Integer port) { this.healthState = new AtomicReference<>(State.CREATED); this.server = new Server(); final ImmutableList<Connector> connectors = hosts.stream().map(host -> { ServerConnector connector = new ServerConnector(server); connector.setHost(host); connector.setPort(port); return connector; }).collect(GuavaCollect.immutableList()); this.server.setConnectors(connectors.toArray(new Connector[connectors.size()])); this.contextHandler = new ContextHandlerCollection(); this.server.setHandler(contextHandler); }
From source file:org.eclipse.buildship.core.workspace.internal.DefaultWorkspaceOperations.java
@Override public void addNature(IProject project, String natureId, IProgressMonitor monitor) { SubMonitor progress = SubMonitor.convert(monitor, 1); try {//from w ww .j av a 2s. c o m // get the description IProjectDescription description = project.getDescription(); // abort if the project already has the nature applied or the nature is not defined List<String> currentNatureIds = ImmutableList.copyOf(description.getNatureIds()); if (currentNatureIds.contains(natureId) || !isNatureRecognizedByEclipse(natureId)) { return; } // add the nature to the project ImmutableList<String> newIds = ImmutableList.<String>builder().addAll(currentNatureIds).add(natureId) .build(); description.setNatureIds(newIds.toArray(new String[newIds.size()])); // save the updated description project.setDescription(description, progress.newChild(1)); } catch (CoreException e) { String message = String.format("Cannot add nature %s to Eclipse project %s.", natureId, project.getName()); throw new GradlePluginsRuntimeException(message, e); } }
From source file:org.kiji.maven.plugins.BentoCluster.java
/** * Execute command to start the Bento cluster container within a timeout. * * @param configDir to write bento hadoop/hbase configuration files to. * @param createBento should be set to false to skip creating the bento container. * @param platformVersion is the optional version of the hadoop/hbase stack to run in the bento * cluster./*from w ww .j av a 2 s. c o m*/ * @param pypiRepository is the optional address or name of the pypi repository to install * kiji-bento-cluster from. * @param timeoutMillis is the optional override for the amount of time to wait in milliseconds * for the bento cluster to start. * @param pollIntervalMillis is the optional override for the amount of time to wait in * milliseconds between checks to see if the bento cluster has started. * @throws java.io.IOException if there is an error calling the bento executable. * @throws java.util.concurrent.ExecutionException if there is an error calling the bento * executable. */ public void start(final File configDir, final boolean createBento, final Optional<String> platformVersion, final Optional<String> pypiRepository, final Optional<Long> timeoutMillis, final Optional<Long> pollIntervalMillis) throws IOException, ExecutionException { Preconditions.checkState(!isRunning(), "Cluster already running: %s", this); mMavenLog.info(String.format("Starting the Bento cluster '%s'...", mBentoName)); final ImmutableList.Builder<String> commandsBuilder = ImmutableList.builder(); // If one doesn't exist already create a virtualenv for this cluster. if (!venvExists()) { commandsBuilder.add(String.format("env python3 -m venv %s", mVenvRoot.getAbsolutePath())); } // Setup the shell environment for the python virtual environment. commandsBuilder.add(sourceVenvCommand()); // Install bento-cluster in this virtualenv. if (pypiRepository.isPresent()) { commandsBuilder.add( String.format("env python3 -m pip install kiji-bento-cluster -i %s", pypiRepository.get())); } else { commandsBuilder.add("env python3 -m pip install kiji-bento-cluster"); } // Add a command to create the bento container. if (createBento) { final StringBuilder pullCommandBuilder = new StringBuilder("pull"); if (platformVersion.isPresent()) { pullCommandBuilder.append(" --platform-version=").append(platformVersion.get()); } commandsBuilder.add(bentoCommand(pullCommandBuilder.toString())); final StringBuilder createCommandBuilder = new StringBuilder("create").append(" --output-config-dir=") .append(configDir.getAbsolutePath()); if (platformVersion.isPresent()) { createCommandBuilder.append(" --platform-version=").append(platformVersion.get()); } commandsBuilder.add(bentoCommand(createCommandBuilder.toString())); } // Add a command to start the bento container. final StringBuilder startCommandBuilder = new StringBuilder("start").append(" --output-config-dir=") .append(configDir.getAbsolutePath()); if (timeoutMillis.isPresent()) { startCommandBuilder.append(" --timeout=").append(timeoutMillis.get()); } if (pollIntervalMillis.isPresent()) { startCommandBuilder.append(" --poll-interval=").append(pollIntervalMillis.get()); } commandsBuilder.add(bentoCommand(startCommandBuilder.toString())); // Run the commands. final ImmutableList<String> commands = commandsBuilder.build(); executeAndLogCommands(commands.toArray(new String[commands.size()])); // Ensure that the cluster has been started. Preconditions.checkState(isRunning(), "Bento cluster failed to start!"); }
From source file:org.apache.james.core.builder.MimeMessageBuilder.java
public MimeMessage build() throws MessagingException { Preconditions.checkState(!(text.isPresent() && content.isPresent()), "Can not get at the same time a text and a content"); MimeMessage mimeMessage = new MimeMessage(Session.getInstance(new Properties())); if (text.isPresent()) { mimeMessage.setContent(text.get(), textContentType.orElse(DEFAULT_TEXT_PLAIN_UTF8_TYPE)); }// w ww. jav a 2s .c o m if (content.isPresent()) { mimeMessage.setContent(content.get()); } if (sender.isPresent()) { mimeMessage.setSender(sender.get()); } if (subject.isPresent()) { mimeMessage.setSubject(subject.get()); } ImmutableList<InternetAddress> fromAddresses = from.build(); if (!fromAddresses.isEmpty()) { mimeMessage.addFrom(fromAddresses.toArray(new InternetAddress[fromAddresses.size()])); } List<InternetAddress> toAddresses = to.build(); if (!toAddresses.isEmpty()) { mimeMessage.setRecipients(Message.RecipientType.TO, toAddresses.toArray(new InternetAddress[toAddresses.size()])); } List<InternetAddress> ccAddresses = cc.build(); if (!ccAddresses.isEmpty()) { mimeMessage.setRecipients(Message.RecipientType.CC, ccAddresses.toArray(new InternetAddress[ccAddresses.size()])); } List<InternetAddress> bccAddresses = bcc.build(); if (!bccAddresses.isEmpty()) { mimeMessage.setRecipients(Message.RecipientType.BCC, bccAddresses.toArray(new InternetAddress[bccAddresses.size()])); } MimeMessage wrappedMessage = MimeMessageWrapper.wrap(mimeMessage); List<Header> headerList = headers.build(); for (Header header : headerList) { if (header.name.equals("Message-ID") || header.name.equals("Date")) { wrappedMessage.setHeader(header.name, header.value); } else { wrappedMessage.addHeader(header.name, header.value); } } wrappedMessage.saveChanges(); return wrappedMessage; }
From source file:org.kiji.maven.plugins.BentoCluster.java
/** * Execute command to stop the Bento cluster container. Wait uninterruptibly until the shell * command returns.//from w w w. j a va2 s . co m * * @param deleteBento should be set to false to skip deleting the bento container. * @param timeoutMillis is the optional override for the amount of time to wait in milliseconds * for the bento cluster to stop. * @param pollIntervalMillis is the optional override for the amount of time to wait in * milliseconds between checks to see if the bento cluster has stopped. * @throws java.io.IOException if there is an error calling the bento executable. * @throws java.util.concurrent.ExecutionException if there is an error calling the bento * executable. */ public void stop(final boolean deleteBento, final Optional<Long> timeoutMillis, final Optional<Long> pollIntervalMillis) throws IOException, ExecutionException { if (!isRunning()) { mMavenLog.error("Attempting to shut down a Bento cluster container, but none running."); return; } final ImmutableList.Builder<String> commandsBuilder = ImmutableList.builder(); // Add a command to activate the python virtual environment for this plugin. commandsBuilder.add(sourceVenvCommand()); // Add a command to stop the bento cluster. final StringBuilder stopCommandBuilder = new StringBuilder("stop"); if (timeoutMillis.isPresent()) { stopCommandBuilder.append(" --timeout=").append(timeoutMillis.get()); } if (pollIntervalMillis.isPresent()) { stopCommandBuilder.append(" --poll-interval").append(pollIntervalMillis.get()); } commandsBuilder.add(bentoCommand(stopCommandBuilder.toString())); // Add a command to delete the bento cluster. if (deleteBento) { commandsBuilder.add(bentoCommand("rm")); } // Run the commands. final ImmutableList<String> commands = commandsBuilder.build(); mMavenLog.info(String.format("Stopping the Bento cluster '%s'...", mBentoName)); executeAndLogCommands(commands.toArray(new String[commands.size()])); }