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

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

Introduction

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

Prototype

public static <E> Builder<E> builder() 

Source Link

Usage

From source file:com.spotify.heroic.shell.QuoteParser.java

public static List<List<String>> parse(String input) throws QuoteParserException {
    int pos = 0;/*from w ww . j  av a2s  . c  o m*/

    final char[] chars = input.toCharArray();

    final ImmutableList.Builder<List<String>> lines = ImmutableList.builder();

    while (pos < chars.length) {
        boolean openSingle = false;
        boolean openDouble = false;
        boolean escapeNext = false;
        boolean whitespaceBlock = false;
        int unicodeChar = 0;
        final char[] unicode = new char[4];

        StringBuffer buffer = new StringBuffer();

        final List<String> parts = new ArrayList<>();

        while (pos < chars.length) {
            final char c = chars[pos++];

            if (unicodeChar > 0) {
                unicode[4 - unicodeChar--] = c;

                if (unicodeChar == 0) {
                    buffer.append(parseUnicodeChar(unicode, pos));
                }

                continue;
            }

            if (escapeNext) {
                escapeNext = false;

                if (c == 'n') {
                    buffer.append(NL);
                    continue;
                }

                if (c == 't') {
                    buffer.append(TAB);
                    continue;
                }

                if (c == 'u') {
                    unicodeChar = 4;
                    continue;
                }

                buffer.append(c);
                continue;
            }

            if (whitespaceBlock && !isWhitespace(c)) {
                whitespaceBlock = false;

                if (buffer.length() > 0) {
                    parts.add(buffer.toString());
                    buffer = new StringBuffer();
                }
            }

            if (c == ';') {
                break;
            }

            if (c == '#') {
                pos = chars.length;
                break;
            }

            if (c == BACKTICK) {
                escapeNext = true;
                continue;
            }

            if (c == SINGLE_QUOTE && !openDouble) {
                openSingle = !openSingle;
                continue;
            }

            if (c == DOUBLE_QUOTE && !openSingle) {
                openDouble = !openDouble;
                continue;
            }

            if (openSingle || openDouble) {
                buffer.append(c);
                continue;
            }

            if (isWhitespace(c)) {
                whitespaceBlock = true;
                continue;
            }

            buffer.append(c);
        }

        if (openSingle) {
            throw new QuoteParserException(pos + ": input ended with open single quote");
        }

        if (openDouble) {
            throw new QuoteParserException(pos + ": input ended with open double quote");
        }

        if (escapeNext) {
            throw new QuoteParserException(pos + ": input ended with open escape");
        }

        if (unicodeChar > 0) {
            throw new QuoteParserException(pos + ": input ended with open unicode escape sequence");
        }

        if (buffer.length() > 0) {
            parts.add(buffer.toString());
        }

        lines.add(ImmutableList.copyOf(parts));
    }

    return lines.build();
}

From source file:com.kratos.birt.report.data.oda.kairosdb.json.BeanValidationException.java

private static List<String> messagesFor(Set<ConstraintViolation<Object>> violations, String context) {
    ImmutableList.Builder<String> messages = new ImmutableList.Builder<String>();
    for (ConstraintViolation<?> violation : violations) {
        if (context != null && !context.isEmpty())
            messages.add(context + "." + violation.getPropertyPath().toString() + " " + violation.getMessage());
        else/*from  ww  w  . j  a  v a  2  s  .c  o m*/
            messages.add(violation.getPropertyPath().toString() + " " + violation.getMessage());
    }

    return messages.build();
}

From source file:org.obiba.magma.datasource.mongodb.converter.VariableConverter.java

private static Iterable<Category> unmarshallCategories(Iterable<?> cats) {
    ImmutableList.Builder<Category> list = ImmutableList.builder();
    for (Object o : cats) {
        BSONObject cat = (BSONObject) o;
        Category.Builder catBuilder = Category.Builder.newCategory(cat.get("name").toString())
                .missing(Boolean.parseBoolean(cat.get("missing").toString()));
        if (cat.containsField("attributes")) {
            catBuilder.addAttributes(unmarshallAttributes((Iterable<?>) cat.get("attributes")));
        }/* w  w  w. ja  va 2  s .  c  o m*/
        list.add(catBuilder.build());
    }
    return list.build();
}

From source file:suneido.database.immudb.Indexes.java

List<List<String>> columns(Columns columns) {
    ImmutableList.Builder<List<String>> list = ImmutableList.builder();
    for (Index index : indexes)
        list.add(index.columns(columns));
    return list.build();
}

From source file:com.google.devtools.build.lib.collect.nestedset.MemoizedUniquefierNestedSet.java

@Override
public List<E> toList() {
    ImmutableList.Builder<E> builder = new ImmutableList.Builder<>();
    memoizedFill(builder);/*from  w  w w . j ava  2  s  . c o  m*/
    return builder.build();
}

From source file:com.google.api.codegen.transformer.ServiceTransformer.java

public ServiceDocView generateServiceDoc(InterfaceContext context, ApiMethodView exampleApiMethod,
        GapicProductConfig productConfig) {
    SurfaceNamer namer = context.getNamer();
    ServiceDocView.Builder serviceDoc = ServiceDocView.newBuilder();

    ImmutableList.Builder<String> docLines = ImmutableList.builder();
    docLines.addAll(namer.getDocLines(context.getInterfaceDescription()));
    InterfaceConfig conf = context.getInterfaceConfig();
    if (!conf.getManualDoc().isEmpty()) {
        docLines.add("");
        docLines.addAll(namer.getDocLines(conf.getManualDoc()));
    }//from w w  w . ja  v a2 s  .  com
    List<String> lines = docLines.build();
    serviceDoc.lines(lines);

    if (lines.isEmpty()) {
        serviceDoc.firstLine("");
        serviceDoc.remainingLines(ImmutableList.<String>of());
    } else {
        serviceDoc.firstLine(lines.get(0));
        serviceDoc.remainingLines(lines.subList(1, lines.size()));
    }

    serviceDoc.exampleApiMethod(exampleApiMethod);
    serviceDoc.apiVarName(namer.getApiWrapperVariableName(context.getInterfaceConfig()));
    serviceDoc.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    serviceDoc.settingsVarName(namer.getApiSettingsVariableName(context.getInterfaceConfig()));
    serviceDoc.settingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
    serviceDoc.hasDefaultInstance(context.getInterfaceConfig().hasDefaultInstance());
    serviceDoc.serviceTitle(context.serviceTitle());
    serviceDoc.defaultTransportProviderBuilder(
            namer.getDefaultTransportProviderBuilder(productConfig.getTransportProtocol()));
    serviceDoc.defaultChannelProviderBuilder(
            namer.getDefaultChannelProviderBuilder(productConfig.getTransportProtocol()));
    return serviceDoc.build();
}

From source file:de.se_rwth.langeditor.util.ResourceLocator.java

public static ImmutableList<Path> assembleModelPath(IProject project) {
    ImmutableList.Builder<Path> builder = ImmutableList.builder();
    for (IClasspathEntry classpathEntry : getModelPathEntries(JavaCore.create(project))) {
        builder.add(classpathEntry.getPath().toFile().toPath());
    }//from   w  ww  .  j  a  va 2s  .c o  m
    return builder.build();
}

From source file:garmintools.adapters.garmin.NavigationFixGarminAdapter.java

@Override
public List<String> read(DataLengthSection dataLengthSection, TableOfContentsEntry entry,
        ByteBuffer byteBuffer) {// www.  ja  v a  2  s  . co  m
    ImmutableList.Builder<String> listBuilder = ImmutableList.builder();
    for (int index = 0; index < entry.itemQuantity; ++index) {
        byte item[] = new byte[entry.itemLength];
        byteBuffer.get(item);
        listBuilder.add(COMPLEX_ENCODING.decode(item).trim());
    }
    return listBuilder.build();
}

From source file:org.gradle.model.internal.type.GenericArrayTypeWrapper.java

@Override
public void collectClasses(ImmutableList.Builder<Class<?>> builder) {
    componentType.collectClasses(builder);
}

From source file:com.facebook.buck.rules.coercer.PatternMatchedCollection.java

public ImmutableList<T> getMatchingValues(String string) {
    ImmutableList.Builder<T> matchingValues = ImmutableList.builder();
    for (Pair<Pattern, T> pair : values) {
        if (pair.getFirst().matcher(string).find()) {
            matchingValues.add(pair.getSecond());
        }//www  . ja va 2s .  c  om
    }
    return matchingValues.build();
}