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.jboss.weld.interceptor.reader.TargetClassInterceptorMetadata.java

private Set<Method> initInterceptorMethods(Map<InterceptionType, List<Method>> interceptorMethodMap) {
    ImmutableSet.Builder<Method> builder = ImmutableSet.builder();
    for (List<Method> methodList : interceptorMethodMap.values()) {
        builder.addAll(methodList);/*from  w w w.j  a  v a  2 s  . c o  m*/
    }
    return builder.build();
}

From source file:com.brighttag.agathon.service.impl.PerDataCenterSeedService.java

@Override
public ImmutableSet<String> getSeeds(CassandraRing ring) {
    ImmutableSet.Builder<String> seedBuilder = ImmutableSet.builder();
    ImmutableSetMultimap<String, CassandraInstance> dataCenterToInstanceMap = buildDataCenterToInstanceMap(
            ring.getInstances());/*  ww w. j a  v a 2  s .c  o m*/

    for (String dc : dataCenterToInstanceMap.keySet()) {
        seedBuilder.addAll(getSeeds(dc, dataCenterToInstanceMap.get(dc)));
    }

    return seedBuilder.build();
}

From source file:com.yahoo.yqlplus.engine.internal.plan.IndexedQueryPlanner.java

public IndexedQueryPlanner(Iterable<IndexDescriptor> indexes) {
    ImmutableMap.Builder<IndexKey, IndexDescriptor> idx = ImmutableMap.builder();
    ImmutableSet.Builder<String> cols = ImmutableSet.builder();
    for (IndexDescriptor index : indexes) {
        idx.put(IndexKey.of(index.getColumnNames()), index);
        cols.addAll(index.getColumnNames());
    }//from  w w  w .  j  a  v  a  2 s .c o  m
    this.indexes = idx.build();
    this.indexColumns = cols.build();
}

From source file:com.facebook.presto.raptor.storage.organization.CompactionSetCreator.java

public Set<OrganizationSet> createCompactionSets(Table tableInfo, Collection<ShardIndexInfo> shards) {
    Collection<Collection<ShardIndexInfo>> shardsByDaysBuckets = getShardsByDaysBuckets(tableInfo, shards);

    ImmutableSet.Builder<OrganizationSet> compactionSets = ImmutableSet.builder();
    for (Collection<ShardIndexInfo> shardInfos : shardsByDaysBuckets) {
        compactionSets.addAll(buildCompactionSets(tableInfo, ImmutableSet.copyOf(shardInfos)));
    }//w ww.j av a 2s  . co  m
    return compactionSets.build();
}

From source file:org.obiba.opal.web.shell.reporting.ProjectReportTemplatesResource.java

@GET
public Set<Opal.ReportTemplateDto> get() {
    ImmutableSet.Builder<ReportTemplate> setBuilder = ImmutableSet.builder();
    setBuilder.addAll(/*from  w w w  .j a  va2 s .  c om*/
            Iterables.filter(reportTemplateService.getReportTemplates(name), new Predicate<ReportTemplate>() {
                @Override
                public boolean apply(ReportTemplate template) {
                    return ReportTemplateAuthorizer.authzGet(template);
                }
            }));
    return Dtos.asDto(setBuilder.build());
}

From source file:com.facebook.buck.util.hashing.FilePathHashLoader.java

public FilePathHashLoader(Path defaultCellRoot, ImmutableSet<Path> assumeModifiedFiles, boolean allowSymlinks)
        throws IOException {
    this.defaultCellRoot = defaultCellRoot;
    this.allowSymlinks = allowSymlinks;
    ImmutableSet.Builder<Path> modifiedFilesBuilder = ImmutableSet.builder();
    for (Path path : assumeModifiedFiles) {
        modifiedFilesBuilder.add(resolvePath(path));
    }//from w  w  w .ja v  a 2  s .c  o  m
    this.assumeModifiedFiles = modifiedFilesBuilder.build();
}

From source file:com.wealdtech.collect.TreeRangedMultimap.java

@Override
public Collection<V> get(final Range<K> range) {
    // Find all items which start before this range ends
    ImmutableSet.Builder<V> startersB = ImmutableSet.builder();
    Map.Entry<K, List<V>> startEntry = startMap.floorEntry(range.upperEndpoint());
    while (startEntry != null) {
        // Because our range is [) we don't include anything on the upper endpoint itself
        if (!startEntry.getKey().equals(range.upperEndpoint())) {
            startersB.addAll(startEntry.getValue());
        }/*from ww  w  . j  ava2  s.  c  o m*/
        startEntry = startMap.lowerEntry(startEntry.getKey());
    }
    final ImmutableSet<V> starters = startersB.build();

    // Final all items which end after this range starts
    ImmutableSet.Builder<V> finishersB = ImmutableSet.builder();
    Map.Entry<K, List<V>> finishEntry = endMap.ceilingEntry(range.lowerEndpoint());
    while (finishEntry != null) {
        // Because our range is [) we don't include anything on the lower endpoint itself
        if (!finishEntry.getKey().equals(range.lowerEndpoint())) {
            finishersB.addAll(finishEntry.getValue());
        }
        finishEntry = endMap.higherEntry(finishEntry.getKey());
    }
    final ImmutableSet<V> finishers = finishersB.build();

    // Our result is everything which is in both sets
    return Sets.intersection(starters, finishers);
}

From source file:com.andrewkroh.cisco.phoneinventory.XmlIpPhoneInventoryManager.java

/**
 * Parses the file located at the given URL into a set of {@link IpPhone}
 * objects.//from www  .j a  v a  2 s .c  om
 *
 * @param phoneInventoryXml
 *            URL to the XML file containing the IP phone inventory
 * @return set of {@link IpPhone} objects read from the XML file
 * @throws JAXBException
 *             if there is a problem parsing the XML
 * @throws IOException
 *             if there is a problem reading the XML file
 */
private static ImmutableSet<IpPhone> parseXmlFile(URL phoneInventoryXml) throws JAXBException, IOException {
    JAXBContext jaxbContext = JAXBContext.newInstance(JaxbPhoneInventory.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    JaxbPhoneInventory jaxbInventory = (JaxbPhoneInventory) jaxbUnmarshaller
            .unmarshal(phoneInventoryXml.openStream());

    System.out.println(jaxbInventory);
    ImmutableSet.Builder<IpPhone> builder = ImmutableSet.builder();
    for (JaxbIpPhone jaxbPhone : jaxbInventory.getPhones()) {
        builder.add(new BasicIpPhone(jaxbPhone.getHostname(), jaxbPhone.getPort(), jaxbPhone.getUsername(),
                jaxbPhone.getPassword()));
    }
    return builder.build();
}

From source file:com.facebook.presto.raptor.storage.FileCompactionSetCreator.java

@Override
public Set<CompactionSet> createCompactionSets(long tableId, Set<ShardMetadata> shardMetadata) {
    // Filter out shards larger than allowed size and sort in descending order of data size
    List<ShardMetadata> shards = shardMetadata.stream()
            .filter(shard -> shard.getUncompressedSize() < maxShardSize.toBytes())
            .filter(shard -> shard.getRowCount() < maxShardRows)
            .sorted(comparing(ShardMetadata::getUncompressedSize).reversed())
            .collect(toCollection(ArrayList::new));

    ImmutableSet.Builder<CompactionSet> compactionSets = ImmutableSet.builder();
    while (!shards.isEmpty()) {
        Set<ShardMetadata> compactionSet = getCompactionSet(shards);
        verify(!compactionSet.isEmpty());
        compactionSets.add(new CompactionSet(tableId, compactionSet));
        shards.removeAll(compactionSet);
    }//from w ww  .java 2s .  c  o  m
    return compactionSets.build();
}

From source file:com.streamsets.pipeline.stage.processor.fieldorder.FieldOrderProcessor.java

@Override
protected List<ConfigIssue> init() {
    List<ConfigIssue> issues = super.init();
    fields = ImmutableSet.copyOf(config.fields);
    discardFields = new ImmutableSet.Builder<String>().add("") // Root item is implicitly ignored
            .addAll(config.discardFields).build();

    if (config.missingFieldAction == MissingFieldAction.USE_DEFAULT) {
        defaultField = Field.create(config.dataType.getType(), config.defaultValue);
    }/*from   w w  w .ja  v  a2  s.c om*/

    // Validate that discard fields and order fields do not contain duplicate field paths
    Set<String> duplicates = Sets.intersection(ImmutableSet.copyOf(config.fields),
            ImmutableSet.copyOf(config.discardFields));
    if (!duplicates.isEmpty()) {
        issues.add(getContext().createConfigIssue("ORDER", "config.fields", Errors.FIELD_ORDER_003,
                StringUtils.join(duplicates, ",")));
    }

    return issues;
}