From a2cb44e4d41e27a212c469d5a842fa6e87578864 Mon Sep 17 00:00:00 2001 From: Mattias Hellborg Arthursson Date: Mon, 9 Sep 2013 11:53:40 +0200 Subject: [PATCH] Fixed some sonar problems. --- .../control/PagedResultsRequestControl.java | 4 ++-- .../ldap/core/support/RangeOption.java | 20 +++++++++++++++++++ .../test/AttributeCheckAttributesMapper.java | 14 ++++++------- .../test/AttributeCheckContextMapper.java | 12 ++++++----- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/springframework/ldap/control/PagedResultsRequestControl.java b/core/src/main/java/org/springframework/ldap/control/PagedResultsRequestControl.java index 90ceb311..5b6bc393 100644 --- a/core/src/main/java/org/springframework/ldap/control/PagedResultsRequestControl.java +++ b/core/src/main/java/org/springframework/ldap/control/PagedResultsRequestControl.java @@ -174,8 +174,8 @@ public class PagedResultsRequestControl extends AbstractRequestControlDirContext Control result = null; try { - result = (Control) constructor.newInstance(new Object[] { new Integer(pageSize), actualCookie, - Boolean.valueOf(critical) }); + result = (Control) constructor.newInstance(pageSize, actualCookie, + critical); } catch (Exception e) { ReflectionUtils.handleReflectionException(e); diff --git a/core/src/main/java/org/springframework/ldap/core/support/RangeOption.java b/core/src/main/java/org/springframework/ldap/core/support/RangeOption.java index dc88e5f2..ca8b65fe 100644 --- a/core/src/main/java/org/springframework/ldap/core/support/RangeOption.java +++ b/core/src/main/java/org/springframework/ldap/core/support/RangeOption.java @@ -151,6 +151,26 @@ class RangeOption implements Comparable { return this.getTerminal() > that.getTerminal() ? 1 : -1; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + RangeOption that = (RangeOption) o; + + if (initial != that.initial) return false; + if (terminal != that.terminal) return false; + + return true; + } + + @Override + public int hashCode() { + int result = initial; + result = 31 * result + terminal; + return result; + } + public RangeOption nextRange(int pageSize) { if (getTerminal() < 0) { throw new IllegalStateException("Cannot generate next range, range-terminal: " + getTerminal()); diff --git a/test-support/src/main/java/org/springframework/ldap/test/AttributeCheckAttributesMapper.java b/test-support/src/main/java/org/springframework/ldap/test/AttributeCheckAttributesMapper.java index db5a5582..2c8af636 100644 --- a/test-support/src/main/java/org/springframework/ldap/test/AttributeCheckAttributesMapper.java +++ b/test-support/src/main/java/org/springframework/ldap/test/AttributeCheckAttributesMapper.java @@ -15,13 +15,13 @@ */ package org.springframework.ldap.test; +import junit.framework.Assert; +import org.springframework.ldap.core.AttributesMapper; + import javax.naming.NamingException; import javax.naming.directory.Attribute; import javax.naming.directory.Attributes; - -import org.springframework.ldap.core.AttributesMapper; - -import junit.framework.Assert; +import java.util.Arrays; /** * Dummy AttributesMapper for testing purposes to check that the received @@ -55,14 +55,14 @@ public class AttributeCheckAttributesMapper implements AttributesMapper { } public void setAbsentAttributes(String[] absentAttributes) { - this.absentAttributes = absentAttributes; + this.absentAttributes = Arrays.copyOf(absentAttributes, absentAttributes.length); } public void setExpectedAttributes(String[] expectedAttributes) { - this.expectedAttributes = expectedAttributes; + this.expectedAttributes = Arrays.copyOf(expectedAttributes, expectedAttributes.length); } public void setExpectedValues(String[] expectedValues) { - this.expectedValues = expectedValues; + this.expectedValues = Arrays.copyOf(expectedValues, expectedValues.length); } } \ No newline at end of file diff --git a/test-support/src/main/java/org/springframework/ldap/test/AttributeCheckContextMapper.java b/test-support/src/main/java/org/springframework/ldap/test/AttributeCheckContextMapper.java index 0696d6ae..47b32fee 100644 --- a/test-support/src/main/java/org/springframework/ldap/test/AttributeCheckContextMapper.java +++ b/test-support/src/main/java/org/springframework/ldap/test/AttributeCheckContextMapper.java @@ -20,6 +20,8 @@ import junit.framework.Assert; import org.springframework.ldap.core.ContextMapper; import org.springframework.ldap.core.DirContextAdapter; +import java.util.Arrays; + /** * Dummy ContextMapper for testing purposes to check that the received * Attributes are the expected ones. @@ -45,22 +47,22 @@ public class AttributeCheckContextMapper implements ContextMapper { Assert.assertEquals(expectedValues[i], attributeValue); } - for (int i = 0; i < absentAttributes.length; i++) { - Assert.assertNull(adapter.getStringAttribute(absentAttributes[i])); + for (String absentAttribute : absentAttributes) { + Assert.assertNull(adapter.getStringAttribute(absentAttribute)); } return adapter; } public void setAbsentAttributes(String[] absentAttributes) { - this.absentAttributes = absentAttributes; + this.absentAttributes = Arrays.copyOf(absentAttributes, absentAttributes.length); } public void setExpectedAttributes(String[] expectedAttributes) { - this.expectedAttributes = expectedAttributes; + this.expectedAttributes = Arrays.copyOf(expectedAttributes, expectedAttributes.length); } public void setExpectedValues(String[] expectedValues) { - this.expectedValues = expectedValues; + this.expectedValues = Arrays.copyOf(expectedValues, expectedValues.length); } } \ No newline at end of file