Better compareTo() syntax

Improving readability for java.lang.Comparable.compareTo()

License

License

Categories

Categories

IDE Development Tools
GroupId

GroupId

se.jiderhamn
ArtifactId

ArtifactId

compare-to
Last Version

Last Version

1.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

Better compareTo() syntax
Improving readability for java.lang.Comparable.compareTo()
Project URL

Project URL

https://github.com/mjiderhamn/compare-to
Source Code Management

Source Code Management

https://github.com/mjiderhamn/compare-to.git

Download compare-to

How to add to project

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

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.10

Project Modules

There are no modules declared in this project.

Better compareTo() syntax

Improving readability for [java.lang.Comparable.compareTo()](http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html#compareTo(T\))

Example usage - expressive syntax

import static se.jiderhamn.CompareTo.is;

...
  boolean oneIsZero = is(1).equalTo(0);
  boolean aIsNotZero = is(a).notEqualTo(0);
  boolean bIsZero = is(b).zero();
  boolean value1LessThanValue2 = is(value1).lessThan(value2);
    
  if(is(a).lessThanOrEqualTo(b)) {
    ...
  }

  boolean date1AfterDate2 = is(date1).greaterThan(date2);

  if(is(a).greaterThanOrEqualTo(b)) {
    ...
  }

Example usage - abbreviated syntax

import static se.jiderhamn.CompareTo.is;

...
  boolean oneIsZero = is(1).eq(0);
  boolean aIsNotZero = is(a).ne(0);
  boolean value1LessThanValue2 = is(value1).lt(value2);

  if(is(a).le(b)) {
    ...
  }

  boolean date1AfterDate2 = is(date1).gt(date2);

  if(is(a).ge(b)) {
    ...
  }

Maven

The library is available in Maven Central with the following details:

<dependency>
  <groupId>se.jiderhamn</groupId>
  <artifactId>compare-to</artifactId>
  <version>1.1.1</version>
</dependency>

Versions

Version
1.1.1
1.1.0
1.0.0