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:com.uber.rave.compiler.CompilerUtils.java

private static void build(
        Map<Class<? extends Annotation>, ImmutableSet.Builder<Class<? extends Annotation>>> temp,
        Class<? extends Annotation> annotation1, Class<? extends Annotation> annotation2) {
    ImmutableSet.Builder<Class<? extends Annotation>> builder = temp.get(annotation1);
    if (builder == null) {
        builder = new ImmutableSet.Builder<>();
        temp.put(annotation1, builder);/*w  ww. j a  v a  2  s.  co  m*/
    }
    builder.add(annotation2);
}

From source file:com.tomtom.speedtools.objects.Immutables.java

/**
 * Returns an immutable set containing elements from elts1, concatenated with elts2. The order of the elements will
 * be preserved (by means of a {@link LinkedHashSet}. When given collection was already an immutable set, this set
 * is simply returned.//from   ww w . ja  va 2s  . co m
 *
 * @param <T>   Element type.
 * @param elts1 Initial elements for the set.
 * @param elts2 Elements to be concatenated.
 * @return Immutable set.
 */
@SafeVarargs
@Nonnull
public static <T> Set<T> setOf(@Nonnull final Collection<? extends T> elts1, @Nonnull final T... elts2) {
    assert elts1 != null;
    assert elts2 != null;
    if (elts1.isEmpty()) {
        return setOf(elts2);
    }
    if (elts2.length == 0) {
        return setOf(elts1);
    }
    final ImmutableSet.Builder<T> builder = ImmutableSet.builder();
    builder.addAll(elts1);
    builder.add(elts2);
    return builder.build();
}

From source file:com.google.devtools.build.xcode.common.TargetDeviceFamily.java

/**
 * Converts the {@code TARGETED_DEVICE_FAMILY} setting in build settings to a set of
 * {@code TargetedDevice}s./*  w w  w  . j  av a 2  s . co  m*/
 */
public static Set<TargetDeviceFamily> fromBuildSetting(String targetedDevice) {
    ImmutableSet.Builder<TargetDeviceFamily> result = ImmutableSet.builder();
    for (String numericSetting : Splitter.on(",").split(targetedDevice)) {
        numericSetting = numericSetting.trim();
        switch (numericSetting) {
        case "1":
            result.add(IPHONE);
            break;
        case "2":
            result.add(IPAD);
            break;
        default:
            throw new IllegalArgumentException("Expect comma-separated list containing only '1' and/or '2' for "
                    + "TARGETED_DEVICE_FAMILY: " + targetedDevice);
        }
    }
    return result.build();
}

From source file:org.opendaylight.groupbasedpolicy.util.SubjectResolverUtils.java

private static ConditionSet buildConditionSet(List<ConditionMatcher> condMatchers) {
    if (condMatchers == null)
        return ConditionSet.EMPTY;

    ImmutableSet.Builder<ConditionName> allb = ImmutableSet.builder();
    ImmutableSet.Builder<ConditionName> noneb = ImmutableSet.builder();
    ImmutableSet.Builder<Set<ConditionName>> anyb = ImmutableSet.builder();
    for (ConditionMatcher condMatcher : condMatchers) {
        if (condMatcher.getCondition() == null)
            continue;
        MatchType type = condMatcher.getMatchType();
        if (type == null)
            type = MatchType.All;//from w  w  w.j a  v a 2 s.co m
        if (type.equals(MatchType.Any)) {
            ImmutableSet.Builder<ConditionName> a = ImmutableSet.builder();
            for (Condition c : condMatcher.getCondition()) {
                a.add(c.getName());
            }
            anyb.add(a.build());
        } else {
            for (Condition c : condMatcher.getCondition()) {
                switch (type) {
                case Any:
                    break;
                case None:
                    noneb.add(c.getName());
                    break;
                case All:
                default:
                    allb.add(c.getName());
                    break;
                }
            }
        }
    }
    return new ConditionSet(allb.build(), noneb.build(), anyb.build());
}

From source file:google.registry.flows.domain.DomainTransferUtils.java

/**
 * Sets up {@link TransferData} for a domain with links to entities for server approval.
 *///w  w  w  .j a va2 s  .  c  o  m
public static TransferData createPendingTransferData(TransferData.Builder transferDataBuilder,
        ImmutableSet<TransferServerApproveEntity> serverApproveEntities) {
    ImmutableSet.Builder<Key<? extends TransferServerApproveEntity>> serverApproveEntityKeys = new ImmutableSet.Builder<>();
    for (TransferServerApproveEntity entity : serverApproveEntities) {
        serverApproveEntityKeys.add(Key.create(entity));
    }
    return transferDataBuilder.setTransferStatus(TransferStatus.PENDING)
            .setServerApproveBillingEvent(
                    Key.create(getOnlyElement(filter(serverApproveEntities, BillingEvent.OneTime.class))))
            .setServerApproveAutorenewEvent(
                    Key.create(getOnlyElement(filter(serverApproveEntities, BillingEvent.Recurring.class))))
            .setServerApproveAutorenewPollMessage(
                    Key.create(getOnlyElement(filter(serverApproveEntities, PollMessage.Autorenew.class))))
            .setServerApproveEntities(serverApproveEntityKeys.build()).build();
}

From source file:com.google.javascript.jscomp.newtypes.EnumType.java

static ImmutableSet<EnumType> normalizeForJoin(ImmutableSet<EnumType> newEnums, JSType joinWithoutEnums) {
    boolean recreateEnums = false;
    for (EnumType e : newEnums) {
        if (e.declaredType.isSubtypeOf(joinWithoutEnums)) {
            recreateEnums = true;/*from  w w w  .  ja  va 2 s. c o  m*/
            break;
        }
    }
    if (!recreateEnums) {
        return newEnums;
    }
    ImmutableSet.Builder<EnumType> builder = ImmutableSet.builder();
    for (EnumType e : newEnums) {
        if (!e.declaredType.isSubtypeOf(joinWithoutEnums)) {
            builder.add(e);
        }
    }
    return builder.build();
}

From source file:com.spectralogic.ds3autogen.utils.ConverterUtil.java

/**
 * Gets a set of type names used within a list of Ds3Params
 *///  w  w  w . j a va2s .co m
protected static ImmutableSet<String> getUsedTypesFromParams(final ImmutableList<Ds3Param> params) {
    if (isEmpty(params)) {
        return ImmutableSet.of();
    }
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    for (final Ds3Param param : params) {
        if (includeType(param.getType())) {
            builder.add(param.getType());
        }
    }
    return builder.build();
}

From source file:org.openspotlight.common.util.SLCollections.java

public static <T> Iterable<T> iterableOf(final T... ts) {
    final ImmutableSet.Builder<T> builder = ImmutableSet.builder();
    for (final T tn : ts) {
        builder.add(tn);
    }/*w w w . ja  va  2  s .co  m*/
    return builder.build();
}

From source file:dagger.internal.codegen.writer.Snippet.java

public static Snippet format(String format, Object... args) {
    ImmutableSet.Builder<TypeName> types = ImmutableSet.builder();
    for (Object arg : args) {
        if (arg instanceof Snippet) {
            types.addAll(((Snippet) arg).types());
        }/*from ww  w.jav a 2s.c  o m*/
        if (arg instanceof TypeName) {
            types.add((TypeName) arg);
        }
        if (arg instanceof HasTypeName) {
            types.add(((HasTypeName) arg).name());
        }
    }
    return new BasicSnippet(format, types.build(), ImmutableList.copyOf(args));
}

From source file:com.facebook.buck.android.toolchain.impl.AndroidPlatformTargetProducer.java

/**
 * Given the path to the Android SDK as well as the platform path within the Android SDK, find all
 * the files needed to create the {@link AndroidPlatformTarget}, assuming that the organization of
 * the Android SDK conforms to the ordinary directory structure.
 *//* w ww  . j av a  2  s . c o m*/
@VisibleForTesting
static AndroidPlatformTarget createFromDefaultDirectoryStructure(ProjectFilesystem filesystem, String name,
        AndroidBuildToolsLocation androidBuildToolsLocation, AndroidSdkLocation androidSdkLocation,
        String platformDirectoryPath, Set<Path> additionalJarPaths, Optional<Supplier<Tool>> aaptOverride,
        Optional<Supplier<Tool>> aapt2Override) {
    Path androidSdkDir = androidSdkLocation.getSdkRootPath();
    if (!androidSdkDir.isAbsolute()) {
        throw new HumanReadableException("Path to Android SDK must be absolute but was: %s.", androidSdkDir);
    }

    Path platformDirectory = androidSdkDir.resolve(platformDirectoryPath);
    Path androidJar = platformDirectory.resolve("android.jar");

    // Add any libraries found in the optional directory under the Android SDK directory. These
    // go at the head of the bootclasspath before any additional jars.
    File optionalDirectory = platformDirectory.resolve("optional").toFile();
    if (optionalDirectory.exists() && optionalDirectory.isDirectory()) {
        String[] optionalDirList = optionalDirectory.list(new AddonFilter());
        if (optionalDirList != null) {
            Arrays.sort(optionalDirList);
            ImmutableSet.Builder<Path> additionalJars = ImmutableSet.builder();
            for (String file : optionalDirList) {
                additionalJars.add(optionalDirectory.toPath().resolve(file));
            }
            additionalJars.addAll(additionalJarPaths);
            additionalJarPaths = additionalJars.build();
        }
    }

    LinkedList<Path> bootclasspathEntries = Lists.newLinkedList(additionalJarPaths);

    // Make sure android.jar is at the front of the bootclasspath.
    bootclasspathEntries.addFirst(androidJar);

    // This is the directory under the Android SDK directory that contains the dx script, jack,
    // jill, and binaries.
    Path buildToolsDir = androidBuildToolsLocation.getBuildToolsPath();
    Path buildToolsBinDir = androidBuildToolsLocation.getBuildToolsBinPath();
    String version = buildToolsDir.getFileName().toString();

    Path zipAlignExecutable = androidSdkDir.resolve("tools/zipalign").toAbsolutePath();
    if (!zipAlignExecutable.toFile().exists()) {
        // Android SDK Build-tools >= 19.1.0 have zipalign under the build-tools directory.
        zipAlignExecutable = androidSdkDir.resolve(buildToolsBinDir).resolve("zipalign").toAbsolutePath();
    }

    Path androidFrameworkIdlFile = platformDirectory.resolve("framework.aidl");
    Path proguardJar = androidSdkDir.resolve("tools/proguard/lib/proguard.jar");
    Path proguardConfig = androidSdkDir.resolve("tools/proguard/proguard-android.txt");
    Path optimizedProguardConfig = androidSdkDir.resolve("tools/proguard/proguard-android-optimize.txt");

    return AndroidPlatformTarget
            .of(name, androidJar.toAbsolutePath(), bootclasspathEntries,
                    aaptOverride
                            .orElse(() -> VersionedTool
                                    .of(PathSourcePath.of(filesystem,
                                            androidSdkDir.resolve(androidBuildToolsLocation.getAaptPath())
                                                    .toAbsolutePath()),
                                            "aapt", version)),
                    aapt2Override.orElse(() -> VersionedTool.of(PathSourcePath.of(filesystem,
                            androidSdkDir.resolve(androidBuildToolsLocation.getAapt2Path()).toAbsolutePath()),
                            "aapt2", version)),
                    androidSdkDir.resolve("platform-tools/adb").toAbsolutePath(),
                    androidSdkDir.resolve(buildToolsBinDir).resolve("aidl").toAbsolutePath(),
                    zipAlignExecutable,
                    buildToolsDir.resolve(Platform.detect() == Platform.WINDOWS ? "dx.bat" : "dx")
                            .toAbsolutePath(),
                    androidFrameworkIdlFile, proguardJar, proguardConfig, optimizedProguardConfig);
}