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:de.johni0702.sponge.noteblockapi.song.Instrument.java

/**
 * Converts the specified note pitch to a sound effect pitch.
 * @param registry The game registry//from w  w  w .  j a  v a2 s.com
 * @param pitch The note
 * @return The sound effect pitch in range [0, 2]
 */
public float getPitch(GameRegistry registry, NotePitch pitch) {
    Iterator<? extends NotePitch> iter = registry.getAllOf(NotePitch.class).iterator();
    return PITCH[Iterators.indexOf(iter, Predicates.equalTo(pitch))];
}

From source file:org.cryptomator.frontend.webdav.servlet.WebDavServlet.java

@Override
protected boolean isPreconditionValid(WebdavRequest request, DavResource resource) {
    IfHeader ifHeader = new IfHeader(request);
    if (ifHeader.hasValue() && Iterators.all(ifHeader.getAllTokens(), Predicates.equalTo(NO_LOCK))) {
        // https://tools.ietf.org/html/rfc4918#section-10.4.8:
        // "DAV:no-lock" is known to never represent a current lock token.
        return false;
    } else if (ifHeader.hasValue() && Iterators.any(ifHeader.getAllNotTokens(), Predicates.equalTo(NO_LOCK))) {
        // by applying "Not" to a state token that is known not to be current, the Condition always evaluates to true.
        return true;
    } else {/*from  ww  w.j  av a 2  s.co m*/
        return request.matchesIfHeader(resource);
    }
}

From source file:org.richfaces.model.SwingTreeNodeImpl.java

public int getIndex(TreeNode node) {
    return Iterables.indexOf(children, Predicates.equalTo(node));
}

From source file:org.apache.aurora.scheduler.updater.InstanceUpdater.java

private static boolean isPermanentlyKilled(IScheduledTask task) {
    boolean wasKilling = Iterables.any(task.getTaskEvents(),
            Predicates.compose(Predicates.equalTo(KILLING), ITaskEvent::getStatus));
    return task.getStatus() != KILLING && wasKilling;
}

From source file:net.automatalib.util.automata.predicates.TransitionPredicates.java

public static <S, I, T> TransitionPredicate<S, I, T> inputIsNot(Object input) {
    return inputSatisfying(Predicates.not(Predicates.equalTo(input)));
}

From source file:org.apache.aurora.common.net.http.handlers.TimeSeriesDataSource.java

@VisibleForTesting
String getResponse(@Nullable String metricsQuery, @Nullable String sinceQuery) throws MetricException {

    if (metricsQuery == null) {
        // Return metric listing.
        return gson.toJson(ImmutableList.copyOf(timeSeriesRepo.getAvailableSeries()));
    }/*  w  w w  . ja  v a  2 s.c  o m*/

    List<Iterable<Number>> tsData = Lists.newArrayList();
    tsData.add(timeSeriesRepo.getTimestamps());
    // Ignore requests for "time" since it is implicitly returned.
    Iterable<String> names = Iterables.filter(Splitter.on(",").split(metricsQuery),
            Predicates.not(Predicates.equalTo(TIME_METRIC)));
    for (String metric : names) {
        TimeSeries series = timeSeriesRepo.get(metric);
        if (series == null) {
            JsonObject response = new JsonObject();
            response.addProperty("error", "Unknown metric " + metric);
            throw new MetricException(gson.toJson(response));
        }
        tsData.add(series.getSamples());
    }

    final long since = Long.parseLong(Optional.fromNullable(sinceQuery).or("0"));
    Predicate<List<Number>> sinceFilter = next -> next.get(0).longValue() > since;

    ResponseStruct response = new ResponseStruct(
            ImmutableList.<String>builder().add(TIME_METRIC).addAll(names).build(),
            FluentIterable.from(Iterables2.zip(tsData, 0)).filter(sinceFilter).toList());
    // TODO(wfarner): Let the jax-rs provider handle serialization.
    return gson.toJson(response);
}

From source file:vazkii.botania.common.block.subtile.functional.SubTileHeiseiDream.java

private static void messWithGetTargetAI(EntityAINearestAttackableTarget aiEntry, EntityLivingBase target) {
    ReflectionHelper.setPrivateValue(EntityAINearestAttackableTarget.class, aiEntry, Entity.class,
            LibObfuscation.TARGET_CLASS);
    ReflectionHelper.setPrivateValue(EntityAINearestAttackableTarget.class, aiEntry, Predicates.equalTo(target),
            LibObfuscation.TARGET_ENTITY_SELECTOR); // todo 1.8 will this leak `target`?
}

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

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

From source file:com.twitter.aurora.scheduler.async.TaskGroup.java

void remove(String taskId) {
    Iterables.removeIf(tasks, Predicates.compose(Predicates.equalTo(taskId), TO_TASK_ID));
}

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

public static Predicate<ThreadVo> equalTo(final String uuid) {
    return Predicates.equalTo(new ThreadVo(uuid, ""));
}