Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
/ aequum Public archive

The Aequum library is designed to help remove some of the boiler plate when writing the equals, hashCode and compareTo methods on POJO classes through the use of Java 8 lambdas.

License

Notifications You must be signed in to change notification settings

notonthehighstreet/aequum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

##Aequum Library##

###Responsibilities### The Aequum library is designed to help remove some of the boiler plate when writing the equals, hashCode and compareTo methods on POJO classes through the use of Java 8 lambdas.

Note that this library depends on Java 8.

###Component initialisation instructions### To use this library, call the builder method on the Aequum class and then add the relevant fields through either the withField or withComparableField. Once the necessary fields have been added, then the build method should be called.

###State characteristics (i.e. stateless)### Once the build method has been called, the state of the built classes will not change and so are thread safe.

###Developer Highlights (i.e. Classes of interest)### Apart from the builder class, Aequum, the two classes of interest are EqualsHashCode and ComparableEqualsHashCode.

####EqualsHashCode#### This class is responsible for calculating equality and the hashCode for an object.

####ComparableEqualsHashCode#### This class extends EqualsHashCode and implements the comparison of an object.

###Example### This is an example of using this library on a POJO:

public Example implements Comparable<Example> {

  private static final ComparableEqualsHashCode<Example> EQUALS_HASH_CODE =
      Aequum.builder(Example.class)
          .withComparableField(Example::getFieldOne)
          .withComparableField(Example::getFieldTwo)
          .withComparableField(Example::getFieldThree)
          .build();

  private final String fieldOne;
  private final String fieldTwo;
  private final int fieldThree;

  public Example(final String fieldOne, final String fieldTwo, final int fieldThree) {...}

  public String getFieldOne() {...}

  public String getFieldTwo() {...}

  public int getFieldThree() {...}

  @Override
  public boolean equals(final Object o) {
    return EQUALS_HASH_CODE.isEqual(this, o);
  }

  @Overide
  public int hashCode() {
    return EQUALS_HASH_CODE.toHashCode(this);
  }

  @Override
  public int compareTo(final Example o) {
    return EQUALS_HASH_CODE.compare(this, o);
  }
}

About

The Aequum library is designed to help remove some of the boiler plate when writing the equals, hashCode and compareTo methods on POJO classes through the use of Java 8 lambdas.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages