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.apache.brooklyn.core.location.LocationPredicates.java

public static <T> Predicate<Location> configEqualTo(final ConfigKey<T> configKey, final T val) {
    return configSatisfies(configKey, Predicates.equalTo(val));
}

From source file:com.eucalyptus.tags.Tags.java

private static Tag lookup(final Tag example) throws NoSuchMetadataException {
    try {/*from  w ww. j  a  v a  2s  .co  m*/
        final List<Tag> result = Transactions.filter(example,
                Predicates.compose(Predicates.equalTo(example.getResourceId()), Tags.resourceId()));
        if (result.size() == 1) {
            return result.get(0);
        }
    } catch (Exception e) {
        throw new NoSuchMetadataException(
                "Failed to find tag: " + example.getKey() + " for " + example.getOwner(), e);
    }

    throw new NoSuchMetadataException(
            "Failed to find unique tag: " + example.getKey() + " for " + example.getOwner());
}

From source file:org.eclipse.xtext.util.formallang.NfaUtil.java

public <S, ITERABLE extends Iterable<? extends S>> boolean canReachFinalState(Nfa<S> nfa, S state) {
    return find(nfa, Collections.singleton(state), Predicates.equalTo(nfa.getStop())) != null;
}

From source file:tile80.tile80.Tile80.java

public Tile80 removeKey(String key) {
    return new Tile80Eager(getPos(), getId(), getTags(), getBehavior(),
            Maps.filterKeys(getKeyspace(), Predicates.equalTo(key)));
}

From source file:com.android.builder.internal.packaging.IncrementalPackager.java

/**
 * Updates files in the archive.//w  w  w  . ja  v  a  2 s.  c  o  m
 *
 * @param updates the updates to perform
 * @throws IOException failed to update the archive
 */
private void updateFiles(@NonNull Set<PackagedFileUpdate> updates) throws IOException {
    Preconditions.checkNotNull(mApkCreator, "mApkCreator == null");

    Iterable<String> deletedPaths = Iterables
            .transform(
                    Iterables
                            .filter(updates,
                                    Predicates.compose(Predicates.equalTo(FileStatus.REMOVED),
                                            PackagedFileUpdate.EXTRACT_STATUS)),
                    PackagedFileUpdate.EXTRACT_NAME);

    for (String deletedPath : deletedPaths) {
        mApkCreator.deleteFile(deletedPath);
    }

    Predicate<PackagedFileUpdate> isNewOrChanged = Predicates.compose(
            Predicates.or(Predicates.equalTo(FileStatus.NEW), Predicates.equalTo(FileStatus.CHANGED)),
            PackagedFileUpdate.EXTRACT_STATUS);

    Function<PackagedFileUpdate, File> extractBaseFile = Functions.compose(RelativeFile.EXTRACT_BASE,
            PackagedFileUpdate.EXTRACT_SOURCE);

    Iterable<PackagedFileUpdate> newOrChangedNonArchiveFiles = Iterables.filter(updates,
            Predicates.and(isNewOrChanged, Predicates.compose(Files.isDirectory(), extractBaseFile)));

    for (PackagedFileUpdate rf : newOrChangedNonArchiveFiles) {
        mApkCreator.writeFile(rf.getSource().getFile(), rf.getName());
    }

    Iterable<PackagedFileUpdate> newOrChangedArchiveFiles = Iterables.filter(updates,
            Predicates.and(isNewOrChanged, Predicates.compose(Files.isFile(), extractBaseFile)));

    Iterable<File> archives = Iterables.transform(newOrChangedArchiveFiles, extractBaseFile);
    Set<String> names = Sets
            .newHashSet(Iterables.transform(newOrChangedArchiveFiles, PackagedFileUpdate.EXTRACT_NAME));

    /*
     * Build the name map. The name of the file in the filesystem (or zip file) may not
     * match the name we want to package it as. See PackagedFileUpdate for more information.
     */
    Map<String, String> pathNameMap = Maps.newHashMap();
    for (PackagedFileUpdate archiveUpdate : newOrChangedArchiveFiles) {
        pathNameMap.put(archiveUpdate.getSource().getOsIndependentRelativePath(), archiveUpdate.getName());
    }

    for (File arch : Sets.newHashSet(archives)) {
        mApkCreator.writeZip(arch, pathNameMap::get, name -> !names.contains(name));
    }
}

From source file:brooklyn.entity.basic.AbstractGroupImpl.java

/**
 * Adds the given entity as a member of this group <em>and</em> this group as one of the groups of the child
 *///from  www.ja va2s .c  om
@Override
public boolean addMember(Entity member) {
    synchronized (members) {
        if (Entities.isNoLongerManaged(member)) {
            // Don't add dead entities, as they could never be removed (because addMember could be called in
            // concurrent thread as removeMember triggered by the unmanage).
            // Not using Entities.isManaged here, as could be called in entity.init()
            log.debug("Group {} ignoring new member {}, because it is no longer managed", this, member);
            return false;
        }

        // FIXME do not set sensors on members; possibly we don't need FIRST at all, just look at the first in MEMBERS, and take care to guarantee order there
        Entity first = getAttribute(FIRST);
        if (first == null) {
            ((EntityLocal) member).setAttribute(FIRST_MEMBER, true);
            ((EntityLocal) member).setAttribute(FIRST, member);
            setAttribute(FIRST, member);
        } else {
            if (first.equals(member) || first.equals(member.getAttribute(FIRST))) {
                // do nothing (rebinding)
            } else {
                ((EntityLocal) member).setAttribute(FIRST_MEMBER, false);
                ((EntityLocal) member).setAttribute(FIRST, first);
            }
        }

        member.addGroup((Group) getProxyIfAvailable());
        boolean changed = addMemberInternal(member);
        if (changed) {
            log.debug("Group {} got new member {}", this, member);
            setAttribute(GROUP_SIZE, getCurrentSize());
            setAttribute(GROUP_MEMBERS, getMembers());
            // emit after the above so listeners can use getMembers() and getCurrentSize()
            emit(MEMBER_ADDED, member);

            if (Boolean.TRUE.equals(getConfig(MEMBER_DELEGATE_CHILDREN))) {
                Optional<Entity> result = Iterables.tryFind(getChildren(), Predicates.equalTo(member));
                if (!result.isPresent()) {
                    String nameFormat = Optional.fromNullable(getConfig(MEMBER_DELEGATE_NAME_FORMAT)).or("%s");
                    DelegateEntity child = addChild(EntitySpec.create(DelegateEntity.class)
                            .configure(DelegateEntity.DELEGATE_ENTITY, member)
                            .displayName(String.format(nameFormat, member.getDisplayName())));
                    Entities.manage(child);
                }
            }

            getManagementSupport().getEntityChangeListener().onMembersChanged();
        }
        return changed;
    }
}

From source file:net.derquinse.common.meta.MetaProperty.java

/**
 * Returns a predicate that evaluates to {@code true} if the property value {@code equals()} the
 * given target or both are null.// w  w w.java2s .co  m
 */
public final Predicate<C> equalTo(@Nullable T target) {
    return compose(Predicates.equalTo(target));
}

From source file:org.polymap.core.data.ui.featuretable.DeferredFeatureContentProvider2.java

protected int doFindElement(Object[] elms, Object search) {
    assert search != null;
    if (search instanceof IFeatureTableElement && elms != null) {
        return Iterables.indexOf(Arrays.asList(elms), Predicates.equalTo(search));
    }/*from   w ww  .j a v  a 2 s. c o m*/
    return -1;
}

From source file:me.emmy.db.MySQLLayer.java

private boolean tableExists() {
    //      InputStream stream = MySQLLayer.class
    //            .getResourceAsStream("/verifyTable.sql");
    //      String sql = String.format(new Scanner(stream).useDelimiter("\\A")
    //            .next(), schema, playerTable.name());
    boolean exists = Iterables.any(jdbc.query("show tables", StringMapper.instance),
            Predicates.equalTo(playerTable.name()));
    return exists;
}

From source file:org.eclipse.sirius.diagram.ui.tools.internal.providers.decorators.SubDiagramDecorator.java

private boolean shouldHaveSubDiagDecoration(DRepresentationElement node) {
    EObject target = node.getTarget();// w  w w.  jav a 2 s  .  c o  m
    boolean shouldHaveSubDiagramDecorator = false;
    if (target != null && target.eResource() != null) {

        if (session != null && !parentHasSameSemanticElement(node)) {
            // Does the target element has any representation on it? Exclude
            // the current representation itself to avoid redundant markers.
            DRepresentation representation = new DRepresentationElementQuery(node).getParentRepresentation();
            Predicate<DRepresentation> otherReperesentation = Predicates
                    .not(Predicates.equalTo(representation));
            shouldHaveSubDiagramDecorator = Iterables
                    .any(DialectManager.INSTANCE.getRepresentations(target, session), otherReperesentation);
            if (node.getMapping() != null && !shouldHaveSubDiagramDecorator) {
                shouldHaveSubDiagramDecorator = checkRepresentationNavigationDescriptions(node);
            }
        }
    }
    return shouldHaveSubDiagramDecorator;
}