Predicate
Stay organized with collections
Save and categorize content based on your preferences.
Public Method Summary
Predicate<T>
|
and( Predicate<? super T> other)
Returns a composed predicate that represents a short-circuiting logical
AND of this predicate and another.
|
static
<T>
Predicate<T>
|
|
Predicate<T>
|
negate()
Returns a predicate that represents the logical negation of this
predicate.
|
Predicate<T>
|
or( Predicate<? super T> other)
Returns a composed predicate that represents a short-circuiting logical
OR of this predicate and another.
|
abstract
boolean
|
test(T t)
Evaluates this predicate on the given argument.
|
Public Methods
Returns a composed predicate that represents a short-circuiting logical
AND of this predicate and another. When evaluating the composed
predicate, if this predicate is false
, then the other
predicate is not evaluated.
Any exceptions thrown during evaluation of either predicate are relayed
to the caller; if evaluation of this predicate throws an exception, the
other
predicate will not be evaluated.
Parameters
other |
a predicate that will be logically-ANDed with this
predicate |
Returns
- a composed predicate that represents the short-circuiting logical
AND of this predicate and the
other
predicate
public
static
Predicate<T>
isEqual
(Object targetRef)
Parameters
targetRef |
the object reference with which to compare for equality,
which may be null |
public
Predicate<T>
negate
()
Returns a predicate that represents the logical negation of this
predicate.
Returns
- a predicate that represents the logical negation of this
predicate
Returns a composed predicate that represents a short-circuiting logical
OR of this predicate and another. When evaluating the composed
predicate, if this predicate is true
, then the other
predicate is not evaluated.
Any exceptions thrown during evaluation of either predicate are relayed
to the caller; if evaluation of this predicate throws an exception, the
other
predicate will not be evaluated.
Parameters
other |
a predicate that will be logically-ORed with this
predicate |
Returns
- a composed predicate that represents the short-circuiting logical
OR of this predicate and the
other
predicate
public
abstract
boolean
test
(T t)
Evaluates this predicate on the given argument.
Returns
true
if the input argument matches the predicate,
otherwise false
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003ePredicate\u003c/code\u003e is a functional interface representing a boolean-valued function of one argument.\u003c/p\u003e\n"],["\u003cp\u003eIts primary function is \u003ccode\u003etest(T t)\u003c/code\u003e, which evaluates the predicate on a given input and returns true or false.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods like \u003ccode\u003eand\u003c/code\u003e, \u003ccode\u003eor\u003c/code\u003e, and \u003ccode\u003enegate\u003c/code\u003e to combine or modify predicates.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eisEqual\u003c/code\u003e method creates a predicate that checks for equality between two objects using \u003ccode\u003eObjects.equals\u003c/code\u003e.\u003c/p\u003e\n"]]],["The `Predicate` interface represents a boolean-valued function. Key actions include: `and()` to create a short-circuiting logical AND predicate; `isEqual()` to test for equality between two arguments; `negate()` to return the logical negation of a predicate; `or()` to create a short-circuiting logical OR predicate; `test()` to evaluate the predicate on a given argument. The interface also provides methods to handle exceptions and null inputs.\n"],null,["# Predicate\n\npublic interface **Predicate** \nRepresents a predicate (boolean-valued function) of one argument.\n\nThis is a [functional interface](/j2objc/javadoc/jre/reference/java/util/function/package-summary)\nwhose functional method is [test(Object)](../../../../reference/java/util/function/Predicate.html#test(T)). \n\n### Public Method Summary\n\n|----------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Predicate](../../../../reference/java/util/function/Predicate.html)\\\u003cT\\\u003e | [and](../../../../reference/java/util/function/Predicate.html#and(java.util.function.Predicate\u003c?%20super%20T\u003e))([Predicate](../../../../reference/java/util/function/Predicate.html)\\\u003c? super T\\\u003e other) Returns a composed predicate that represents a short-circuiting logical AND of this predicate and another. |\n| static \\\u003cT\\\u003e [Predicate](../../../../reference/java/util/function/Predicate.html)\\\u003cT\\\u003e | [isEqual](../../../../reference/java/util/function/Predicate.html#isEqual(java.lang.Object))([Object](../../../../reference/java/lang/Object.html) targetRef) Returns a predicate that tests if two arguments are equal according to [Objects.equals(Object, Object)](../../../../reference/java/util/Objects.html#equals(java.lang.Object,%20java.lang.Object)). |\n| [Predicate](../../../../reference/java/util/function/Predicate.html)\\\u003cT\\\u003e | [negate](../../../../reference/java/util/function/Predicate.html#negate())() Returns a predicate that represents the logical negation of this predicate. |\n| [Predicate](../../../../reference/java/util/function/Predicate.html)\\\u003cT\\\u003e | [or](../../../../reference/java/util/function/Predicate.html#or(java.util.function.Predicate\u003c?%20super%20T\u003e))([Predicate](../../../../reference/java/util/function/Predicate.html)\\\u003c? super T\\\u003e other) Returns a composed predicate that represents a short-circuiting logical OR of this predicate and another. |\n| abstract boolean | [test](../../../../reference/java/util/function/Predicate.html#test(T))(T t) Evaluates this predicate on the given argument. |\n\nPublic Methods\n--------------\n\n#### public [Predicate](../../../../reference/java/util/function/Predicate.html)\\\u003cT\\\u003e\n**and**\n([Predicate](../../../../reference/java/util/function/Predicate.html)\\\u003c? super T\\\u003e other)\n\nReturns a composed predicate that represents a short-circuiting logical\nAND of this predicate and another. When evaluating the composed\npredicate, if this predicate is `false`, then the `other`\npredicate is not evaluated.\n\nAny exceptions thrown during evaluation of either predicate are relayed\nto the caller; if evaluation of this predicate throws an exception, the\n`other` predicate will not be evaluated. \n\n##### Parameters\n\n| other | a predicate that will be logically-ANDed with this predicate |\n|-------|--------------------------------------------------------------|\n\n##### Returns\n\n- a composed predicate that represents the short-circuiting logical AND of this predicate and the `other` predicate \n\n##### Throws\n\n| [NullPointerException](../../../../reference/java/lang/NullPointerException.html) | if other is null |\n|-----------------------------------------------------------------------------------|------------------|\n\n#### public static [Predicate](../../../../reference/java/util/function/Predicate.html)\\\u003cT\\\u003e\n**isEqual**\n([Object](../../../../reference/java/lang/Object.html) targetRef)\n\nReturns a predicate that tests if two arguments are equal according\nto [Objects.equals(Object, Object)](../../../../reference/java/util/Objects.html#equals(java.lang.Object,%20java.lang.Object)). \n\n##### Parameters\n\n| targetRef | the object reference with which to compare for equality, which may be `null` |\n|-----------|------------------------------------------------------------------------------|\n\n##### Returns\n\n- a predicate that tests if two arguments are equal according to [Objects.equals(Object, Object)](../../../../reference/java/util/Objects.html#equals(java.lang.Object,%20java.lang.Object)) \n\n#### public [Predicate](../../../../reference/java/util/function/Predicate.html)\\\u003cT\\\u003e\n**negate**\n()\n\nReturns a predicate that represents the logical negation of this\npredicate. \n\n##### Returns\n\n- a predicate that represents the logical negation of this predicate \n\n#### public [Predicate](../../../../reference/java/util/function/Predicate.html)\\\u003cT\\\u003e\n**or**\n([Predicate](../../../../reference/java/util/function/Predicate.html)\\\u003c? super T\\\u003e other)\n\nReturns a composed predicate that represents a short-circuiting logical\nOR of this predicate and another. When evaluating the composed\npredicate, if this predicate is `true`, then the `other`\npredicate is not evaluated.\n\nAny exceptions thrown during evaluation of either predicate are relayed\nto the caller; if evaluation of this predicate throws an exception, the\n`other` predicate will not be evaluated. \n\n##### Parameters\n\n| other | a predicate that will be logically-ORed with this predicate |\n|-------|-------------------------------------------------------------|\n\n##### Returns\n\n- a composed predicate that represents the short-circuiting logical OR of this predicate and the `other` predicate \n\n##### Throws\n\n| [NullPointerException](../../../../reference/java/lang/NullPointerException.html) | if other is null |\n|-----------------------------------------------------------------------------------|------------------|\n\n#### public abstract boolean\n**test**\n(T t)\n\nEvaluates this predicate on the given argument. \n\n##### Parameters\n\n| t | the input argument |\n|---|--------------------|\n\n##### Returns\n\n- `true` if the input argument matches the predicate, otherwise `false`"]]