predicates

The intention of this project is to improve readability of equality and relational operators using predefined [Predicates](https://docs.oracle.com/javase/8/docs/api/java/util/function/Predicate.html).

License

License

GroupId

GroupId

com.github.puddingspudding
ArtifactId

ArtifactId

predicates
Last Version

Last Version

0.4
Release Date

Release Date

Type

Type

jar
Description

Description

predicates
The intention of this project is to improve readability of equality and relational operators using predefined [Predicates](https://docs.oracle.com/javase/8/docs/api/java/util/function/Predicate.html).
Project URL

Project URL

https://github.com/puddingspudding/java-predicates
Source Code Management

Source Code Management

https://github.com/puddingspudding/java-predicates

Download predicates

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.puddingspudding/predicates/ -->
<dependency>
    <groupId>com.github.puddingspudding</groupId>
    <artifactId>predicates</artifactId>
    <version>0.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.puddingspudding/predicates/
implementation 'com.github.puddingspudding:predicates:0.4'
// https://jarcasting.com/artifacts/com.github.puddingspudding/predicates/
implementation ("com.github.puddingspudding:predicates:0.4")
'com.github.puddingspudding:predicates:jar:0.4'
<dependency org="com.github.puddingspudding" name="predicates" rev="0.4">
  <artifact name="predicates" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.puddingspudding', module='predicates', version='0.4')
)
libraryDependencies += "com.github.puddingspudding" % "predicates" % "0.4"
[com.github.puddingspudding/predicates "0.4"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Java8 Predicates

The intention of this project is to improve readability of equality and relational operators (< > <= >= == !=) using predefined Predicates. It also contains a Predicate interface with then(), orElse() and elseIf() to replace if-then and if-then-else statements.


mvn

<dependency>
    <groupId>com.github.puddingspudding</groupId>
    <artifactId>predicates</artifactId>
    <version>0.4</version>
</dependency>

Predicates

  • isEqualTo { a == b }
  • isNotEqualTo { a != b }
  • isBiggerThan { a > b }
  • isSmallerThan { a < b }
  • isEqualOrBiggerThan { a >= b }
  • isEqualOrSmallerThan { a <= b }
  • isInRange { a <= x && x <= b }
  • isNotInRage { x < a && b < x }
  • isNegative { a < 0 }
  • isPositive { a > 0 }
  • isEven { x % 2 == 0 }
  • isOdd { x % 2 != 0 }

Examples

java.util.function.Predicate

import java.util.function.Predicate;
import static com.github.puddingspudding.IntegerPredicates.*;
import static com.github.puddingspudding.LongPredicates.*;

// isEqualTo
Predicate<Integer> isEqualToOne = isEqualTo(1);
if (isEqualToOne.test(1)) {
    // do something
}

// isNotEqualTo
Predicate<Integer> isNotEqualToOne = isNotEqualTo(1);
if (isNotEqualToOne.test(2)) {
    // do something
}

// ...

if (isBiggerThan(10).or(isSmallerThan(-10)).test(x))) {
    // x is awesome
    // or use isNotInRange(-10).apply(10).test(x)
}

Stream.of(1,2,3,4,5,6)
	.filter(isBiggerThan(3))
	.collect(Collectors.toList());
	// [4, 5, 6]

License

Apache 2.0

Versions

Version
0.4
0.3
0.2
0.1