Skip to content

Commit

Permalink
fix hashCode & equals implementation for AtomicPositiveInteger
Browse files Browse the repository at this point in the history
  • Loading branch information
beiwei30 committed Jun 12, 2016
1 parent 63cd838 commit 6589f5e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,16 @@ public String toString() {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((i == null) ? 0 : i.hashCode());
result = prime * result + i.hashCode();
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
if (!(obj instanceof AtomicPositiveInteger)) return false;
AtomicPositiveInteger other = (AtomicPositiveInteger) obj;
if (i == null) {
if (other.i != null) return false;
} else if (!i.equals(other.i)) return false;
return true;
return i.intValue() == other.i.intValue();
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.common.utils;

import static org.hamcrest.CoreMatchers.allOf;
Expand Down Expand Up @@ -158,4 +158,10 @@ public void test_addAndGet() throws Exception {
assertEquals(2, get);
assertEquals(2, i3.get());
}

@Test
public void test_equals() {
assertEquals(new AtomicPositiveInteger(), new AtomicPositiveInteger());
assertEquals(new AtomicPositiveInteger(1), new AtomicPositiveInteger(1));
}
}

0 comments on commit 6589f5e

Please sign in to comment.