{"id":100,"date":"2010-03-18T22:10:08","date_gmt":"2010-03-18T21:10:08","guid":{"rendered":"http:\/\/www.pmannel.de\/wordpress\/?p=100"},"modified":"2011-01-08T17:40:19","modified_gmt":"2011-01-08T16:40:19","slug":"project-lombok-%e2%80%93-sehr-interessant","status":"publish","type":"post","link":"https:\/\/www.pmannel.de\/wordpress\/?p=100","title":{"rendered":"Project Lombok \u2013 Sehr interessant!"},"content":{"rendered":"\n<p>Wem sein \u201cgetter\/setter\u201d-Boilerplatecode in seinen Domainenobjekten auf die Nerven geht, sollte sich mal das <a href=\"http:\/\/projectlombok.org\/index.html\">Project Lombok<\/a> ansehen!<\/p>\n<p>Nachdem man die Bibliothek eingebunden hat, werden mit @Annotations an den Objekten im Hintergrund die <em>getter\/setter<\/em> sowie <em>hashcode<\/em>, <em>toString <\/em>und <em>equals <\/em>generiert. Das Sch\u00f6ne daran ist auch, das die Klasse leer bleibt, jedoch der Outline-View in Eclipse alle Methoden anzeigt.<\/p>\n<p>Als Beispiel hier mal mein Dom\u00e4nenobjekt ohne Lombok (100 Zeilen):<\/p>\n<pre class=\"brush:java\">\r\npackage de.test.domain;\r\n\r\nimport org.apache.commons.lang.builder.EqualsBuilder;\r\nimport org.apache.commons.lang.builder.HashCodeBuilder;\r\nimport org.hibernate.Hibernate;\r\n\r\npublic class User  implements java.io.Serializable\r\n{\r\n\r\n\tprivate Integer id;\r\n\tprivate String name;\r\n\tprivate String surname;\r\n\tprivate String username;\r\n\tprivate String password;\r\n\tprivate Boolean active;\r\n\tprivate String email;\r\n\r\n\tpublic Integer getId() {\r\n\t\treturn this.id;\r\n\t}\r\n\r\n\tpublic void setId(Integer id) {\r\n\t\tthis.id = id;\r\n\t}\r\n\tpublic String getName() {\r\n\t\treturn this.name;\r\n\t}\r\n\r\n\tpublic void setName(String name) {\r\n\t\tthis.name = name;\r\n\t}\r\n\r\n\tpublic String getSurname() {\r\n\t\treturn this.surname;\r\n\t}\r\n\r\n\tpublic void setSurname(String surname) {\r\n\t\tthis.surname = surname;\r\n\t}\r\n\r\n\tpublic String getUsername() {\r\n\t\treturn this.username;\r\n\t}\r\n\r\n\tpublic void setUsername(String username) {\r\n\t\tthis.username = username;\r\n\t}\r\n\r\n\tpublic String getPassword() {\r\n\t\treturn this.password;\r\n\t}\r\n\r\n\tpublic void setPassword(String password) {\r\n\t\tthis.password = password;\r\n\t}\r\n\r\n\tpublic Boolean getActive() {\r\n\t\treturn this.active;\r\n\t}\r\n\r\n\tpublic void setActive(Boolean active) {\r\n\t\tthis.active = active;\r\n\t}\r\n\r\n\tpublic String getEmail()\r\n\t{\r\n\t\treturn email;\r\n\t}\r\n\r\n\tpublic void setEmail(String email)\r\n\t{\r\n\t\tthis.email = email;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic int hashCode()\r\n\t{\r\n\t\treturn new HashCodeBuilder(17,37).append(this.getUsername()).toHashCode();\r\n\t}\r\n\r\n\t@Override\r\n\tpublic boolean equals(Object other)\r\n\t{\r\n\t\tif(this == other)\r\n\t\t\treturn  true;\r\n\t\tif (other == null || Hibernate.getClass(this) != Hibernate.getClass(other))\r\n\t\t\treturn false;\r\n\r\n\t\tfinal User rhs = (User) other;\r\n\t\treturn new EqualsBuilder().append(this.getUsername(),rhs.getUsername()).isEquals();\r\n\t}\r\n\r\n\t@Override\r\n\tpublic String toString()\r\n\t{\r\n\t\treturn \"User [active=\" + active + \", name=\" + name + \", email=\" + email + \", password=\"\r\n\t\t              + password + \", surname=\" + surname + \", username=\" + username\r\n\t\t              + \"]\";\r\n\t}\r\n}\r\n\r\n<\/pre>\n<p>..und hier mein Dom\u00e4nenobjekt mit Lombok (21 Zeilen):<\/p>\n<pre class=\"brush:java\">\r\npackage de.test.domain;\r\n\r\nimport lombok.EqualsAndHashCode;\r\nimport lombok.Getter;\r\nimport lombok.Setter;\r\nimport lombok.ToString;\r\n\r\n@EqualsAndHashCode(exclude={\"id\",\"name\",\"surname\",\"password\",\"active\",\"email\"})\r\n@ToString(exclude=\"id\")\r\npublic class User  implements java.io.Serializable\r\n{\r\n\r\n\tprivate @Getter @Setter  Integer id;\r\n\tprivate @Getter @Setter  String name;\r\n\tprivate @Getter @Setter  String surname;\r\n\tprivate @Getter @Setter  String username;\r\n\tprivate @Getter @Setter  String password;\r\n\tprivate @Getter @Setter  Boolean active;\r\n\tprivate @Getter @Setter  String email;\r\n\r\n}\r\n\r\n<\/pre>\n<p>Hier das Objekt in Eclipse:\n<\/p>\n<div id=\"attachment_241\" class=\"wp-caption alignnone\" style=\"width: 310px;\"><a href=\"http:\/\/www.pmannel.de\/wordpress\/wp-content\/uploads\/lombok1.JPG\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.pmannel.de\/wordpress\/wp-content\/uploads\/lombok1-300x181.jpg\" alt=\"Lombok im Eclipse-View\" title=\"lombok\" class=\"size-medium wp-image-241\" height=\"181\" width=\"300\"><\/a><\/p>\n<p class=\"wp-caption-text\">Lombok im Eclipse-View<\/p>\n<\/div>\n<p>Man k\u00f6nnte jetzt in der Lombokmagie ein Problem sehen, allerdings sehe ich eher das Problem darin, das wir langsam von der XML-Hell geradewegs in die @Annotation-Hell kommen\u2026<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wem sein \u201cgetter\/setter\u201d-Boilerplatecode in seinen Domainenobjekten auf die Nerven geht, sollte sich mal das Project Lombok ansehen! Nachdem man die Bibliothek eingebunden hat, werden mit @Annotations an den Objekten im Hintergrund die getter\/setter sowie hashcode, toString und equals generiert. Das Sch\u00f6ne daran ist auch, das die Klasse leer bleibt, jedoch der Outline-View in Eclipse alle&#8230; <\/p>\n<div class=\"read-more\"><a href=\"https:\/\/www.pmannel.de\/wordpress\/?p=100\">Weiterlesen<\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[37],"class_list":["post-100","post","type-post","status-publish","format-standard","hentry","category-java","tag-lombok"],"_links":{"self":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=100"}],"version-history":[{"count":9,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/100\/revisions"}],"predecessor-version":[{"id":132,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/100\/revisions\/132"}],"wp:attachment":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}