List of usage examples for com.google.common.collect ImmutableList.Builder addAll
boolean addAll(Collection<? extends E> c);
From source file:io.brooklyn.ambari.EtcHostsManager.java
public static void setHostsOnMachines(Iterable<? extends Entity> machines, AttributeSensor<String> addressSensor) { Map<String, String> mapping = gatherIpHostnameMapping(machines, addressSensor); for (Entity e : machines) { Maybe<SshMachineLocation> sshLocation = Machines.findUniqueSshMachineLocation(e.getLocations()); if (!sshLocation.isPresentAndNonNull()) { LOG.debug("{} has no {}, not setting hostname or updating /etc/hosts", e, SshMachineLocation.class); continue; }/*from w w w.j a va 2 s . co m*/ SshMachineLocation loc = sshLocation.get(); ImmutableList.Builder<String> commands = ImmutableList.builder(); // It would be great if we could use BashCommands.setHostname(), but it doesn't quite do what we need: it // maps the hostname to 127.0.0.1. But this then means that e.g. "ping myhostname" pings 127.0.0.1, and that // behaviour causes some processes to bind ports to 127.0.0.1 instead of 0.0.0.0. What we need instead is // that the first line maps the hostname to its actual IP address. So we partly override the behaviour of // this method later by pre-pending to /etc/hosts. // Find and set entity's own hostname Maybe<String> ip = Machines.findSubnetOrPrivateIp(e); String key = e.getAttribute(addressSensor); if (ip.isAbsentOrNull()) { LOG.debug("{} has no IP address, not setting hostname", e); continue; } else if (!mapping.containsKey(key)) { LOG.debug("{} has no hostname mapping, not setting hostname", e); } else { commands.addAll(BashCommands.setHostname(mapping.get(key))); } // Add the other entity's details to /etc/hosts for (Map.Entry<String, String> entry : mapping.entrySet()) { boolean isMyOwnEntry = entry.getKey().equals(key); String fqdn = entry.getValue(); if (fqdn.endsWith(".")) fqdn = fqdn.substring(0, fqdn.length() - 1); int dotAt = fqdn.indexOf('.'); String[] values = dotAt > 0 ? new String[] { fqdn, fqdn.substring(0, dotAt) } : new String[] { fqdn }; if (isMyOwnEntry) commands.add(prependToEtcHosts(ip.get(), values)); else commands.add(appendToEtcHosts(entry.getKey(), values)); } // Ensure that 127.0.0.1 maps to localhost, and nothing else String bakFileExtension = "bak" + Identifiers.makeRandomId(4); commands.add(sudo( "sed -i." + bakFileExtension + " -e \'s/127.0.0.1\\s.*/127.0.0.1 localhost/\' /etc/hosts")); loc.execCommands("set hostname and fill /etc/hosts", commands.build()); } }
From source file:edu.bsu.cybersec.core.ui.LoadingScreen.java
private void startLoadingSounds() { List<RFuture<Sound>> sounds = Lists.newArrayList(); ImmutableList.Builder<Sound> allSoundsBuilder = new ImmutableList.Builder<>(); allSoundsBuilder.addAll(MusicCache.instance().all()); allSoundsBuilder.addAll(SfxCache.instance().all()); for (Sound sound : allSoundsBuilder.build()) { sounds.add(sound.state);/*from www.j a v a 2s . co m*/ sound.state.onComplete(new Slot<Try<Sound>>() { @Override public void onEmit(Try<Sound> event) { progressBar.increment(); } }); } RFuture.collect(sounds).onComplete(new Slot<Try<Collection<Sound>>>() { @Override public void onEmit(Try<Collection<Sound>> event) { if (event.isFailure()) { game().plat.log().warn("Failed to load a sound: " + event); } else { countDown(); } } }); }
From source file:com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.MipsCrosstools.java
ImmutableList<CToolchain.Builder> createCrosstools() { ImmutableList.Builder<CToolchain.Builder> toolchains = ImmutableList.builder(); toolchains.addAll(createMips64Toolchains()); toolchains.addAll(createMipsToolchains()); return toolchains.build(); }
From source file:org.softao.jassandra.Column.java
/** * Gets the columns.// www. j a v a 2 s .co m * * @return the columns * @throws JassandraException * the jassandra exception */ @Override public List<IColumn> getColumns() throws JassandraException { if (!isSuper()) { throw new JassandraException("Only super column supports getColumns."); } ImmutableList.Builder<IColumn> builder = ImmutableList.builder(); builder.addAll(mColumns); return builder.build(); }
From source file:com.yahoo.yqlplus.engine.internal.generate.StructGenerator.java
private void implementRecord() { MethodGenerator fieldNamesGenerator = createMethod("getAllFieldNames"); ImmutableList.Builder<String> fieldNames = ImmutableList.builder(); fieldNames.addAll(fields.keySet()); BytecodeExpression expr = constant(fieldNames.build()); fieldNamesGenerator.setReturnType(getValueTypeAdapter().adaptInternal(new TypeLiteral<Iterable<String>>() { }));//from www. j av a 2s . c o m fieldNamesGenerator.add(expr); fieldNamesGenerator.add(new ReturnCode(Opcodes.ARETURN)); // Object get(String field); generateGetMethod(); // void put(String field, Object value); generatePutMethod(); // generate equals() and hashCode and hashValue(byte[] ...) }
From source file:com.facebook.buck.features.lua.LuaStandaloneBinary.java
@Override public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) { ImmutableList.Builder<Step> steps = ImmutableList.builder(); buildableContext.recordArtifact(output); // Make sure the parent directory exists. steps.add(MkdirStep.of(BuildCellRelativePath.fromCellRelativePath(context.getBuildCellRootPath(), getProjectFilesystem(), output.getParent()))); // Delete any other pex that was there (when switching between pex styles). steps.add(RmStep.of(BuildCellRelativePath.fromCellRelativePath(context.getBuildCellRootPath(), getProjectFilesystem(), output)).withRecursive(true)); SourcePathResolver resolver = context.getSourcePathResolver(); steps.add(new ShellStep(getProjectFilesystem().getRootPath()) { @Override/*from w ww .j a v a 2 s . c om*/ protected Optional<String> getStdin(ExecutionContext context) { try { return Optional.of(ObjectMappers.WRITER.writeValueAsString(ImmutableMap.of("modules", Maps.transformValues(components.getModules(), Functions.compose(Object::toString, resolver::getAbsolutePath)), "pythonModules", Maps.transformValues(components.getPythonModules(), Functions.compose(Object::toString, resolver::getAbsolutePath)), "nativeLibraries", Maps.transformValues(components.getNativeLibraries(), Functions.compose(Object::toString, resolver::getAbsolutePath))))); } catch (IOException e) { throw new RuntimeException(e); } } @Override protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) { ImmutableList.Builder<String> command = ImmutableList.builder(); command.addAll(builder.getCommandPrefix(resolver)); command.addAll(builderArgs); command.add("--entry-point", mainModule); command.add("--interpreter"); if (starter.isPresent()) { command.add(resolver.getAbsolutePath(starter.get()).toString()); } else { command.add(lua.getCommandPrefix(resolver).get(0)); } command.add(getProjectFilesystem().resolve(output).toString()); return command.build(); } @Override public String getShortName() { return "lua_package"; } }); return steps.build(); }
From source file:com.facebook.presto.hive.HiveUtil.java
public static List<HiveColumnHandle> hiveColumnHandles(String connectorId, Table table) { ImmutableList.Builder<HiveColumnHandle> columns = ImmutableList.builder(); // add the data fields first int hiveColumnIndex = 0; for (FieldSchema field : table.getSd().getCols()) { // ignore unsupported types rather than failing TypeInfo typeInfo = getTypeInfoFromTypeString(field.getType()); if (HiveType.isSupportedType(typeInfo)) { HiveType hiveType = toHiveType(typeInfo); columns.add(new HiveColumnHandle(connectorId, field.getName(), hiveType, hiveType.getTypeSignature(), hiveColumnIndex, false)); }/*from w ww . j a va 2 s . c o m*/ hiveColumnIndex++; } // add the partition keys last (like Hive does) columns.addAll(getPartitionKeyColumnHandles(connectorId, table)); return columns.build(); }
From source file:blusunrize.immersiveengineering.client.models.multilayer.BakedMultiLayerModel.java
@Nonnull @Override//from w w w . ja va2 s . c o m public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) { BlockRenderLayer current = MinecraftForgeClient.getRenderLayer(); if (current == null) { ImmutableList.Builder<BakedQuad> ret = new Builder<>(); for (List<IBakedModel> forLayer : models.values()) for (IBakedModel model : forLayer) ret.addAll(model.getQuads(state, side, rand)); return ret.build(); } else if (models.containsKey(current)) { ImmutableList.Builder<BakedQuad> ret = new Builder<>(); for (IBakedModel model : models.get(current)) ret.addAll(model.getQuads(state, side, rand)); return ret.build(); } else return ImmutableList.of(); }
From source file:io.prestosql.plugin.raptor.legacy.metadata.ShardPredicate.java
private static String createShardPredicate(ImmutableList.Builder<JDBCType> types, ImmutableList.Builder<Object> values, Domain domain, JDBCType jdbcType) { List<Range> ranges = domain.getValues().getRanges().getOrderedRanges(); // only apply predicates if all ranges are single values if (ranges.isEmpty() || !ranges.stream().allMatch(Range::isSingleValue)) { return "true"; }//from w w w . java 2 s . co m ImmutableList.Builder<Object> valuesBuilder = ImmutableList.builder(); ImmutableList.Builder<JDBCType> typesBuilder = ImmutableList.builder(); StringJoiner rangePredicate = new StringJoiner(" OR "); for (Range range : ranges) { Slice uuidText = (Slice) range.getSingleValue(); try { Slice uuidBytes = uuidStringToBytes(uuidText); typesBuilder.add(jdbcType); valuesBuilder.add(uuidBytes); } catch (IllegalArgumentException e) { return "true"; } rangePredicate.add("shard_uuid = ?"); } types.addAll(typesBuilder.build()); values.addAll(valuesBuilder.build()); return rangePredicate.toString(); }
From source file:com.facebook.buck.rust.RustCompile.java
@Override public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) { ImmutableMap.Builder<String, Path> externalCratesBuilder = ImmutableMap.builder(); ImmutableSet.Builder<Path> externalDepsBuilder = ImmutableSet.builder(); buildableContext.recordArtifact(output); for (BuildRule buildRule : getDeps()) { if (buildRule instanceof RustLinkable) { RustLinkable linkable = (RustLinkable) buildRule; Path ruleOutput = linkable.getLinkPath(); externalCratesBuilder.put(linkable.getLinkTarget(), ruleOutput); externalDepsBuilder.addAll(linkable.getDependencyPaths()); }/*from www . ja v a 2s .c om*/ } Tool compiler = this.compiler.get(); ImmutableList.Builder<String> linkerArgs = ImmutableList.builder(); linkerArgs.addAll(linker.get().getCommandPrefix(getResolver())); linkerArgs.addAll(this.linkerArgs); SourcePathResolver resolver = getResolver(); return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir), new SymlinkFilesIntoDirectoryStep(getProjectFilesystem(), getProjectFilesystem().getRootPath(), srcs.stream().map(resolver::getRelativePath).collect(MoreCollectors.toImmutableList()), scratchDir), new MakeCleanDirectoryStep(getProjectFilesystem(), output.getParent()), new RustCompileStep(getProjectFilesystem().getRootPath(), compiler.getEnvironment(), compiler.getCommandPrefix(getResolver()), linkerArgs.build(), flags, features, output, externalCratesBuilder.build(), externalDepsBuilder.build(), nativePaths, getCrateRoot())); }