LANG-804 - Redundant check for zero in HashCodeBuilder ctor. Patch provided by Allon Mureinik via github.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1526817 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9ad1a4df47
commit
26375b2cfd
|
@ -22,6 +22,7 @@
|
|||
<body>
|
||||
|
||||
<release version="3.2" date="TBA" description="Next release">
|
||||
<action issue="LANG-804" type="update" dev="britter" due-to="Allon Mureinik">Redundant check for zero in HashCodeBuilder ctor</action>
|
||||
<action issue="LANG-893" type="add" dev="oheger" due-to="Woonsan Ko">StrSubstitutor now supports default values for variables</action>
|
||||
<action issue="LANG-913" type="add" dev="britter" due-to="Allon Mureinik">Adding .gitignore to commons-lang</action>
|
||||
<action issue="LANG-837" type="add">Add ObjectUtils.toIdentityString methods that support StringBuilder, StrBuilder, and Appendable</action>
|
||||
|
|
|
@ -520,7 +520,7 @@ public class HashCodeBuilder implements Builder<Integer> {
|
|||
|
||||
/**
|
||||
* <p>
|
||||
* Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
|
||||
* Two randomly chosen, odd numbers must be passed in. Ideally these should be different for each class,
|
||||
* however this is not vital.
|
||||
* </p>
|
||||
*
|
||||
|
@ -528,28 +528,22 @@ public class HashCodeBuilder implements Builder<Integer> {
|
|||
* Prime numbers are preferred, especially for the multiplier.
|
||||
* </p>
|
||||
*
|
||||
* @param initialNonZeroOddNumber
|
||||
* a non-zero, odd number used as the initial value
|
||||
* @param multiplierNonZeroOddNumber
|
||||
* a non-zero, odd number used as the multiplier
|
||||
* @param initialOddNumber
|
||||
* am odd number used as the initial value
|
||||
* @param multiplierOddNumber
|
||||
* an odd number used as the multiplier
|
||||
* @throws IllegalArgumentException
|
||||
* if the number is zero or even
|
||||
* if the number is even
|
||||
*/
|
||||
public HashCodeBuilder(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber) {
|
||||
if (initialNonZeroOddNumber == 0) {
|
||||
throw new IllegalArgumentException("HashCodeBuilder requires a non zero initial value");
|
||||
}
|
||||
if (initialNonZeroOddNumber % 2 == 0) {
|
||||
public HashCodeBuilder(final int initialOddNumber, final int multiplierOddNumber) {
|
||||
if (initialOddNumber % 2 == 0) {
|
||||
throw new IllegalArgumentException("HashCodeBuilder requires an odd initial value");
|
||||
}
|
||||
if (multiplierNonZeroOddNumber == 0) {
|
||||
throw new IllegalArgumentException("HashCodeBuilder requires a non zero multiplier");
|
||||
}
|
||||
if (multiplierNonZeroOddNumber % 2 == 0) {
|
||||
if (multiplierOddNumber % 2 == 0) {
|
||||
throw new IllegalArgumentException("HashCodeBuilder requires an odd multiplier");
|
||||
}
|
||||
iConstant = multiplierNonZeroOddNumber;
|
||||
iTotal = initialNonZeroOddNumber;
|
||||
iConstant = multiplierOddNumber;
|
||||
iTotal = initialOddNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,15 +55,20 @@ public class HashCodeBuilderTest {
|
|||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testConstructorEx1() {
|
||||
public void testConstructorExZero() {
|
||||
new HashCodeBuilder(0, 0);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testConstructorEx2() {
|
||||
public void testConstructorExEven() {
|
||||
new HashCodeBuilder(2, 2);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testConstructorExEvenNegative() {
|
||||
new HashCodeBuilder(-2, -2);
|
||||
}
|
||||
|
||||
static class TestObject {
|
||||
private int a;
|
||||
|
||||
|
|
Loading…
Reference in New Issue