|
hai 10 meses | |
---|---|---|
.github | hai 1 ano | |
beans | hai 10 meses | |
beans-bom | %!s(int64=2) %!d(string=hai) anos | |
jacoco-coverage-report | %!s(int64=2) %!d(string=hai) anos | |
.editorconfig | %!s(int64=5) %!d(string=hai) anos | |
.gitignore | %!s(int64=5) %!d(string=hai) anos | |
LICENSE | %!s(int64=5) %!d(string=hai) anos | |
README.org | %!s(int64=2) %!d(string=hai) anos | |
pom.xml | hai 10 meses |
Common code for Java beans, used in my other projects. Having this code in a library cuts down on boilerplate.
file:https://github.com/steinarb/beans/actions/workflows/beans-maven-ci-build.yml/badge.svg file:https://coveralls.io/repos/github/steinarb/beans/badge.svg file:https://sonarcloud.io/api/project_badges/measure?project=steinarb_beans&metric=alert_status#.svg file:https://maven-badges.herokuapp.com/maven-central/no.priv.bang.beans/beans/badge.svg file:https://www.javadoc.io/badge/no.priv.bang.beans/beans.svg
file:https://sonarcloud.io/images/project_badges/sonarcloud-white.svg
file:https://sonarcloud.io/api/project_badges/measure?project=steinarb_beans&metric=sqale_index#.svg file:https://sonarcloud.io/api/project_badges/measure?project=steinarb_beans&metric=coverage#.svg file:https://sonarcloud.io/api/project_badges/measure?project=steinarb_beans&metric=ncloc#.svg file:https://sonarcloud.io/api/project_badges/measure?project=steinarb_beans&metric=code_smells#.svg file:https://sonarcloud.io/api/project_badges/measure?project=steinarb_beans&metric=sqale_rating#.svg file:https://sonarcloud.io/api/project_badges/measure?project=steinarb_beans&metric=security_rating#.svg file:https://sonarcloud.io/api/project_badges/measure?project=steinarb_beans&metric=bugs#.svg file:https://sonarcloud.io/api/project_badges/measure?project=steinarb_beans&metric=vulnerabilities#.svg file:https://sonarcloud.io/api/project_badges/measure?project=steinarb_beans&metric=duplicated_lines_density#.svg file:https://sonarcloud.io/api/project_badges/measure?project=steinarb_beans&metric=reliability_rating#.svg
Date | Version | Comment |
---|---|---|
<2022-05-29 Sun 08:26> | 1.2.0 | Use karaf 4.4.0 and OSGi 8 |
<2021-06-09 Wed 21:46> | 1.1.4 | Avoid dependencyManagement version "leakage" in the BoM |
<2021-04-18 Sun 22:47> | 1.1.2 | Add a "Bill of Materials" (BoM) |
<2021-04-15 Thu 00:43> | 1.1.1 | Get common maven dependencies and maven plugin config from parent |
<2021-04-11 Sun 21:43> | 1.1.0 | Built with karaf 4.3.0 and OSGi 7 |
<2019-12-31 Tue 00:47> | 1.0.0 | Adds bean base class Immutable implementing hashCode() and equals() |
This is an OSGi bundle that contains the class Immutable which serves as a base class for immutable Java beans and provides the beans with implementations of hashCode() and equals().
The Object.hashCode() and Object.equals() methods must be overriden from their default Object implmentations in data objects, if those data objects are to work properly in maps and sets. However, writing hashCode() and equals() methods manually is boring. It consists of creating a lot of boilerplate code, and that boilerplate needs to have tests written if I don't wish to have sonar complain about test coverage, increasing the code that has to be modified when the bean changes.
IDEs like eclipse and IntelliJ can create hashCode() and equals() methods, but the auto-generated code may need a little tinkering, and the tests needs to be handwritten, or your code coverage will become low enough for sonar to complain. And if the beans change the IDE can recreate the methods, but the tests still needs to be changed manually
The apache commons-lang3 HashCodeBuilder has methods to create hashCode() using reflection, but using reflections means there is a performance cost. However, since the beans used in my jackson/jersey REST APIs are invariably immutable, it is possible to create the hashCode() lazily and then cache it. And that's what the Immutable bean base class found in this library does.
The equals() method also depends on the hashCode(), so it may not be entirely comparison proof, but for the first version I'm trying it out.
To use the latest version of the OSGi bundle in a maven project, or just use it as a plain JAR file, add the following dependencies (commons-lang3 is a provided dependency in the beans.immutable pom, so won't become a transitive dependency and must be added explicitly to a project using beans.immutable, even if the project is just using beans.immutable as a plain JAR file):
no.priv.bang.beans beans.immutable 1.2.0 org.apache.commons commons-lang3 3.9
This code is licensed under the Apache license v. 2. See the LICENSE file for details.