Example usage for com.google.common.base Predicates equalTo

List of usage examples for com.google.common.base Predicates equalTo

Introduction

In this page you can find the example usage for com.google.common.base Predicates equalTo.

Prototype

public static <T> Predicate<T> equalTo(@Nullable T target) 

Source Link

Document

Returns a predicate that evaluates to true if the object being tested equals() the given target or both are null.

Usage

From source file:org.xwiki.extension.test.ExtensionPackager.java

public void generateExtensions() throws IOException {
    Collection<URL> urls = ClasspathHelper.forPackage(PACKAGEFILE_PACKAGE);

    if (!urls.isEmpty()) {
        Reflections reflections = new Reflections(
                new ConfigurationBuilder().setScanners(new ResourcesScanner()).setUrls(urls)
                        .filterInputsBy(new FilterBuilder.Include(FilterBuilder.prefix(PACKAGEFILE_PACKAGE))));

        Set<String> descriptors = reflections.getResources(Predicates.equalTo(PACKAGEFILE_DESCRIPTOR));

        for (String descriptor : descriptors) {
            String classPackageFolder = descriptor.substring(0,
                    descriptor.length() - PACKAGEFILE_DESCRIPTOR.length());
            generateExtension(classPackageFolder, getClass().getClassLoader().getResource(descriptor));
        }//from  w  ww  .ja v a2s  .  c  o  m
    }
}

From source file:org.linagora.linshare.core.domain.vo.UploadRequestEntryVo.java

public static Predicate<? super UploadRequestEntryVo> equalTo(String uuid) {
    UploadRequestEntryVo test = new UploadRequestEntryVo();

    test.setUuid(uuid);/*from  ww w  . java  2  s .com*/
    return Predicates.equalTo(test);
}

From source file:com.eucalyptus.util.CollectionUtils.java

/**
 * Convenience method for a predicate on a property value.
 *
 * @param propertyValue The property value to match
 * @param propertyFunction The function to extract the property
 * @param <T> The predicate type//from w  ww.  j ava 2  s . c  om
 * @param <PT> The property type
 * @return A predicate that extracts a value to compare with the given value.
 */
public static <T, PT> Predicate<T> propertyPredicate(final PT propertyValue,
        final Function<T, PT> propertyFunction) {
    return Predicates.compose(Predicates.equalTo(propertyValue), propertyFunction);
}

From source file:org.apache.brooklyn.entity.nosql.couchbase.CouchbaseSyncGatewaySshDriver.java

@Override
public void launch() {
    Entity cbNode = entity.getConfig(CouchbaseSyncGateway.COUCHBASE_SERVER);
    Entities.waitForServiceUp(cbNode, Duration.ONE_HOUR);
    DependentConfiguration.waitInTaskForAttributeReady(cbNode, CouchbaseCluster.IS_CLUSTER_INITIALIZED,
            Predicates.equalTo(true));
    // Even once the bucket has published its API URL, it can still take a couple of seconds for it to become available
    Time.sleep(10 * 1000);//from   w  ww.  j  av a 2s .  c om
    if (cbNode instanceof CouchbaseCluster) {
        // in_cluster now applies even to a node in a cluster of size 1
        Optional<Entity> cbClusterNode = Iterables.tryFind(cbNode.getAttribute(CouchbaseCluster.GROUP_MEMBERS),
                Predicates.and(Predicates.instanceOf(CouchbaseNode.class),
                        EntityPredicates.attributeEqualTo(CouchbaseNode.IS_IN_CLUSTER, Boolean.TRUE)));

        if (!cbClusterNode.isPresent()) {
            throw new IllegalArgumentException(
                    format("The cluster %s does not contain any suitable Couchbase nodes to connect to..",
                            cbNode.getId()));
        }

        cbNode = cbClusterNode.get();
    }
    String hostname = cbNode.getAttribute(CouchbaseNode.HOSTNAME);
    String webPort = cbNode.getAttribute(CouchbaseNode.COUCHBASE_WEB_ADMIN_PORT).toString();

    String username = cbNode.getConfig(CouchbaseNode.COUCHBASE_ADMIN_USERNAME);
    String password = cbNode.getConfig(CouchbaseNode.COUCHBASE_ADMIN_PASSWORD);

    String bucketName = entity.getConfig(CouchbaseSyncGateway.COUCHBASE_SERVER_BUCKET);
    String pool = entity.getConfig(CouchbaseSyncGateway.COUCHBASE_SERVER_POOL);
    String pretty = entity.getConfig(CouchbaseSyncGateway.PRETTY) ? "-pretty" : "";
    String verbose = entity.getConfig(CouchbaseSyncGateway.VERBOSE) ? "-verbose" : "";

    String adminRestApiPort = entity.getConfig(CouchbaseSyncGateway.ADMIN_REST_API_PORT).iterator().next()
            .toString();
    String syncRestApiPort = entity.getConfig(CouchbaseSyncGateway.SYNC_REST_API_PORT).iterator().next()
            .toString();

    String serverWebAdminUrl = format("http://%s:%s@%s:%s", username, password, hostname, webPort);
    String options = format(
            "-url %s -bucket %s -adminInterface 0.0.0.0:%s -interface 0.0.0.0:%s -pool %s %s %s",
            serverWebAdminUrl, bucketName, adminRestApiPort, syncRestApiPort, pool, pretty, verbose);

    newScript(ImmutableMap.of("usePidFile", true), LAUNCHING).body
            .append(format("/opt/couchbase-sync-gateway/bin/sync_gateway %s ", options)
                    + "> out.log 2> err.log < /dev/null &")
            .failOnNonZeroResultCode().execute();
}

From source file:org.apache.brooklyn.core.typereg.RegisteredTypePredicates.java

public static Predicate<RegisteredType> version(final String name) {
    return version(Predicates.equalTo(name));
}

From source file:net.seedboxer.core.logic.ContentManager.java

private boolean isContentIn(Content content, List<Content> historyContentOfType) {
    Optional<Content> find = Iterables.tryFind(historyContentOfType, Predicates.equalTo(content));
    return find.isPresent();
}

From source file:com.qcadoo.mes.materialFlow.hooks.TransformationsModelValidators.java

public boolean checkIfTransfersAreValid(final DataDefinition transformationsDD, final Entity transformations) {
    List<Entity> transfersConsumption = transformations.getHasManyField(TRANSFERS_CONSUMPTION);
    List<Entity> transfersProduction = transformations.getHasManyField(TRANSFERS_PRODUCTION);

    Iterable<Boolean> validationResults = Lists.newArrayList(areTransfersValid(transfersConsumption),
            areTransfersValid(transfersProduction),
            checkIfTransfersNumbersAreDistinct(transfersConsumption, transfersProduction),
            checkIfTransfersNumbersAreDistinct(transfersProduction, transfersConsumption));
    return Iterables.all(validationResults, Predicates.equalTo(true));
}

From source file:com.eucalyptus.loadbalancing.config.LoadBalancingServiceBuilder.java

@SuppressWarnings("unchecked")
private boolean noOtherEnabled(final ServiceConfiguration config) {
    return Iterables.isEmpty(ServiceConfigurations.filter(LoadBalancing.class,
            Predicates.and(ServiceConfigurations.filterHostLocal(), ServiceConfigurations.filterEnabled(),
                    Predicates.not(Predicates.equalTo(config)))));
}

From source file:org.jclouds.vagrant.internal.MachineConfig.java

public void save(Map<String, Object> config) {
    File parent = configPath.getParentFile();
    if (!parent.exists() && !parent.mkdirs()) {
        if (!parent.exists()) {
            throw new IllegalStateException("Failure creating folder " + parent.getAbsolutePath());
        }/*w  w  w. ja  v a2s  .co m*/
    }

    Map<String, Object> configWithoutVersion = Maps.filterKeys(config,
            Predicates.not(Predicates.equalTo(VagrantConstants.CONFIG_JCLOUDS_VERSION)));
    String version = VagrantConstants.CONFIG_JCLOUDS_VERSION + ": " + JcloudsVersion.get().toString() + "\n";
    String output = version + Joiner.on("\n").withKeyValueSeparator(": ").join(configWithoutVersion);

    FileOutputStream fileOut = null;
    BufferedWriter out = null;

    try {
        fileOut = new FileOutputStream(configPath);
        out = new BufferedWriter(new OutputStreamWriter(fileOut, Charsets.UTF_8));
        out.write(output);
    } catch (IOException e) {
        throw new IllegalStateException("Failed writing to machine config file " + configPath.getAbsolutePath(),
                e);
    } finally {
        if (out != null) {
            Closeables2.closeQuietly(out);
        } else if (fileOut != null) {
            Closeables2.closeQuietly(fileOut);
        }
    }
}

From source file:com.eucalyptus.cloudformation.config.CloudFormationServiceBuilder.java

@SuppressWarnings("unchecked")
private boolean noOtherEnabled(final ServiceConfiguration config) {
    return Iterables.isEmpty(ServiceConfigurations.filter(CloudFormation.class,
            Predicates.and(ServiceConfigurations.filterHostLocal(), ServiceConfigurations.filterEnabled(),
                    Predicates.not(Predicates.equalTo(config)))));
}