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:edu.mit.streamjit.impl.distributed.common.Utils.java

public static Token getblobID(Set<Worker<?, ?>> workers) {
    ImmutableSet.Builder<Token> inputBuilder = new ImmutableSet.Builder<>();
    for (IOInfo info : IOInfo.externalEdges(workers)) {
        if (info.isInput())
            inputBuilder.add(info.token());
    }// w  ww. j  a v  a 2  s  . c  om

    return Collections.min(inputBuilder.build());
}

From source file:org.lanternpowered.server.block.trait.LanternIntegerTrait.java

/**
 * Creates a new integer trait with the specified name and the possible values.
 * //  w w w.java 2  s .  co m
 * <p>The possible values array may not be empty.</p>
 * 
 * @param name the name
 * @param key the key that should be attached to the trait
 * @param possibleValues the possible values
 * @return the integer trait
 */
public static IntegerTrait of(String name, Key<? extends Value<Integer>> key, int... possibleValues) {
    checkNotNullOrEmpty(name, "name");
    checkNotNull(possibleValues, "possibleValues");
    checkNotNull(key, "key");
    checkState(possibleValues.length != 0, "possibleValues may not be empty");
    ImmutableSet.Builder<Integer> builder = ImmutableSet.builder();
    for (int possibleValue : possibleValues) {
        builder.add(possibleValue);
    }
    return new LanternIntegerTrait(name, key, builder.build());
}

From source file:com.xemantic.tadedon.gwt.field.rebind.UiFieldAccessorGenerators.java

public static Set<String> getFieldNames(OwnerClass ownerClass) {
    Collection<OwnerField> fields = ownerClass.getUiFields();
    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    for (OwnerField ownerField : fields) {
        builder.add(ownerField.getName());
    }//from w  w  w  .  jav a 2  s  . c om
    return builder.build();
}

From source file:org.graylog2.indexer.IndexHelper.java

public static Set<String> determineAffectedIndices(IndexRangeService indexRangeService, Deflector deflector,
        TimeRange range) {/*from w  ww  . j  a  v  a2 s. c  om*/
    final Set<IndexRange> indexRanges = determineAffectedIndicesWithRanges(indexRangeService, deflector, range);
    final ImmutableSet.Builder<String> indices = ImmutableSet.builder();
    for (IndexRange indexRange : indexRanges) {
        indices.add(indexRange.indexName());
    }

    return indices.build();
}

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

/**
 * Parses the file located at the given URL into a set of {@link IpPhone}
 * objects.// w  w w  . j av a2s.c  o  m
 *
 * @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.google.api.server.spi.auth.EndpointsPeerAuthenticator.java

private static ImmutableSet<String> getLocalHostAddresses() {
    ImmutableSet.Builder<String> builder = new ImmutableSet.Builder<>();
    try {//from w ww.ja  v a  2 s.  c  o  m
        builder.add(InetAddress.getLocalHost().getHostAddress());
    } catch (IOException e) {
        // try next.
    }
    try {
        builder.add(InetAddress.getByName(null).getHostAddress());
    } catch (IOException e) {
        // try next.
    }
    try {
        for (InetAddress inetAddress : InetAddress.getAllByName("localhost")) {
            builder.add(inetAddress.getHostAddress());
        }
    } catch (IOException e) {
        // check at the end.
    }
    ImmutableSet<String> localHostSet = builder.build();
    if (localHostSet.isEmpty()) {
        logger.warning("Unable to lookup local addresses.");
    }
    return localHostSet;
}

From source file:org.apache.calcite.rel.core.CorrelationId.java

/** Converts a set of correlation ids to a set of names. */
public static ImmutableSet<CorrelationId> setOf(Set<String> set) {
    if (set.isEmpty()) {
        return ImmutableSet.of();
    }/*from www  . j a  v  a  2s .c  o  m*/
    final ImmutableSet.Builder<CorrelationId> builder = ImmutableSet.builder();
    for (String s : set) {
        builder.add(new CorrelationId(s));
    }
    return builder.build();
}

From source file:org.apache.calcite.rel.core.CorrelationId.java

/** Converts a set of names to a set of correlation ids. */
public static Set<String> names(Set<CorrelationId> set) {
    if (set.isEmpty()) {
        return ImmutableSet.of();
    }/*from ww  w.ja  v a2  s.  com*/
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    for (CorrelationId s : set) {
        builder.add(s.name);
    }
    return builder.build();
}

From source file:org.elasticsearch.script.ScriptContextRegistry.java

private static ImmutableSet<String> reservedScriptContexts() {
    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    for (ScriptService.ScriptType scriptType : ScriptService.ScriptType.values()) {
        builder.add(scriptType.toString());
    }/*from   w  w  w  .j av a  2  s  .c om*/
    for (ScriptContext.Standard scriptContext : ScriptContext.Standard.values()) {
        builder.add(scriptContext.getKey());
    }
    builder.add("script").add("engine");
    return builder.build();
}

From source file:com.google.caliper.core.Parameters.java

private static ImmutableSet<String> findDefaults(Field field) {
    String[] defaultsAsStrings = field.getAnnotation(Param.class).value();
    if (defaultsAsStrings.length > 0) {
        return ImmutableSet.copyOf(defaultsAsStrings);
    }/*ww  w  .j  ava 2 s .  com*/

    Class<?> type = field.getType();
    if (type == boolean.class) {
        return ALL_BOOLEANS;
    }

    if (type.isEnum()) {
        ImmutableSet.Builder<String> builder = ImmutableSet.builder();
        for (Object enumConstant : type.getEnumConstants()) {
            builder.add(enumConstant.toString());
        }
        return builder.build();
    }
    return ImmutableSet.of();
}