commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "J. Taylor Mayfield (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (LANG-395) annotations based builders
Date Fri, 08 Nov 2013 15:31:19 GMT

     [ https://issues.apache.org/jira/browse/LANG-395?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

J. Taylor Mayfield updated LANG-395:
------------------------------------

    Attachment: LANG-395.patch

Here's what I have so far. Basically, the method builds a list of exclude fields from the
lhs ('this') class fields that aren't annotated and then calls the reflection equals method.
This involved expanding FieldUtils, AnnotationUtils, and, obviously, EqualsBuilder. I also
included a "default" annotation, although I wasn't sure where to put it.

Before I implement similar logic for toString and hash code I thought I'd get opinions.

> annotations based builders
> --------------------------
>
>                 Key: LANG-395
>                 URL: https://issues.apache.org/jira/browse/LANG-395
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.builder.*
>            Reporter: Jörg Gottschling
>             Fix For: Patch Needed
>
>         Attachments: LANG-395.patch
>
>
> What about enabling the builders (ToStringBuilder, EqualsBuilder, etc.) that use reflection
to use annotations to find the field to include?
> Something like:
> ToStringBuilder.annotationsBasedToString(Object object, Class<Annotation> class,
Class<?> reflectUpToClass)
> One could use the JPA-Annotation @ID for example, espescially for Equals- and HashCodeBuilder.
There should also be some default annotation comming with LangTwo.
> Usage:
> public class User
> {
>   @StringRepresentation
>   @EqualsAndHashCode
>   private String name
>   @StringRepresentation
>   private String email;
>   private String password;
>   // ...
>   @Override
>   public String toString()
>   {
>     return annotationsBasedToString(this);
>   }
>   @Override
>   public boolean equals(Object other)
>   {
>     return annotationsBasedEquals(this, other);
>   }
>   @Override
>   public int hashCode()
>   {
>     return annotationsBasedHashCode(this);
>   }
> }



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Mime
View raw message