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.caleydo.view.domino.internal.tourguide.ui.EntityTypeSelector.java

/**
 * @return//www.  ja  v a  2 s . c  o m
 */
public static Set<IDCategory> findAllUsedIDCategories() {
    ImmutableSet.Builder<IDCategory> b = ImmutableSortedSet.orderedBy(new Comparator<IDCategory>() {
        @Override
        public int compare(IDCategory o1, IDCategory o2) {
            return String.CASE_INSENSITIVE_ORDER.compare(o1.getCategoryName(), o2.getCategoryName());
        }
    });
    IDataSupportDefinition inhomogenous = DataSupportDefinitions.inhomogenousTables;
    for (ATableBasedDataDomain d : DataDomainManager.get().getDataDomainsByType(ATableBasedDataDomain.class)) {
        b.add(d.getRecordIDCategory());
        if (!inhomogenous.apply(d)) // just in case of uniform tables
            b.add(d.getDimensionIDCategory());
    }
    return b.build();
}

From source file:com.google.idea.blaze.base.util.WorkspacePathUtil.java

/** Removes any duplicates or overlapping directories */
public static ImmutableSet<WorkspacePath> calculateMinimalWorkspacePaths(
        Collection<WorkspacePath> workspacePaths) {
    ImmutableSet.Builder<WorkspacePath> minimalWorkspacePaths = ImmutableSet.builder();
    for (WorkspacePath directory : workspacePaths) {
        boolean ok = true;
        for (WorkspacePath otherDirectory : workspacePaths) {
            if (directory.equals(otherDirectory)) {
                continue;
            }/*from w  w w .  java  2  s  .co m*/
            if (FileUtil.isAncestor(otherDirectory.relativePath(), directory.relativePath(), true)) {
                ok = false;
                break;
            }
        }
        if (ok) {
            minimalWorkspacePaths.add(directory);
        }
    }
    return minimalWorkspacePaths.build();
}

From source file:org.apache.flex.compiler.definitions.references.ReferenceFactory.java

/**
 * Generates an {@link IReference} for a base name qualified by a package
 * name.//from   w ww  .  jav  a  2s  .c o m
 * 
 * @param workspace The workspace.
 * @param packageName The package name to use as the qualifier.
 * @param baseName The base name you want a reference to.
 * @param includeInternal Indicates whether or not the reference should
 * resolve to package internal definitions.
 * @return A {@link ResolvedQualifiersReference}.
 */
public static IResolvedQualifiersReference packageQualifiedReference(IWorkspace workspace, String packageName,
        String baseName, boolean includeInternal) {
    INamespaceDefinition packagePublicNS = ((Workspace) workspace).getPackageNamespaceDefinitionCache()
            .get(packageName, false);
    ImmutableSet.Builder<INamespaceDefinition> namespaceSetBuilder = new ImmutableSet.Builder<INamespaceDefinition>()
            .add(packagePublicNS);
    if (includeInternal) {
        INamespaceDefinition packageInternalNS = ((Workspace) workspace).getPackageNamespaceDefinitionCache()
                .get(packageName, true);
        namespaceSetBuilder.add(packageInternalNS);
    }
    ImmutableSet<INamespaceDefinition> namespaceSet = namespaceSetBuilder.build();
    return new ResolvedQualifiersReference(namespaceSet, baseName);
}

From source file:org.inferred.freebuilder.processor.BuilderFactory.java

private static ImmutableSet<String> findPotentialStaticFactoryMethods(TypeElement builderType) {
    ImmutableSet.Builder<String> resultBuilder = ImmutableSet.builder();
    Element valueType = builderType.getEnclosingElement();
    for (ExecutableElement method : methodsIn(valueType.getEnclosedElements())) {
        Set<Modifier> modifiers = method.getModifiers();
        if (modifiers.contains(Modifier.STATIC) && !modifiers.contains(Modifier.PRIVATE)
                && method.getParameters().isEmpty()
                && builderType.asType().toString().equals(method.getReturnType().toString())) {
            resultBuilder.add(method.getSimpleName().toString());
        }//w  ww  . j a v  a 2  s  .c  om
    }
    return resultBuilder.build();
}

From source file:com.facebook.buck.android.relinker.Symbols.java

public static ImmutableSet<String> getDtNeeded(ProcessExecutor executor, Tool objdump,
        SourcePathResolver resolver, Path lib) throws IOException, InterruptedException {
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();

    final Pattern re = Pattern.compile("^ *NEEDED *(\\S*)$");

    runObjdump(executor, objdump, resolver, lib, ImmutableList.of("-p"), new LineProcessor<Void>() {
        @Override//  ww w  . ja  v a 2 s.  c  o  m
        public boolean processLine(String line) throws IOException {
            Matcher m = re.matcher(line);
            if (!m.matches()) {
                return true;
            }
            builder.add(m.group(1));
            return true;
        }

        @Override
        public Void getResult() {
            return null;
        }
    });

    return builder.build();
}

From source file:com.outerspacecat.icalendar.Attendee.java

/**
 * Parses an attendee property.//from  w  w w  .j  av  a  2  s. co m
 * 
 * @param property the property to parse. Must be non {@code null}.
 * @return an attendee. Never {@code null}.
 * @throws CalendarParseException if {@code property} cannot be parsed
 */
public static Attendee parse(final Property property) throws CalendarParseException {
    Preconditions.checkNotNull(property, "property required");
    Preconditions.checkArgument(property.getName().getName().equals("ATTENDEE"),
            "property name must be ATTENDEE, saw: " + property.getName());

    UriType address = property.asUri();

    ParameterValue calendarUserType = property.getParameterValue("CUTYPE");

    ImmutableSet.Builder<UriType> memberships = ImmutableSet.builder();
    Parameter memberParam = property.getParameters().get("MEMBER");
    if (memberParam != null) {
        for (ParameterValue value : memberParam.getValues())
            memberships.add(UriType.parse(value.getValue()));
    }

    ParameterValue role = property.getParameterValue("ROLE");
    ParameterValue participationStatus = property.getParameterValue("PARTSTAT");

    ParameterValue rsvpParam = property.getParameterValue("RSVP");
    boolean rsvpExpected = rsvpParam != null && rsvpParam.getValue().equalsIgnoreCase("TRUE");

    ImmutableSet.Builder<UriType> delegatees = ImmutableSet.builder();
    Parameter delegatedToParam = property.getParameters().get("DELEGATED-TO");
    if (delegatedToParam != null) {
        for (ParameterValue value : delegatedToParam.getValues())
            delegatees.add(UriType.parse(value.getValue()));
    }

    ImmutableSet.Builder<UriType> delegators = ImmutableSet.builder();
    Parameter delegatedFromParam = property.getParameters().get("DELEGATED-FROM");
    if (delegatedFromParam != null) {
        for (ParameterValue value : delegatedFromParam.getValues())
            delegators.add(UriType.parse(value.getValue()));
    }

    ParameterValue sentByParam = property.getParameterValue("SENT-BY");
    UriType sentBy = sentByParam != null ? UriType.parse(sentByParam.getValue()) : null;

    ParameterValue commonName = property.getParameterValue("CN");

    ParameterValue dirParam = property.getParameterValue("DIR");
    UriType directoryEntry = dirParam != null ? UriType.parse(dirParam.getValue()) : null;

    ParameterValue language = property.getParameterValue("LANGUAGE");

    return new Attendee(address, calendarUserType, memberships.build(), role, participationStatus, rsvpExpected,
            delegatees.build(), delegators.build(), sentBy, commonName, directoryEntry, language,
            property.getParametersExcept(RESTRICTED_PARAMETER_NAMES).values());
}

From source file:com.tngtech.archunit.junit.ArchRuleDeclaration.java

static Set<ArchRuleDeclaration<?>> toDeclarations(ArchRules rules, Class<?> testClass,
        Class<? extends Annotation> archTestAnnotationType, boolean forceIgnore) {

    ImmutableSet.Builder<ArchRuleDeclaration<?>> result = ImmutableSet.builder();
    Class<?> definitionLocation = rules.getDefinitionLocation();
    for (Field field : getAllFields(definitionLocation, withAnnotation(archTestAnnotationType))) {
        result.addAll(archRuleDeclarationsFrom(testClass, field, definitionLocation, archTestAnnotationType,
                forceIgnore));/*from w  w w .ja v a 2  s  . c o  m*/
    }
    for (Method method : getAllMethods(definitionLocation, withAnnotation(archTestAnnotationType))) {
        result.add(ArchRuleDeclaration.from(testClass, method, definitionLocation, forceIgnore));
    }
    return result.build();
}

From source file:io.prestosql.plugin.hive.HiveBucketing.java

public static Optional<HiveBucketFilter> getHiveBucketFilter(Table table,
        TupleDomain<ColumnHandle> effectivePredicate) {
    if (!table.getStorage().getBucketProperty().isPresent()) {
        return Optional.empty();
    }/*from   w w w .ja  v a  2  s.  c  o m*/

    Optional<Map<ColumnHandle, NullableValue>> bindings = TupleDomain.extractFixedValues(effectivePredicate);
    if (!bindings.isPresent()) {
        return Optional.empty();
    }
    OptionalInt singleBucket = getHiveBucket(table, bindings.get());
    if (singleBucket.isPresent()) {
        return Optional.of(new HiveBucketFilter(ImmutableSet.of(singleBucket.getAsInt())));
    }

    if (!effectivePredicate.getDomains().isPresent()) {
        return Optional.empty();
    }
    Optional<Domain> domain = effectivePredicate.getDomains().get().entrySet().stream()
            .filter(entry -> ((HiveColumnHandle) entry.getKey()).getName().equals(BUCKET_COLUMN_NAME))
            .findFirst().map(Entry::getValue);
    if (!domain.isPresent()) {
        return Optional.empty();
    }
    ValueSet values = domain.get().getValues();
    ImmutableSet.Builder<Integer> builder = ImmutableSet.builder();
    int bucketCount = table.getStorage().getBucketProperty().get().getBucketCount();
    for (int i = 0; i < bucketCount; i++) {
        if (values.containsValue((long) i)) {
            builder.add(i);
        }
    }
    return Optional.of(new HiveBucketFilter(builder.build()));
}

From source file:org.onos.yangtools.yang.parser.impl.util.YangModelDependencyInfo.java

private static ImmutableSet<ModuleImport> parseImports(final List<Import_stmtContext> importStatements) {
    ImmutableSet.Builder<ModuleImport> builder = ImmutableSet.builder();
    for (Import_stmtContext importStmt : importStatements) {
        String moduleName = getArgumentString(importStmt);
        Date revision = getRevision(importStmt.revision_date_stmt());
        builder.add(new ModuleImportImpl(moduleName, revision));
    }/*  www  . j ava2 s  .c  o  m*/
    return builder.build();
}

From source file:org.apache.flex.compiler.internal.css.CSSManager.java

/**
 * Find compilation units for the given definition set. A definition might
 * not have a compilation unit, but a compiler problem must already be
 * logged for it in {@code problems} before this method is called.
 * /* w ww .j  av  a 2 s  . c o m*/
 * @param flexProject Flex project.
 * @param classDefinitions Class definitions.
 * @param problems Problems collection.
 * @return A set of compilation unit for the given class definitions.
 */
static ImmutableSet<ICompilationUnit> getCompilationUnitsForDefinitions(final FlexProject flexProject,
        final Set<IClassDefinition> classDefinitions, final Collection<ICompilerProblem> problems) {
    final ImmutableSet.Builder<ICompilationUnit> builder = new ImmutableSet.Builder<ICompilationUnit>();
    for (final IClassDefinition classDefinition : classDefinitions) {
        final ASProjectScope scope = flexProject.getScope();
        final ICompilationUnit compilationUnit = scope.getCompilationUnitForDefinition(classDefinition);
        if (compilationUnit != null)
            builder.add(compilationUnit);
        else
            assert problemCreatedForUnresolvedClassReference(problems,
                    classDefinition) : "Can't find compilation unit for class '"
                            + classDefinition.getQualifiedName()
                            + "'. Expected a 'CSSUnresolvedClassReference'.";
    }
    return builder.build();
}