summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/sdk/android/api/org/webrtc/Predicate.java
blob: 50e69750002702ef14a024c66e03aff2d92fef4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

package org.webrtc;

/**
 * Represents a predicate (boolean-valued function) of one argument.
 */
public interface Predicate<T> {
  /**
   * Evaluates this predicate on the given argument.
   *
   * @param arg the input argument
   * @return true if the input argument matches the predicate, otherwise false
   */
  boolean test(T arg);

  /**
   * 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.
   *
   * @param other a predicate that will be logically-ORed with this predicate
   * @return a composed predicate that represents the short-circuiting logical OR of this predicate
   *     and the other predicate
   */
  default Predicate<T> or(Predicate<? super T> other) {
    return new Predicate<T>() {
      @Override
      public boolean test(T arg) {
        return Predicate.this.test(arg) || other.test(arg);
      }
    };
  }

  /**
   * Returns a composed predicate that represents a short-circuiting logical AND of this predicate
   * and another.
   *
   * @param other a predicate that will be logically-ANDed with this predicate
   * @return a composed predicate that represents the short-circuiting logical AND of this predicate
   *     and the other predicate
   */
  default Predicate<T> and(Predicate<? super T> other) {
    return new Predicate<T>() {
      @Override
      public boolean test(T arg) {
        return Predicate.this.test(arg) && other.test(arg);
      }
    };
  }

  /**
   * Returns a predicate that represents the logical negation of this predicate.
   *
   * @return a predicate that represents the logical negation of this predicate
   */
  default Predicate<T> negate() {
    return new Predicate<T>() {
      @Override
      public boolean test(T arg) {
        return !Predicate.this.test(arg);
      }
    };
  }
}