List of usage examples for com.google.common.collect ImmutableList get
E get(int index);
From source file:com.spectralogic.ds3autogen.c.helpers.StructHelper.java
public static String generateResponseAttributesParser(final String structName, final ImmutableList<StructMember> structMembers) throws ParseException { boolean firstElement = true; final StringBuilder outputBuilder = new StringBuilder(); for (int structMemberIndex = 0; structMemberIndex < structMembers.size(); structMemberIndex++) { final StructMember currentStructMember = structMembers.get(structMemberIndex); if (!currentStructMember.isAttribute()) continue; // only parsing attributes for a specific node outputBuilder.append(indent(2)); if (!firstElement) { outputBuilder.append("} else "); } else {//w ww . j a v a 2 s. c o m firstElement = false; } outputBuilder.append("if (attribute_equal(attribute, \"") .append(Helper.capFirst(currentStructMember.getNameToMarshall())).append("\") == true) {") .append("\n"); outputBuilder.append(StructMemberHelper.getParseStructMemberAttributeBlock(currentStructMember)); } outputBuilder.append(indent(2)).append("} else {").append("\n"); outputBuilder.append(indent(3)).append("ds3_log_message(client->log, DS3_ERROR, \"Unknown attribute[%s] of " + structName + " [%s]\\n\", attribute->name, root->name);").append("\n"); outputBuilder.append(indent(2)).append("}").append("\n"); outputBuilder.append("\n"); outputBuilder.append(indent(2)).append("if (error != NULL) {\n"); outputBuilder.append(indent(3)).append("break;\n"); outputBuilder.append(indent(2)).append("}\n"); return outputBuilder.toString(); }
From source file:com.spectralogic.ds3autogen.c.helpers.StructHelper.java
public static String generateResponseParser(final String structName, final ImmutableList<StructMember> structMembers) throws ParseException { boolean firstElement = true; final StringBuilder outputBuilder = new StringBuilder(); for (int structMemberIndex = 0; structMemberIndex < structMembers.size(); structMemberIndex++) { final StructMember currentStructMember = structMembers.get(structMemberIndex); if (currentStructMember.isAttribute()) continue; // only parsing child nodes for a specific node if (currentStructMember.getName().startsWith("num_")) continue; // skip - these are used for array iteration and are not a part of the response if (currentStructMember.getName().equals("paging")) continue; // skip - parsed from pagination headers outputBuilder.append(indent(2)); if (!firstElement) { outputBuilder.append("} else "); } else {/*from w w w . j a v a2s. c o m*/ firstElement = false; } outputBuilder.append("if (element_equal(child_node, \"").append(getXmlTag(currentStructMember)) .append("\")) {").append("\n"); outputBuilder.append(StructMemberHelper.getParseStructMemberBlock(currentStructMember)); } outputBuilder.append(indent(2)).append("} else {").append("\n"); outputBuilder.append(indent(3)).append("ds3_log_message(client->log, DS3_ERROR, \"Unknown node[%s] of " + structName + " [%s]\\n\", child_node->name, root->name);").append("\n"); outputBuilder.append(indent(2)).append("}").append("\n"); outputBuilder.append("\n"); outputBuilder.append(indent(2)).append("if (error != NULL) {\n"); outputBuilder.append(indent(3)).append("break;\n"); outputBuilder.append(indent(2)).append("}\n"); return outputBuilder.toString(); }
From source file:com.facebook.buck.artifact_cache.ArtifactCaches.java
private static ArtifactCache newInstanceInternal(ArtifactCacheBuckConfig buckConfig, BuckEventBus buckEventBus, ProjectFilesystem projectFilesystem, Optional<String> wifiSsid, ListeningExecutorService httpWriteExecutorService, boolean distributedBuildModeEnabled) { ImmutableSet<ArtifactCacheBuckConfig.ArtifactCacheMode> modes = buckConfig.getArtifactCacheModes(); if (modes.isEmpty()) { return new NoopArtifactCache(); }/*from w w w. ja v a 2s.co m*/ ImmutableList.Builder<ArtifactCache> builder = ImmutableList.builder(); for (ArtifactCacheBuckConfig.ArtifactCacheMode mode : modes) { switch (mode) { case dir: builder.add(createDirArtifactCache(Optional.of(buckEventBus), buckConfig.getDirCache(), projectFilesystem)); break; case http: initializeDistributedCaches(buckConfig, buckEventBus, projectFilesystem, wifiSsid, httpWriteExecutorService, builder, distributedBuildModeEnabled, HTTP_PROTOCOL); break; case thrift_over_http: initializeDistributedCaches(buckConfig, buckEventBus, projectFilesystem, wifiSsid, httpWriteExecutorService, builder, distributedBuildModeEnabled, THRIFT_PROTOCOL); break; } } ImmutableList<ArtifactCache> artifactCaches = builder.build(); ArtifactCache result; if (artifactCaches.size() == 1) { // Don't bother wrapping a single artifact cache in MultiArtifactCache. result = artifactCaches.get(0); } else { result = new MultiArtifactCache(artifactCaches); } // Always support reading two-level cache stores (in case we performed any in the past). result = new TwoLevelArtifactCacheDecorator(result, projectFilesystem, buckEventBus, buckConfig.getTwoLevelCachingEnabled(), buckConfig.getTwoLevelCachingMinimumSize(), buckConfig.getTwoLevelCachingMaximumSize()); return result; }
From source file:org.locationtech.geogig.repository.NodeRef.java
/** * Remove the parent path from the given child path. * /*from w w w.j a v a 2 s . c o m*/ * @param parentPath the parent path to remove * @param childPath the child path to remove from * @return the stripped child path */ public static String removeParent(final String parentPath, final String childPath) { checkArgument(isChild(parentPath, childPath)); ImmutableList<String> parent = split(parentPath); ImmutableList<String> child = split(childPath); child = child.subList(parent.size(), child.size()); String strippedChildPath = child.get(0); for (int i = 1; i < child.size(); i++) { strippedChildPath = appendChild(strippedChildPath, child.get(i)); } return strippedChildPath; }
From source file:org.geogig.osm.internal.OSMUnmapOp.java
private static int getPropertyIndex(RevFeatureType type, String name) { ImmutableList<PropertyDescriptor> descriptors = type.descriptors(); for (int i = 0; i < descriptors.size(); i++) { if (descriptors.get(i).getName().getLocalPart().equals(name)) { return i; }// w w w.ja v a 2 s . c o m } // shouldn't reach this throw new RuntimeException("wrong field name"); }
From source file:org.lanternpowered.server.text.gson.JsonTextLiteralSerializer.java
static JsonElement serializeLiteralText(Text text, String content, JsonSerializationContext context, boolean removeComplexity) { final boolean noActionsAndStyle = areActionsAndStyleEmpty(text); final ImmutableList<Text> children = text.getChildren(); if (noActionsAndStyle) { if (children.isEmpty()) { return new JsonPrimitive(content); // Try to make the serialized text object less complex, // like text objects nested in a lot of other // text objects, this seems to happen a lot } else if (removeComplexity && content.isEmpty()) { if (children.size() == 1) { return context.serialize(children.get(0)); } else { return context.serialize(children); }/*from w w w . java2 s .co m*/ } } final JsonObject json = new JsonObject(); json.addProperty(TEXT, content); serialize(json, text, context); return json; }
From source file:com.sourceclear.headlines.util.HeaderBuilder.java
/** * @param values - list of String attribute values * @return formatted values//from w w w.j av a2 s .c om */ public static String formatListAttributeValues(ImmutableList<String> values) { // In the case of an empty map return the empty string: if (values.isEmpty()) { return ""; } StringBuilder sb = new StringBuilder(); // Outer loop - loop through each directive for (int i = 0; i < values.size(); i++) { // Don't add a directive if it has zero elements if (values.size() == 0) { continue; } //adding value of header attributes sb.append("'").append(values.get(i)).append("'"); // adding comma if list value isn't last if (values.size() > 1 && i < values.size() - 1) { sb.append(","); } } return sb.toString().trim(); }
From source file:org.apache.calcite.linq4j.Ord.java
/** * Iterates over a list in reverse order. * * <p>Given the list ["a", "b", "c"], returns (2, "c") then (1, "b") then * (0, "a")./*from ww w . jav a 2s.c om*/ */ public static <E> Iterable<Ord<E>> reverse(Iterable<? extends E> elements) { final ImmutableList<E> elementList = ImmutableList.copyOf(elements); return new Iterable<Ord<E>>() { public Iterator<Ord<E>> iterator() { return new Iterator<Ord<E>>() { int i = elementList.size() - 1; public boolean hasNext() { return i >= 0; } public Ord<E> next() { return Ord.of(i, elementList.get(i--)); } public void remove() { throw new UnsupportedOperationException("remove"); } }; } }; }
From source file:org.lanternpowered.server.text.FormattingCodeTextSerializer.java
private static StringBuilder to(Text text, Locale locale, StringBuilder builder, @Nullable Character colorCode, @Nullable ResolvedChatStyle current) { ResolvedChatStyle style = null;/*from w ww . j ava 2 s . c o m*/ if (colorCode != null) { style = resolve(current, text.getFormat()); if (current == null || (current.color != style.color) || (current.bold && !style.bold) || (current.italic && !style.italic) || (current.underlined && !style.underlined) || (current.strikethrough && !style.strikethrough) || (current.obfuscated && !style.obfuscated)) { if (style.color != null) { apply(builder, colorCode, ((FormattingCodeHolder) style.color).getCode()); } else if (current != null) { apply(builder, colorCode, TextConstants.RESET); } apply(builder, colorCode, TextConstants.BOLD, style.bold); apply(builder, colorCode, TextConstants.ITALIC, style.italic); apply(builder, colorCode, TextConstants.UNDERLINE, style.underlined); apply(builder, colorCode, TextConstants.STRIKETHROUGH, style.strikethrough); apply(builder, colorCode, TextConstants.OBFUSCATED, style.obfuscated); } else { apply(builder, colorCode, TextConstants.BOLD, current.bold != style.bold); apply(builder, colorCode, TextConstants.ITALIC, current.italic != style.italic); apply(builder, colorCode, TextConstants.UNDERLINE, current.underlined != style.underlined); apply(builder, colorCode, TextConstants.STRIKETHROUGH, current.strikethrough != style.strikethrough); apply(builder, colorCode, TextConstants.OBFUSCATED, current.obfuscated != style.obfuscated); } } if (text instanceof LiteralText) { builder.append(((LiteralText) text).getContent()); } else if (text instanceof SelectorText) { builder.append(((SelectorText) text).getSelector().toPlain()); } else if (text instanceof TranslatableText) { TranslatableText text0 = (TranslatableText) text; Translation translation = text0.getTranslation(); ImmutableList<Object> args = text0.getArguments(); Object[] args0 = new Object[args.size()]; for (int i = 0; i < args0.length; i++) { Object object = args.get(i); if (object instanceof Text || object instanceof Text.Builder || object instanceof TextRepresentable) { if (object instanceof Text) { // Ignore } else if (object instanceof Text.Builder) { object = ((Text.Builder) object).build(); } else { object = ((TextRepresentable) object).toText(); } args0[i] = to((Text) object, locale, new StringBuilder(), colorCode).toString(); } else { args0[i] = object; } } builder.append(translation.get(locale, args0)); } else if (text instanceof ScoreText) { ScoreText text0 = (ScoreText) text; Optional<String> override = text0.getOverride(); if (override.isPresent()) { builder.append(override.get()); } else { builder.append(text0.getScore().getScore()); } } for (Text child : text.getChildren()) { to(child, locale, builder, colorCode, style); } return builder; }
From source file:com.facebook.buck.parser.implicit.AbstractImplicitInclude.java
/** * Constructs a {@link AbstractImplicitInclude} from a configuration string in the form of * * <p>//path/to:bzl_file.bzl::symbol_to_import::second_symbol_to_import * * @param configurationString The string used in configuration * @return A parsed {@link AbstractImplicitInclude} object * @throws {@link HumanReadableException} if the configuration string is invalid *//*from w w w .j a v a 2 s.co m*/ public static ImplicitInclude fromConfigurationString(String configurationString) { // Double colons are used so that if someone uses an absolute windows path, their error // messages will not be confusing. e.g. C:\foo.bzl:bar would lead to a file named // 'C', and symbols '\foo.bzl' and 'bar'. This just makes things explicit. ImmutableList<String> parts = Arrays.stream(configurationString.split("::")).map(String::trim) .collect(ImmutableList.toImmutableList()); if (parts.size() < 2) { throw new HumanReadableException( "Configuration setting '%s' did not list any symbols to load. Setting should be of " + "the format //<load label>::<symbol1>::<symbol2>...", configurationString); } String rawLabel = validateLabelFromConfiguration(parts.get(0), configurationString); ImmutableMap<String, String> symbols = parseAllSymbolsFromConfiguration(parts.subList(1, parts.size()), configurationString); return ImplicitInclude.of(rawLabel, symbols); }