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:graph.features.cpp.NodeOfDegree1Pruning.java

private Map<T, Integer> computeData(final UndirectedGraph<T> graph) {

    final Map<T, Integer> deltas = Maps.newHashMap();

    final DegreeInterface<T> degreeInterface = graph.fetch(DegreeFeature.class).up();

    final ImmutableSet.Builder<WeightedEdge<T>> doubledEdgesbuilder = new ImmutableSet.Builder<WeightedEdge<T>>();

    final Map<T, Integer> nodesWithDegree1 = degreeInterface.getNodesHavingDegree(1);
    final List<T> nodes = Lists.newArrayList(nodesWithDegree1.keySet());
    for (final T node : nodes) {
        final WeightedEdge<T> edge = graph.getEdgesFrom(node).iterator().next();
        Integer integer1 = deltas.get(edge.getEndPoint1());
        if (integer1 == null)
            integer1 = 0;//from  w ww.ja  v  a2  s .c o m
        deltas.put(edge.getEndPoint1(), integer1 + 1);
        Integer integer2 = deltas.get(edge.getEndPoint2());
        if (integer2 == null)
            integer2 = 0;
        deltas.put(edge.getEndPoint2(), integer2 + 1);
        doubledEdgesbuilder.add(edge);
    }
    this.doubledEdges = doubledEdgesbuilder.build();

    final Builder<T, Integer> remainingOddVerticesBuilder = new ImmutableMap.Builder<T, Integer>();
    final Set<T> remainingOddVertices = Sets.newHashSet();
    for (final Entry<T, Integer> entry : degreeInterface.getDegreeByNode().entrySet()) {
        final T node = entry.getKey();
        final Integer degree = entry.getValue();
        Integer delta = deltas.get(node);
        if (delta == null)
            delta = 0;
        remainingOddVerticesBuilder.put(node, degree + delta);
        if ((degree + delta) % 2 == 1)
            remainingOddVertices.add(node);
    }
    this.remainingOddVertices = remainingOddVertices;

    return remainingOddVerticesBuilder.build();
}

From source file:org.fcrepo.kernel.utils.impl.DistributedFixityCheck.java

@Override
public Collection<FixityResult> call() throws Exception {
    final ImmutableSet.Builder<FixityResult> fixityResults = new ImmutableSet.Builder<>();

    for (final CacheStore store : stores()) {

        final String digest = ContentDigest.getAlgorithm(new URI("urn:sha1"));

        FixityInputStream fixityInputStream;
        final InputStream cacheLoaderChunkInputStream = new StoreChunkInputStream(store, dataKey);

        fixityInputStream = new FixityInputStream(cacheLoaderChunkInputStream,
                MessageDigest.getInstance(digest));
        IOUtils.copy(fixityInputStream, NULL_OUTPUT_STREAM);

        final URI calculatedChecksum = ContentDigest.asURI(digest,
                fixityInputStream.getMessageDigest().digest());
        fixityResults.add(new FixityResultImpl(getExternalIdentifier(store), fixityInputStream.getByteCount(),
                calculatedChecksum));/*from w  w  w.  j av  a2 s .co m*/
    }

    return fixityResults.build();
}

From source file:org.spongepowered.api.util.GuavaCollectors.java

/**
 * Collect the values from a stream to an {@link ImmutableSet}.
 *
 * @param <T> The type of elements contained in the set
 * @return The appropriate collector//  w w  w .  ja v  a  2  s  .  co  m
 */
@SuppressWarnings({ "unchecked", "rawtypes" }) // We are just sharing an instance
public static <T> Collector<T, ImmutableSet.Builder<T>, ImmutableSet<T>> toImmutableSet() {
    return (Collector) IMMUTABLE_SET_COLLECTOR;
}

From source file:es.udc.pfc.gamelib.chess.MiniChessGame.java

private final ImmutableSet<ChessMovement> getPossibleMovements(final ChessBoard board, final ChessColor turn) {
    final ImmutableSet.Builder<ChessMovement> moves = ImmutableSet.builder();

    for (final ChessPiece piece : board.getAllPieces()) {
        if (!currentTurn.equals(piece.getColor()))
            continue;

        final Position from = board.getPositionFor(piece);

        if (piece instanceof ChessBishop) {
            for (final Position to : ((ChessBishop) piece).getMiniMoves(board)) {
                moves.add(checkMovement(from, to));
            }//from  ww w .java 2  s .  com
        } else {
            for (final Position to : piece.getStandardMoves(board)) {
                moves.add(checkMovement(from, to));
            }
        }
    }

    return moves.build();
}

From source file:org.sosy_lab.cpachecker.cpa.pointer2.util.ExplicitLocationSet.java

@Override
public LocationSet addElements(Iterable<String> pLocations) {
    ImmutableSet.Builder<String> builder = null;
    for (String target : pLocations) {
        if (!explicitSet.contains(target)) {
            if (builder == null) {
                builder = ImmutableSet.builder();
                builder.addAll(explicitSet);
            }//  www. j a  va  2 s . com
            builder.add(target);
        }
    }
    if (builder == null) {
        return this;
    }
    return new ExplicitLocationSet(builder.build());
}

From source file:org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.ImmutableModuleExclusionSet.java

private synchronized void precomputeCaches() {
    if (excludedModules != null) {
        return;// w w  w. j av  a2s.c  o m
    }
    ImmutableSet.Builder<ModuleIdentifier> moduleIds = ImmutableSet.builder();
    ImmutableList.Builder<AbstractModuleExclusion> modules = ImmutableList.builder();
    ImmutableList.Builder<AbstractModuleExclusion> artifacts = ImmutableList.builder();
    for (AbstractModuleExclusion exclusion : delegate) {
        if (exclusion instanceof ModuleIdExcludeSpec) {
            moduleIds.add(((ModuleIdExcludeSpec) exclusion).moduleId);
        } else {
            if (!exclusion.excludesNoModules()) {
                modules.add(exclusion);
            }
            if (exclusion.mayExcludeArtifacts()) {
                artifacts.add(exclusion);
            }
        }
    }
    excludedModules = moduleIds.build();
    moduleExcludes = modules.build();
    artifactExcludes = artifacts.build();
}

From source file:org.jclouds.googlecompute.options.FirewallOptions.java

/**
 * @see org.jclouds.googlecompute.domain.Firewall#getAllowed()
 *///from   w w  w  . j a  va  2  s.c  om
public FirewallOptions allowedRules(Set<Firewall.Rule> allowedRules) {
    this.allowed = ImmutableSet.builder();
    this.allowed.addAll(allowedRules);
    return this;
}

From source file:org.lenskit.data.entities.BasicEntity.java

@Override
public Set<TypedName<?>> getTypedAttributeNames() {
    // TODO Make this more efficient
    ImmutableSet.Builder<TypedName<?>> bld = ImmutableSet.builder();
    for (Attribute<?> name : attributes.values()) {
        bld.add(name.getTypedName());/* ww  w . ja  va  2  s.c  o  m*/
    }
    return bld.build();
}

From source file:com.github.errantlinguist.io.ImmutableSetFileParser.java

/**
 * //from   w  ww.  j ava  2 s.  co  m
 * @param transformer
 *            The {@link Function} used for transforming each file line into
 *            the desired output type.
 */
public ImmutableSetFileParser(final Function<String, O> transformer) {
    parseBuilder = ImmutableSet.builder();

    this.transformer = transformer;

    this.hashCode = calculateHashCode();
}

From source file:ch.ledcom.tomcat.valves.allocation.RequestAllocationRecorderValve.java

public RequestAllocationRecorderValve() {
    disabled = parseBoolean(System.getProperty(PROP_DISABLED), false);
    boolean printSummary = parseBoolean(System.getProperty(PROP_PRINT_SUMMARY), false);
    int printSummaryPeriod = parseInt(System.getProperty(PROP_PRINT_SUMMARY_PERIOD), 1);

    if (!disabled) {
        threadAllocationTracer = new InstrumentedThreadAllocationTracer();
    } else {//from   ww  w  . j  a  v  a  2 s .  c o m
        threadAllocationTracer = null;
    }

    ImmutableSet.Builder<AllocationReporter> builder = ImmutableSet.builder();
    builder.add(new AllocationLogger());

    if (printSummary) {
        builder.add(new SummaryAllocationLogger(printSummaryPeriod));
    }
    reporters = builder.build();
}