Created
October 10, 2014 14:20
-
-
Save krujos/a40489ae31c706c91056 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks if everything except id's and results are equal! | |
* An example of using the stream operator and a couple of gauva and apache | |
* language extensions to implement an equality check. We create a pair for | |
* each thing we want to compare then stream through and assert that | |
* everything matches the equality test. We use the hash code in the | |
* equality test as it's a little less finicky for equality tests. This is a | |
* pretty expensive and heavy weight implementation, not because of the | |
* functional stuff, but because of all the intermediary objects created. As | |
* this is example code we don't sweat the efficiency. A simpler | |
* Implementation would just use a big equality test. | |
* Example disabled because of hibernate bug... | |
* https://hibernate.atlassian.net/browse/HHH-9132 | |
* | |
* @param other | |
* @return true if every element is equal | |
*/ | |
private boolean checkEquality(final Schedule other) { | |
// Nifty fancy but expensive lambda Pair disabled because of hibernate | |
// bug. | |
// https://hibernate.atlassian.net/browse/HHH-9132 | |
//@formatter:off | |
return Lists | |
.newArrayList(Pair.of(callbackURI, other.callbackURI), | |
Pair.of(cronExpression, other.cronExpression), | |
Pair.of(method, other.method), | |
Pair.of(scheduleType, other.scheduleType), | |
Pair.of(executeAt, other.executeAt)).stream() | |
.allMatch(pair -> hashIfNotNull(pair.getLeft()) == hashIfNotNull(pair.getRight())); | |
//@formatter:on | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment