jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felix Schumacher <felix.schumac...@internetallee.de>
Subject Re: svn commit: r1802732 - in /jmeter/trunk: src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java
Date Mon, 31 Jul 2017 09:56:43 GMT


Am 30. Juli 2017 22:14:08 MESZ schrieb sebb <sebbaz@gmail.com>:
>On 23 July 2017 at 16:48,  <fschumacher@apache.org> wrote:
>> Author: fschumacher
>> Date: Sun Jul 23 15:48:41 2017
>> New Revision: 1802732
>>
>> URL: http://svn.apache.org/viewvc?rev=1802732&view=rev
>> Log:
>> Change equals and hashCode so that they are more independent from
>JMeterVariables.
>>
>> Modified:
>>    
>jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java
>>    
>jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java
>>
>> Modified:
>jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java
>> URL:
>http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java?rev=1802732&r1=1802731&r2=1802732&view=diff
>>
>==============================================================================
>> ---
>jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java
>(original)
>> +++
>jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java
>Sun Jul 23 15:48:41 2017
>> @@ -40,8 +40,13 @@ class UnmodifiableJMeterVariables extend
>>
>>      @Override
>>      public int hashCode() {
>> -        return variables.hashCode();
>> +        final int prime = 31;
>> +        int result = 1;
>> +        result = prime * result
>
>This is always 31.
>
>> +                + ((variables == null) ? 0 : variables.hashCode());
>> +        return result;
>
>Not sure what the point of adding 31 is.

It is the default implementation that eclipse generates. I was a bit lazy here. I kept the
31 as that way the hash code would be different to that of JMeterVariables. 

Felix

>
>Why not just use:
>
>return variables == null) ? 0 : variables.hashCode()
>
>>      }
>> +
>>
>>      @Override
>>      public String getThreadName() {
>> @@ -88,8 +93,21 @@ class UnmodifiableJMeterVariables extend
>>          return variables.get(key);
>>      }
>>
>> +    @Override
>>      public boolean equals(Object obj) {
>> -        return variables.equals(obj);
>> +        if (this == obj)
>> +            return true;
>> +        if (obj == null)
>> +            return false;
>> +        if (getClass() != obj.getClass())
>> +            return false;
>
>Since null is not and instanceof anything, the last two checks can be
>simplified to:
>
>    if (!obj instanceof UnmodifiableJMeterVariables) {
>        return false;
>    }
>
>> +        UnmodifiableJMeterVariables other =
>(UnmodifiableJMeterVariables) obj;
>> +        if (variables == null) {
>> +            if (other.variables != null)
>> +                return false;
>> +        } else if (!variables.equals(other.variables))
>> +            return false;
>> +        return true;
>>      }
>>
>>      @Override
>>
>> Modified:
>jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java
>> URL:
>http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java?rev=1802732&r1=1802731&r2=1802732&view=diff
>>
>==============================================================================
>> ---
>jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java
>(original)
>> +++
>jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java
>Sun Jul 23 15:48:41 2017
>> @@ -124,13 +124,26 @@ public class TestUnmodifiableJMeterVaria
>>      }
>>
>>      @Test
>> -    public void testEqualsObject() {
>> -        assertThat(unmodifiables, CoreMatchers.is(vars));
>> +    public void testEqualsObjectSymmetry() {
>> +        UnmodifiableJMeterVariables otherUnmodifiables = new
>UnmodifiableJMeterVariables(vars);
>> +        assertThat(unmodifiables,
>CoreMatchers.is(otherUnmodifiables));
>> +        assertThat(otherUnmodifiables,
>CoreMatchers.is(unmodifiables));
>> +    }
>> +
>> +    @Test
>> +    public void testEqualsObjectReflexivity() {
>> +        assertThat(unmodifiables, CoreMatchers.is(unmodifiables));
>> +    }
>> +
>> +    @Test
>> +    public void testEqualsObjectWithJMeterVariables() {
>> +        assertThat(unmodifiables.equals(vars),
>CoreMatchers.is(vars.equals(unmodifiables)));
>>      }
>>
>>      @Test
>>      public void testHashCode() {
>> -        assertThat(unmodifiables.hashCode(),
>CoreMatchers.is(vars.hashCode()));
>> +        UnmodifiableJMeterVariables otherUnmodifiables = new
>UnmodifiableJMeterVariables(vars);
>> +        assertThat(unmodifiables.hashCode(),
>CoreMatchers.is(otherUnmodifiables.hashCode()));
>>      }
>>
>>  }
>>
>>

Mime
View raw message