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

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

Introduction

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

Prototype

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

Source Link

Usage

From source file:org.jclouds.location.suppliers.SupplyPredefinedRegions.java

@Override
public Set<? extends Location> get() {
    Builder<Location> locations = ImmutableSet.builder();
    Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, endpoint.toASCIIString(), null);
    for (String zone : regions) {
        locations.add(new LocationImpl(LocationScope.REGION, zone.toString(), zone.toString(), provider));
    }/*from  w  ww  . ja v a  2  s  . c  o m*/
    return locations.build();
}

From source file:com.greensopinion.finance.services.web.Application.java

@Override
public Set<Object> getSingletons() {
    ImmutableSet.Builder<Object> builder = ImmutableSet.<Object>builder();
    Map<Key<?>, Binding<?>> bindings = injector.getBindings();
    for (Key<?> key : bindings.keySet()) {
        if (hasAnnotation(key, ImmutableList.of(Path.class, Provides.class, Consumes.class))
                && isEligible(key)) {
            builder.add(injector.getInstance(key));
        }//w w  w.  j av  a  2s .c o m
    }
    return builder.build();
}

From source file:org.jasig.portal.events.aggr.FilteredEventSession.java

FilteredEventSession(EventSession parent, AggregatedGroupConfig aggregatedGroupConfig) {
    this.parent = parent;
    this.aggregatedGroupConfig = aggregatedGroupConfig;

    final Builder<AggregatedGroupMapping> filteredGroupMappingsBuilder = ImmutableSet.builder();
    for (final AggregatedGroupMapping aggregatedGroupMapping : parent.getGroupMappings()) {
        if (FilteredEventSession.this.aggregatedGroupConfig.isIncluded(aggregatedGroupMapping)) {
            filteredGroupMappingsBuilder.add(aggregatedGroupMapping);
        }//from   w w  w  .  j  a  v a 2s  .c  o  m
    }
    this.filteredGroupMappings = filteredGroupMappingsBuilder.build();
}

From source file:org.opendaylight.aaa.shiro.realm.mapping.impl.BestAttemptGroupToRolesMappingStrategy.java

@Override
public Map<String, Set<String>> mapGroupsToRoles(final Collection<String> groupNames, final String delimiter,
        final Map<String, String> groupRolesMap) {

    final ImmutableMap.Builder<String, Set<String>> roleNamesBuilder = ImmutableMap.builder();

    if (groupRolesMap != null) {
        for (String groupName : groupNames) {
            final String roleNamesString = groupRolesMap.get(groupName);

            LOG.debug("association discovered: groupName={} and roleNamesString={}", groupName,
                    roleNamesString);/*ww  w .j  a  v a2  s. c  om*/
            if (roleNamesString != null) {
                final String[] roleNames = roleNamesString.split(delimiter);
                final ImmutableSet.Builder<String> rolesSet = ImmutableSet.builder();
                for (String roleName : roleNames) {
                    rolesSet.add(roleName);
                }
                roleNamesBuilder.put(groupName, rolesSet.build());
            }
        }
    } else {
        LOG.info("groupRolesMap was unspecified; directly mapping LDAP groups instead: {}", groupNames);
        for (String groupName : groupNames) {
            final ImmutableSet.Builder<String> rolesSet = ImmutableSet.builder();
            rolesSet.add(groupName);
            roleNamesBuilder.put(groupName, rolesSet.build());
        }
    }

    return roleNamesBuilder.build();

}

From source file:de.cosmocode.commons.reflect.DefaultPackages.java

public DefaultPackages(Classpath classpath, Iterable<String> packages) throws IOException {
    Preconditions.checkNotNull(classpath, "Classpath");
    Preconditions.checkNotNull(packages, "Packages");
    final Builder<Class<?>> builder = ImmutableSet.builder();

    for (URL url : classpath) {
        final File file = new File(url.getFile());
        if (file.isFile()) {
            loadJar(builder, file, packages);
        } else if (file.isDirectory()) {
            loadDirectory(builder, file, packages);
        } else {/* ww w.  j  av  a2s  . c  om*/
            LOG.warn("Unable to load from classpath entry {}", url);
        }
    }

    this.classes = builder.build();
}

From source file:org.caleydo.view.tourguide.api.model.InhomogenousDataDomainQuery.java

public InhomogenousDataDomainQuery(ATableBasedDataDomain dataDomain, Set<EDataClass> dataClasses) {
    super(dataDomain);
    this.dataClass = dataClasses;
    Builder<EDataType> builder = ImmutableSet.builder();
    for (EDataClass dataClass : dataClasses)
        builder.addAll(dataClass.getSupportedDataTypes());
    this.possible = builder.build();
    this.selectedDataTypes = new HashSet<>(possible);
    setMinSize(MyPreferences.getMinClusterSize());
}

From source file:sonia.legman.maven.MethodAnnotationClassVisitor.java

/**
 * Constructs ...// w w  w .ja  v  a  2s .  c  o  m
 *
 *
 * @param api
 * @param methodAnnotationHandler
 * @param annotationClasses
 */
private MethodAnnotationClassVisitor(int api, MethodAnnotationHandler methodAnnotationHandler,
        Iterable<Class<? extends Annotation>> annotationClasses) {
    super(api);
    this.methodAnnotationHandler = methodAnnotationHandler;

    ImmutableSet.Builder<String> builder = ImmutableSet.builder();

    for (Class<? extends Annotation> annotationClass : annotationClasses) {
        builder.add(annotationClass.getName());
    }

    annotations = builder.build();
}

From source file:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ContainerEffectiveStatementImpl.java

public ContainerEffectiveStatementImpl(
        final StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
    super(ctx);/*w ww . j  av  a  2s.co m*/
    this.original = ctx.getOriginalCtx() == null ? null
            : (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
    final ImmutableSet.Builder<ActionDefinition> actionsBuilder = ImmutableSet.builder();
    final Builder<NotificationDefinition> notificationsBuilder = ImmutableSet.builder();
    for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
        if (effectiveStatement instanceof ActionDefinition) {
            actionsBuilder.add((ActionDefinition) effectiveStatement);
        }

        if (effectiveStatement instanceof NotificationDefinition) {
            notificationsBuilder.add((NotificationDefinition) effectiveStatement);
        }
    }

    this.actions = actionsBuilder.build();
    this.notifications = notificationsBuilder.build();
}

From source file:org.apache.shiro.guice.web.FilterChainResolverProvider.java

public FilterChainResolverProvider(Map<String, Key<? extends Filter>[]> chains) {
    this.chains = chains;
    ImmutableSet.Builder<Dependency<?>> dependenciesBuilder = ImmutableSet.builder();
    for (String chain : chains.keySet()) {
        for (Key<? extends Filter> filterKey : chains.get(chain)) {
            dependenciesBuilder.add(Dependency.get(filterKey));
        }/*from   ww  w  .ja va 2  s  . c  om*/
    }
    this.dependencies = dependenciesBuilder.build();
}

From source file:com.facebook.buck.cli.TargetsCommandOptions.java

/**
 * Filter files under the project root, and convert to canonical relative path style.
 * For example, the project root is /project,
 * 1. file path /project/./src/com/facebook/./test/../Test.java will be converted to
 *    src/com/facebook/Test.java/*  w  w  w  .  j av  a2  s  .c o m*/
 * 2. file path /otherproject/src/com/facebook/Test.java will be ignored.
 */
public static ImmutableSet<String> getCanonicalFilesUnderProjectRoot(File projectRoot,
        ImmutableSet<String> nonCanonicalFilePaths) throws IOException {
    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    String projectRootCanonicalFullPathWithEndSlash = projectRoot.getCanonicalPath() + File.separator;
    for (String filePath : nonCanonicalFilePaths) {
        String canonicalFullPath = new File(filePath).getCanonicalPath();

        // Ignore files that aren't under project root.
        if (canonicalFullPath.startsWith(projectRootCanonicalFullPathWithEndSlash)) {
            builder.add(MorePaths
                    .newPathInstance(
                            canonicalFullPath.substring(projectRootCanonicalFullPathWithEndSlash.length()))
                    .toString());
        }
    }
    return builder.build();
}