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

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

Introduction

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

Prototype

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

Source Link

Usage

From source file:com.google.cloud.security.scanner.primitives.GCPResourcePolicyDiff.java

/**
 * Construct a GCPResourcePolicyDiff object from two GCPResourcePolicy objects.
 *
 * @param firstPolicy The first policy object.
 * @param secondPolicy The second policy object.
 * @return A GCPResourcePolicyDiff object that represents the difference between the two policies.
 *///from  w  w w. j  a  v  a2 s. co m
public static GCPResourcePolicyDiff diff(GCPResourcePolicy firstPolicy, GCPResourcePolicy secondPolicy) {
    Set<PolicyBindingDelta> firstPolicyBindings = flattenBindings(firstPolicy);
    Set<PolicyBindingDelta> secondPolicyBindings = flattenBindings(secondPolicy);
    Set<PolicyBindingDelta> removedBindings = new HashSet<>(firstPolicyBindings);
    removedBindings.removeAll(secondPolicyBindings);
    Set<PolicyBindingDelta> addedBindings = new HashSet<>(secondPolicyBindings);
    addedBindings.removeAll(firstPolicyBindings);

    ImmutableList.Builder<PolicyBindingDelta> deltas = ImmutableList.builder();
    for (PolicyBindingDelta delta : removedBindings) {
        deltas.add(
                new PolicyBindingDelta(delta.getRole(), delta.getMember(), PolicyBindingDelta.Action.REMOVED));
    }

    for (PolicyBindingDelta delta : addedBindings) {
        deltas.add(new PolicyBindingDelta(delta.getRole(), delta.getMember(), PolicyBindingDelta.Action.ADDED));
    }

    return new GCPResourcePolicyDiff(firstPolicy, secondPolicy, deltas.build());
}

From source file:com.project4.PersonsResource.java

@GET
@Produces(MediaType.APPLICATION_JSON)/*from   ww  w. jav a2 s  . c om*/
public Response listAll() {
    Builder<PersonRepresentation> builder = ImmutableList.builder();
    for (Person person : store.getAll()) {
        builder.add(from(person, null));
    }
    return Response.ok(builder.build()).build();
}

From source file:com.google.devtools.build.lib.skyframe.PrepareDepsOfPatternsFunction.java

public static ImmutableList<SkyKey> getSkyKeys(SkyKey skyKey, EventHandler eventHandler) {
    TargetPatternSequence targetPatternSequence = (TargetPatternSequence) skyKey.argument();
    Iterable<PrepareDepsOfPatternSkyKeyOrException> keysMaybe = PrepareDepsOfPatternValue
            .keys(targetPatternSequence.getPatterns(), targetPatternSequence.getOffset());

    ImmutableList.Builder<SkyKey> skyKeyBuilder = ImmutableList.builder();
    boolean handlerIsParseFailureListener = eventHandler instanceof ParseFailureListener;
    for (PrepareDepsOfPatternSkyKeyOrException skyKeyOrException : keysMaybe) {
        try {//from   www  .  java2  s.c  o  m
            skyKeyBuilder.add(skyKeyOrException.getSkyKey());
        } catch (TargetParsingException e) {
            handleTargetParsingException(eventHandler, handlerIsParseFailureListener,
                    skyKeyOrException.getOriginalPattern(), e);
        }
    }

    return skyKeyBuilder.build();
}

From source file:org.lenskit.util.keys.KeyedObjectMapBuilder.java

public KeyedObjectMapBuilder(KeyExtractor<? super T> ex) {
    extractor = ex;
    builder = ImmutableList.builder();
}

From source file:org.sonar.plugins.j3c.J3cPlugin.java

@Override
public List<Class<? extends Extension>> getExtensions() {

    ImmutableList.Builder<Class<? extends Extension>> extensions = ImmutableList.builder();
    extensions.add(J3cConfiguration.class);
    extensions.add(J3cSensor.class);
    extensions.add(J3cWidget.class);
    extensions.add(J3cMetrics.class);

    return extensions.build();
}

From source file:org.apache.aurora.scheduler.resources.AcceptedOffer.java

public static AcceptedOffer create(Offer offer, IAssignedTask task, ResourceBag executorOverhead,
        TierInfo tierInfo) throws ResourceManager.InsufficientResourcesException {

    ImmutableList.Builder<Resource> taskResources = ImmutableList.builder();
    ImmutableList.Builder<Resource> executorResources = ImmutableList.builder();

    ResourceManager.bagFromResources(task.getTask().getResources()).streamResourceVectors().forEach(entry -> {
        ResourceType type = entry.getKey();
        Iterable<Resource.Builder> offerResources = StreamSupport
                .stream(getOfferResources(offer, tierInfo, entry.getKey()).spliterator(), false)
                // Note the reverse order of args in .compare(): we want RESERVED resources first.
                .sorted((l, r) -> Boolean.compare(RESERVED.test(r), RESERVED.test(l))).map(Resource::toBuilder)
                .collect(toList());//  w  ww.j  a va  2  s  .co  m

        boolean isRevocable = type.isMesosRevocable() && tierInfo.isRevocable();

        taskResources.addAll(type.getMesosResourceConverter().toMesosResource(offerResources,
                type.getMapper().isPresent() ? () -> type.getMapper().get().getAssigned(task)
                        : () -> entry.getValue(),
                isRevocable));

        if (executorOverhead.getResourceVectors().containsKey(type)) {
            executorResources.addAll(type.getMesosResourceConverter().toMesosResource(offerResources,
                    () -> executorOverhead.getResourceVectors().get(type), isRevocable));
        }
    });

    return new AcceptedOffer(taskResources.build(), executorResources.build());
}

From source file:org.acz.mailsplat.MessagesResource.java

@GET
@Produces(MediaType.APPLICATION_JSON)//from  ww  w .  j ava  2 s.  co  m
public Response listAll() {
    Builder<MessageRepresentation> builder = ImmutableList.builder();
    for (Message message : store.getAll()) {
        builder.add(from(message, null, false));
    }
    return Response.ok(builder.build()).build();
}

From source file:com.tkmtwo.sarapi.mapping.EntryMappingOperation.java

public void addEntryHandler(EntryHandler eh) {
    ImmutableList.Builder<EntryHandler> ilb = new ImmutableList.Builder<EntryHandler>()
            .addAll(getEntryHandlers()).add(eh);
    entryHandlers = ilb.build();//  w w  w  .  j  a v a2 s.co m
}

From source file:ch.ethz.system.mt.tpch.Distribution.java

public Distribution(String name, Map<String, Integer> distribution) {
    this.name = checkNotNull(name, "name is null");
    checkNotNull(distribution, "distribution is null");

    ImmutableList.Builder<String> values = ImmutableList.builder();
    this.weights = new int[distribution.size()];

    int runningWeight = 0;
    int index = 0;
    boolean isValidDistribution = true;
    for (Entry<String, Integer> entry : distribution.entrySet()) {
        values.add(entry.getKey());/*from   w ww.ja  v a  2 s. c  o  m*/

        runningWeight += entry.getValue();
        weights[index] = runningWeight;

        isValidDistribution = isValidDistribution && entry.getValue() > 0;

        index++;
    }
    this.values = values.build();

    // "nations" is hack and not a valid distribution so we need to skip it
    if (isValidDistribution) {
        this.maxWeight = weights[weights.length - 1];
        this.distribution = new String[maxWeight];

        index = 0;
        for (String value : this.values) {
            int count = distribution.get(value);
            for (int i = 0; i < count; i++) {
                this.distribution[index++] = value;
            }
        }
    } else {
        this.maxWeight = -1;
        this.distribution = null;
    }
}

From source file:org.sonar.plugins.spcaf.spcafPluginCss.java

/**
 * {@inheritDoc}//from   w w w  .ja  v  a 2 s.co  m
 */
@Override
public List getExtensions() {
    ImmutableList.Builder builder = ImmutableList.builder();

    // Plugin properties and languages
    builder.add(PropertyDefinition.builder(CSS_SUFFIXES_KEY).defaultValue(CSS_SUFFIXES_DEFAULT_VALUE)
            .name("File Suffixes").description("Comma-separated list of suffixes for files to analyze.")
            .subCategory("General").onQualifiers(Qualifiers.PROJECT).build(), Css.class);

    return builder.build();
}