Example usage for com.google.common.collect ImmutableSet.Builder add

List of usage examples for com.google.common.collect ImmutableSet.Builder add

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSet.Builder add.

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:org.quil.interpreter.strata.JarMarketDataBuilder.java

private static ImmutableSet<String> getEntries(File jarFile, String rootPath) {
    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    try (JarFile jar = new JarFile(jarFile)) {
        Enumeration<JarEntry> jarEntries = jar.entries();
        while (jarEntries.hasMoreElements()) {
            JarEntry entry = jarEntries.nextElement();
            String entryName = entry.getName();
            if (entryName.startsWith(rootPath) && !entryName.equals(rootPath)) {
                String relativeEntryPath = entryName.substring(rootPath.length() + 1);
                if (!relativeEntryPath.trim().isEmpty()) {
                    builder.add(relativeEntryPath);
                }/*www.  j a  va 2s  .  c  o m*/
            }
        }
    } catch (Exception e) {
        throw new IllegalArgumentException(Messages.format("Error scanning entries in JAR file: {}", jarFile),
                e);
    }
    return builder.build();
}

From source file:google.registry.flows.ExtensionManager.java

private static void checkForUnimplementedExtensions(ImmutableList<CommandExtension> suppliedExtensionInstances,
        ImmutableSet<Class<? extends CommandExtension>> implementedExtensionClasses)
        throws UnimplementedExtensionException {
    ImmutableSet.Builder<Class<? extends CommandExtension>> unimplementedExtensionsBuilder = new ImmutableSet.Builder<>();
    for (final CommandExtension instance : suppliedExtensionInstances) {
        if (!any(implementedExtensionClasses, new Predicate<Class<? extends CommandExtension>>() {
            @Override//from   ww  w  . j av  a2  s . co m
            public boolean apply(Class<? extends CommandExtension> implementedExtensionClass) {
                return implementedExtensionClass.isInstance(instance);
            }
        })) {
            unimplementedExtensionsBuilder.add(instance.getClass());
        }
    }
    ImmutableSet<Class<? extends CommandExtension>> unimplementedExtensions = unimplementedExtensionsBuilder
            .build();
    if (!unimplementedExtensions.isEmpty()) {
        logger.infofmt("Unimplemented extensions: %s", unimplementedExtensions);
        throw new UnimplementedExtensionException();
    }
}

From source file:eu.eidas.auth.commons.PersonalAttributeList.java

public static ImmutableSet<AttributeValue<?>> toAttributeValues(AttributeDefinition<?> attributeDefinition,
        List<String> personalAttributeValues) {
    AttributeValueMarshaller<?> attributeValueMarshaller = attributeDefinition.getAttributeValueMarshaller();
    ImmutableSet.Builder<AttributeValue<?>> setBuilder = ImmutableSet.builder();
    for (final String value : personalAttributeValues) {
        try {/*  w  ww  .ja v a 2  s . co m*/
            setBuilder.add(attributeValueMarshaller.unmarshal(value, false));
        } catch (AttributeValueMarshallingException e) {
            throw new IllegalStateException(e);
        }
    }
    return setBuilder.build();
}

From source file:com.google.devtools.build.xcode.xcodegen.XcodeprojGeneration.java

/**
 * Returns the {@code FRAMEWORK_SEARCH_PATHS} array for a target's build config given the list of
 * {@code .framework} directory paths./*ww w .j  av a  2s  .c o  m*/
 */
private static NSArray frameworkSearchPaths(Iterable<String> frameworks) {
    ImmutableSet.Builder<NSString> result = new ImmutableSet.Builder<>();
    for (String framework : frameworks) {
        result.add(new NSString("$(WORKSPACE_ROOT)/" + Paths.get(framework).getParent()));
    }
    // This is needed by XcTest targets (and others, just in case) for SenTestingKit.framework.
    result.add(new NSString("$(SDKROOT)/Developer/Library/Frameworks"));
    // This is needed by non-XcTest targets that use XcTest.framework, for instance for test
    // utility libraries packaged as an objc_library.
    result.add(new NSString("$(PLATFORM_DIR)/Developer/Library/Frameworks"));

    return (NSArray) NSObject.wrap(result.build().asList());
}

From source file:com.facebook.buck.apple.project_generator.XCodeProjectCommandHelper.java

@VisibleForTesting
static ImmutableSet<ProjectGenerator.Option> buildWorkspaceGeneratorOptions(boolean isReadonly,
        boolean isWithTests, boolean isWithDependenciesTests, boolean isProjectsCombined,
        boolean shouldUseHeaderMaps, boolean shouldMergeHeaderMaps,
        boolean shouldGenerateHeaderSymlinkTreesOnly) {
    ImmutableSet.Builder<ProjectGenerator.Option> optionsBuilder = ImmutableSet.builder();
    if (isReadonly) {
        optionsBuilder.add(ProjectGenerator.Option.GENERATE_READ_ONLY_FILES);
    }/*from ww  w. j av a  2s.  c om*/
    if (isWithTests) {
        optionsBuilder.add(ProjectGenerator.Option.INCLUDE_TESTS);
    }
    if (isWithDependenciesTests) {
        optionsBuilder.add(ProjectGenerator.Option.INCLUDE_DEPENDENCIES_TESTS);
    }
    if (isProjectsCombined) {
        optionsBuilder.addAll(ProjectGenerator.COMBINED_PROJECT_OPTIONS);
    } else {
        optionsBuilder.addAll(ProjectGenerator.SEPARATED_PROJECT_OPTIONS);
    }
    if (!shouldUseHeaderMaps) {
        optionsBuilder.add(ProjectGenerator.Option.DISABLE_HEADER_MAPS);
    }
    if (shouldMergeHeaderMaps) {
        optionsBuilder.add(ProjectGenerator.Option.MERGE_HEADER_MAPS);
    }
    if (shouldGenerateHeaderSymlinkTreesOnly) {
        optionsBuilder.add(ProjectGenerator.Option.GENERATE_HEADERS_SYMLINK_TREES_ONLY);
    }
    return optionsBuilder.build();
}

From source file:org.apache.aurora.scheduler.base.Numbers.java

/**
 * Converts a set of integers into a set of contiguous closed ranges that equally represent the
 * input integers.//from ww w  . j  ava 2 s.  c  o m
 * <p>
 * The resulting ranges will be in ascending order.
 * <p>
 * TODO(wfarner): Change this to return a canonicalized RangeSet.
 *
 * @param values Values to transform to ranges.
 * @return Closed ranges with identical members to the input set.
 */
public static Set<Range<Integer>> toRanges(Iterable<Integer> values) {
    ImmutableSet.Builder<Range<Integer>> builder = ImmutableSet.builder();

    PeekingIterator<Integer> iterator = Iterators.peekingIterator(Sets.newTreeSet(values).iterator());

    // Build ranges until there are no numbers left.
    while (iterator.hasNext()) {
        // Start a new range.
        int start = iterator.next();
        int end = start;
        // Increment the end until the range is non-contiguous.
        while (iterator.hasNext() && iterator.peek() == end + 1) {
            end++;
            iterator.next();
        }

        builder.add(Range.closed(start, end));
    }

    return builder.build();
}

From source file:com.cynnyx.auto.value.map.MapMethod.java

static Set<ExecutableElement> filteredAbstractMethods(AutoValueExtension.Context context) {
    TypeElement type = context.autoValueClass();

    // check that the class contains method: public abstract Map<String, Object> toMap() or Map toMap()
    ParameterizedTypeName targetReturnType = ParameterizedTypeName.get(ClassName.get(Map.class),
            ClassName.get(String.class), TypeName.OBJECT);
    ImmutableSet.Builder<ExecutableElement> foundMethods = ImmutableSet.builder();

    for (ExecutableElement method : ElementFilter.methodsIn(type.getEnclosedElements())) {
        if (method.getModifiers().contains(Modifier.ABSTRACT) && method.getModifiers().contains(Modifier.PUBLIC)
                && method.getSimpleName().toString().equals(METHOD_NAME)
                && method.getParameters().size() == 0) {
            TypeMirror rType = method.getReturnType();
            TypeName returnType = TypeName.get(rType);
            if (returnType.equals(targetReturnType)) {
                foundMethods.add(method);
                break;
            }//  ww  w  .  j ava  2 s . c  o m

            if (returnType.equals(targetReturnType.rawType)) {
                if (returnType instanceof ParameterizedTypeName) {
                    Messager messager = context.processingEnvironment().getMessager();
                    ParameterizedTypeName paramReturnType = (ParameterizedTypeName) returnType;
                    TypeName argument = paramReturnType.typeArguments.get(0);
                    messager.printMessage(Diagnostic.Kind.WARNING, String.format(
                            "Found public static method returning Map<%s> instead of Map<String,Object>",
                            argument));
                } else {
                    foundMethods.add(method);
                }
            }
        }
    }

    return foundMethods.build();
}

From source file:com.google.devtools.build.xcode.xcodegen.XcodeprojGeneration.java

/**
 * Returns the {@code ARCHS} array for a target's build config given the list of architecture
 * strings. If none is given, an array with default architectures "armv7" and "arm64" will be
 * returned./*from ww w  .  j  a va  2 s.  co  m*/
 */
private static NSArray cpuArchitectures(Iterable<String> architectures) {
    if (Iterables.isEmpty(architectures)) {
        return new NSArray(new NSString("armv7"), new NSString("arm64"));
    } else {
        ImmutableSet.Builder<NSString> result = new ImmutableSet.Builder<>();
        for (String architecture : architectures) {
            result.add(new NSString(architecture));
        }
        return (NSArray) NSObject.wrap(result.build().asList());
    }
}

From source file:com.google.errorprone.dataflow.nullnesspropagation.inference.NullnessQualifierInference.java

private static ImmutableSet<InferenceVariable> findUnannotatedTypeVarRefs(TypeVariableSymbol typeVar,
        Type declaredType, @Nullable Symbol decl, Tree sourceNode) {
    ImmutableSet.Builder<InferenceVariable> result = ImmutableSet.builder();
    visitTypeVarRefs(typeVar, declaredType, new ArrayDeque<>(), null, (typeVarRef, selector, unused) -> {
        if (!extractExplicitNullness(typeVarRef, selector.isEmpty() ? decl : null).isPresent()) {
            result.add(TypeArgInferenceVar.create(ImmutableList.copyOf(selector), sourceNode));
        }//from  w ww  . j  av a  2  s .c  o m
    });
    return result.build();
}

From source file:io.crate.auth.user.UserManagerService.java

static Set<User> getUsers(@Nullable UsersMetaData metaData,
        @Nullable UsersPrivilegesMetaData privilegesMetaData) {
    ImmutableSet.Builder<User> usersBuilder = new ImmutableSet.Builder<User>().add(CRATE_USER);
    if (metaData != null) {
        for (Map.Entry<String, SecureHash> user : metaData.users().entrySet()) {
            String userName = user.getKey();
            SecureHash password = user.getValue();
            Set<Privilege> privileges = null;
            if (privilegesMetaData != null) {
                privileges = privilegesMetaData.getUserPrivileges(userName);
            }/*from ww  w  . ja  va 2 s .  c  o m*/
            usersBuilder.add(User.of(userName, privileges, password));
        }
    }
    return usersBuilder.build();
}