[DS-2763] Continue cleaning up serialization bugs found by Findbugs

This commit is contained in:
Mark H. Wood
2015-11-13 21:53:48 -05:00
committed by Mark H. Wood
parent e61352ef29
commit 3b123a05e0
4 changed files with 28 additions and 14 deletions

View File

@@ -7,9 +7,15 @@
*/ */
package org.dspace.content; package org.dspace.content;
import java.io.Serializable;
import java.util.Comparator; import java.util.Comparator;
public class CollectionNameComparator implements Comparator<Collection> { /**
* Compares the names of two {@link Collection}s.
*/
public class CollectionNameComparator
implements Comparator<Collection>, Serializable
{
@Override @Override
public int compare(Collection collection1, Collection collection2) { public int compare(Collection collection1, Collection collection2) {
return collection1.getName().compareTo(collection2.getName()); return collection1.getName().compareTo(collection2.getName());

View File

@@ -40,7 +40,8 @@ public class ItemComparator implements Comparator, Serializable
/** Whether maximum or minimum value will be used */ /** Whether maximum or minimum value will be used */
protected boolean max; protected boolean max;
protected ItemService itemService; protected transient ItemService itemService
= ContentServiceFactory.getInstance().getItemService();
/** /**
* Constructor. * Constructor.
@@ -63,7 +64,6 @@ public class ItemComparator implements Comparator, Serializable
this.qualifier = qualifier; this.qualifier = qualifier;
this.language = language; this.language = language;
this.max = max; this.max = max;
this.itemService = ContentServiceFactory.getInstance().getItemService();
} }
/** /**
@@ -127,6 +127,7 @@ public class ItemComparator implements Comparator, Serializable
* The object to compare to. * The object to compare to.
* @return True if the other object is equal to this one, false otherwise. * @return True if the other object is equal to this one, false otherwise.
*/ */
@Override
public boolean equals(Object obj) public boolean equals(Object obj)
{ {
if (!(obj instanceof ItemComparator)) if (!(obj instanceof ItemComparator))
@@ -141,13 +142,16 @@ public class ItemComparator implements Comparator, Serializable
&& equalsWithNull(language, other.language) && (max == other.max); && equalsWithNull(language, other.language) && (max == other.max);
} }
@Override
public int hashCode() public int hashCode()
{ {
return new HashCodeBuilder().append(element).append(qualifier).append(language).append(max).toHashCode(); return new HashCodeBuilder().append(element).append(qualifier).append(language).append(max).toHashCode();
} }
/** /**
* Return true if the first string is equal to the second. Either or both * @param first
* @param second
* @return true if the first string is equal to the second. Either or both
* may be null. * may be null.
*/ */
protected boolean equalsWithNull(String first, String second) protected boolean equalsWithNull(String first, String second)
@@ -180,7 +184,7 @@ public class ItemComparator implements Comparator, Serializable
// The overall array and each element are guaranteed non-null // The overall array and each element are guaranteed non-null
List<MetadataValue> dcvalues = itemService.getMetadata(item, MetadataSchema.DC_SCHEMA, element, qualifier, language); List<MetadataValue> dcvalues = itemService.getMetadata(item, MetadataSchema.DC_SCHEMA, element, qualifier, language);
if (dcvalues.size() == 0) if (dcvalues.isEmpty())
{ {
return null; return null;
} }
@@ -192,7 +196,7 @@ public class ItemComparator implements Comparator, Serializable
// We want to sort using Strings, but also keep track of // We want to sort using Strings, but also keep track of
// which Metadatum the value came from. // which Metadatum the value came from.
Map<String, Integer> values = new HashMap<String, Integer>(); Map<String, Integer> values = new HashMap<>();
for (int i = 0; i < dcvalues.size(); i++) for (int i = 0; i < dcvalues.size(); i++)
{ {
@@ -204,7 +208,7 @@ public class ItemComparator implements Comparator, Serializable
} }
} }
if (values.size() == 0) if (values.isEmpty())
{ {
return null; return null;
} }
@@ -220,6 +224,8 @@ public class ItemComparator implements Comparator, Serializable
/** /**
* Normalize the title of a Metadatum. * Normalize the title of a Metadatum.
* @param value
* @return
*/ */
protected String normalizeTitle(MetadataValue value) protected String normalizeTitle(MetadataValue value)
{ {

View File

@@ -15,6 +15,7 @@ import org.dspace.core.GenericDAO;
* All DSpaceObject DAO classes should implement this class since it ensures that the T object is of type DSpaceObject * All DSpaceObject DAO classes should implement this class since it ensures that the T object is of type DSpaceObject
* *
* @author kevinvandevelde at atmire.com * @author kevinvandevelde at atmire.com
* @param <T>
*/ */
public interface DSpaceObjectDAO<T extends DSpaceObject> extends GenericDAO<T> { public interface DSpaceObjectDAO<T extends DSpaceObject> extends GenericDAO<T> {
} }

View File

@@ -17,6 +17,7 @@ import java.sql.SQLException;
* to identify DSpaceObjects prior to DSpace 6.0 * to identify DSpaceObjects prior to DSpace 6.0
* *
* @author kevinvandevelde at atmire.com * @author kevinvandevelde at atmire.com
* @param <T>
*/ */
public interface DSpaceObjectLegacySupportDAO<T extends DSpaceObject> extends DSpaceObjectDAO<T> { public interface DSpaceObjectLegacySupportDAO<T extends DSpaceObject> extends DSpaceObjectDAO<T> {