You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2016/09/20 23:29:21 UTC

logging-log4j2 git commit: Add equals() and hashCode() since Log4jLogEvent's equals() and hashCode() depends on them, all implementors should implement these methods.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 08a529fbb -> 436416b99


Add equals() and hashCode() since Log4jLogEvent's equals() and
hashCode() depends on them, all implementors should implement these
methods.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/436416b9
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/436416b9
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/436416b9

Branch: refs/heads/master
Commit: 436416b990fe7f405cc4b57aa5ea2dae1ea04518
Parents: 08a529f
Author: Gary Gregory <gg...@apache.org>
Authored: Tue Sep 20 16:29:18 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Tue Sep 20 16:29:18 2016 -0700

----------------------------------------------------------------------
 .../logging/log4j/spi/MutableContextData.java     | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/436416b9/log4j-api/src/main/java/org/apache/logging/log4j/spi/MutableContextData.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/spi/MutableContextData.java b/log4j-api/src/main/java/org/apache/logging/log4j/spi/MutableContextData.java
index 96251ef..346ea35 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/MutableContextData.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/MutableContextData.java
@@ -80,4 +80,22 @@ public interface MutableContextData extends ContextData {
      * @return  {@code true} if this object has been {@linkplain #freeze() frozen}, {@code false} otherwise
      */
     boolean isFrozen();
+
+    /**
+     * Returns a hash code value for the object.
+     * @return a hash code value for this object.
+     */
+    @Override
+    int hashCode();
+
+    /**
+     * Indicates whether some other object is "equal to" this one.
+     * 
+     * @param obj
+     *            the reference object with which to compare.
+     * @return {@code true} if this object is the same as the obj argument; {@code false} otherwise.
+     * @see #hashCode()
+     */
+    @Override
+    boolean equals(final Object obj);
 }
\ No newline at end of file


Re: logging-log4j2 git commit: Add equals() and hashCode() since Log4jLogEvent's equals() and hashCode() depends on them, all implementors should implement these methods.

Posted by Gary Gregory <ga...@gmail.com>.
It has to be in the contract (the interface) because it signals the intent
and expectation formally. That, and it let's the compiler's lint pass
(depending on the compiler), tooling, and FindBugs provide better feedback.

Gary

On Tue, Sep 20, 2016 at 5:03 PM, Remko Popma <re...@gmail.com> wrote:

> It may be more effective to add a "note to implementors" to that effect in
> the javadoc.
> Programmers are more likely to follow your advice if they know the reason
> behind it.
>
> Sent from my iPhone
>
> > On 2016/09/21, at 8:29, ggregory@apache.org wrote:
> >
> > Repository: logging-log4j2
> > Updated Branches:
> >  refs/heads/master 08a529fbb -> 436416b99
> >
> >
> > Add equals() and hashCode() since Log4jLogEvent's equals() and
> > hashCode() depends on them, all implementors should implement these
> > methods.
> >
> > Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> > Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/
> commit/436416b9
> > Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/
> 436416b9
> > Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/
> 436416b9
> >
> > Branch: refs/heads/master
> > Commit: 436416b990fe7f405cc4b57aa5ea2dae1ea04518
> > Parents: 08a529f
> > Author: Gary Gregory <gg...@apache.org>
> > Authored: Tue Sep 20 16:29:18 2016 -0700
> > Committer: Gary Gregory <gg...@apache.org>
> > Committed: Tue Sep 20 16:29:18 2016 -0700
> >
> > ----------------------------------------------------------------------
> > .../logging/log4j/spi/MutableContextData.java     | 18
> ++++++++++++++++++
> > 1 file changed, 18 insertions(+)
> > ----------------------------------------------------------------------
> >
> >
> > http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> 436416b9/log4j-api/src/main/java/org/apache/logging/log4j/
> spi/MutableContextData.java
> > ----------------------------------------------------------------------
> > diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/spi/MutableContextData.java
> b/log4j-api/src/main/java/org/apache/logging/log4j/spi/
> MutableContextData.java
> > index 96251ef..346ea35 100644
> > --- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/
> MutableContextData.java
> > +++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/
> MutableContextData.java
> > @@ -80,4 +80,22 @@ public interface MutableContextData extends
> ContextData {
> >      * @return  {@code true} if this object has been {@linkplain
> #freeze() frozen}, {@code false} otherwise
> >      */
> >     boolean isFrozen();
> > +
> > +    /**
> > +     * Returns a hash code value for the object.
> > +     * @return a hash code value for this object.
> > +     */
> > +    @Override
> > +    int hashCode();
> > +
> > +    /**
> > +     * Indicates whether some other object is "equal to" this one.
> > +     *
> > +     * @param obj
> > +     *            the reference object with which to compare.
> > +     * @return {@code true} if this object is the same as the obj
> argument; {@code false} otherwise.
> > +     * @see #hashCode()
> > +     */
> > +    @Override
> > +    boolean equals(final Object obj);
> > }
> > \ No newline at end of file
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: logging-log4j2 git commit: Add equals() and hashCode() since Log4jLogEvent's equals() and hashCode() depends on them, all implementors should implement these methods.

Posted by Remko Popma <re...@gmail.com>.
It may be more effective to add a "note to implementors" to that effect in the javadoc. 
Programmers are more likely to follow your advice if they know the reason behind it.

Sent from my iPhone

> On 2016/09/21, at 8:29, ggregory@apache.org wrote:
> 
> Repository: logging-log4j2
> Updated Branches:
>  refs/heads/master 08a529fbb -> 436416b99
> 
> 
> Add equals() and hashCode() since Log4jLogEvent's equals() and
> hashCode() depends on them, all implementors should implement these
> methods.
> 
> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/436416b9
> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/436416b9
> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/436416b9
> 
> Branch: refs/heads/master
> Commit: 436416b990fe7f405cc4b57aa5ea2dae1ea04518
> Parents: 08a529f
> Author: Gary Gregory <gg...@apache.org>
> Authored: Tue Sep 20 16:29:18 2016 -0700
> Committer: Gary Gregory <gg...@apache.org>
> Committed: Tue Sep 20 16:29:18 2016 -0700
> 
> ----------------------------------------------------------------------
> .../logging/log4j/spi/MutableContextData.java     | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/436416b9/log4j-api/src/main/java/org/apache/logging/log4j/spi/MutableContextData.java
> ----------------------------------------------------------------------
> diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/spi/MutableContextData.java b/log4j-api/src/main/java/org/apache/logging/log4j/spi/MutableContextData.java
> index 96251ef..346ea35 100644
> --- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/MutableContextData.java
> +++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/MutableContextData.java
> @@ -80,4 +80,22 @@ public interface MutableContextData extends ContextData {
>      * @return  {@code true} if this object has been {@linkplain #freeze() frozen}, {@code false} otherwise
>      */
>     boolean isFrozen();
> +
> +    /**
> +     * Returns a hash code value for the object.
> +     * @return a hash code value for this object.
> +     */
> +    @Override
> +    int hashCode();
> +
> +    /**
> +     * Indicates whether some other object is "equal to" this one.
> +     * 
> +     * @param obj
> +     *            the reference object with which to compare.
> +     * @return {@code true} if this object is the same as the obj argument; {@code false} otherwise.
> +     * @see #hashCode()
> +     */
> +    @Override
> +    boolean equals(final Object obj);
> }
> \ No newline at end of file
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org