mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
[DS-2763] Continue cleaning up serialization bugs found by Findbugs
This commit is contained in:

committed by
Mark H. Wood

parent
e61352ef29
commit
3b123a05e0
@@ -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());
|
||||||
|
@@ -17,12 +17,12 @@ import org.dspace.sort.OrderFormat;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare two Items by their DCValues.
|
* Compare two Items by their DCValues.
|
||||||
*
|
*
|
||||||
* The DCValues to be compared are specified by the element, qualifier and
|
* The DCValues to be compared are specified by the element, qualifier and
|
||||||
language parameters to the constructor. If the Item has more than one
|
language parameters to the constructor. If the Item has more than one
|
||||||
matching Metadatum, then the max parameter to the constructor specifies whether
|
matching Metadatum, then the max parameter to the constructor specifies whether
|
||||||
the maximum or minimum lexicographic value will be used.
|
the maximum or minimum lexicographic value will be used.
|
||||||
*
|
*
|
||||||
* @author Peter Breton
|
* @author Peter Breton
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
*/
|
*/
|
||||||
@@ -40,11 +40,12 @@ 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.
|
||||||
*
|
*
|
||||||
* @param element
|
* @param element
|
||||||
* The Dublin Core element
|
* The Dublin Core element
|
||||||
* @param qualifier
|
* @param qualifier
|
||||||
@@ -63,19 +64,18 @@ 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare two Items by checking their DCValues for element, qualifier, and
|
* Compare two Items by checking their DCValues for element, qualifier, and
|
||||||
* language.
|
* language.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Return >= 1 if the first is lexicographically greater than the second; <=
|
* Return >= 1 if the first is lexicographically greater than the second; <=
|
||||||
* -1 if the second is lexicographically greater than the first, and 0
|
* -1 if the second is lexicographically greater than the first, and 0
|
||||||
* otherwise.
|
* otherwise.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param first
|
* @param first
|
||||||
* The first object to compare. Must be an object of type
|
* The first object to compare. Must be an object of type
|
||||||
* org.dspace.content.Item.
|
* org.dspace.content.Item.
|
||||||
@@ -122,11 +122,12 @@ public class ItemComparator implements Comparator, Serializable
|
|||||||
* Return true if the object is equal to this one, false otherwise. Another
|
* Return true if the object is equal to this one, false otherwise. Another
|
||||||
* object is equal to this one if it is also an ItemComparator, and has the
|
* object is equal to this one if it is also an ItemComparator, and has the
|
||||||
* same values for element, qualifier, language, and max.
|
* same values for element, qualifier, language, and max.
|
||||||
*
|
*
|
||||||
* @param obj
|
* @param obj
|
||||||
* 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)
|
||||||
@@ -170,7 +174,7 @@ public class ItemComparator implements Comparator, Serializable
|
|||||||
* values, null is returned. If there is exactly one value, then it is
|
* values, null is returned. If there is exactly one value, then it is
|
||||||
* returned. Otherwise, either the maximum or minimum lexicographical value
|
* returned. Otherwise, either the maximum or minimum lexicographical value
|
||||||
* is returned; the parameter to the constructor says which.
|
* is returned; the parameter to the constructor says which.
|
||||||
*
|
*
|
||||||
* @param item
|
* @param item
|
||||||
* The item to check
|
* The item to check
|
||||||
* @return The chosen value, or null
|
* @return The chosen value, or null
|
||||||
@@ -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)
|
||||||
{
|
{
|
||||||
|
@@ -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> {
|
||||||
}
|
}
|
||||||
|
@@ -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> {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user