Package org.dspace.content
Class ItemComparator
- java.lang.Object
-
- org.dspace.content.ItemComparator
-
- All Implemented Interfaces:
Serializable,Comparator
public class ItemComparator extends Object implements Comparator, Serializable
Compare two Items by their DCValues. The DCValues to be compared are specified by the element, qualifier and language parameters to the constructor. If the Item has more than one matching Metadatum, then the max parameter to the constructor specifies whether the maximum or minimum lexicographic value will be used.- Version:
- $Revision$
- Author:
- Peter Breton
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected StringelementDublin Core elementprotected ItemServiceitemServiceprotected StringlanguageLanguageprotected booleanmaxWhether maximum or minimum value will be usedprotected StringqualifierDublin Core qualifier
-
Constructor Summary
Constructors Constructor Description ItemComparator(String element, String qualifier, String language, boolean max)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompare(Object first, Object second)Compare two Items by checking their DCValues for element, qualifier, and language.booleanequals(Object obj)Return true if the object is equal to this one, false otherwise.protected booleanequalsWithNull(String first, String second)protected StringgetValue(Item item)Choose the canonical value from an item for comparison.inthashCode()protected StringnormalizeTitle(MetadataValue value)Normalize the title of a Metadatum.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Field Detail
-
element
protected String element
Dublin Core element
-
qualifier
protected String qualifier
Dublin Core qualifier
-
language
protected String language
Language
-
max
protected boolean max
Whether maximum or minimum value will be used
-
itemService
protected transient ItemService itemService
-
-
Constructor Detail
-
ItemComparator
public ItemComparator(String element, String qualifier, String language, boolean max)
Constructor.- Parameters:
element- The Dublin Core elementqualifier- The Dublin Core qualifierlanguage- The language for the DCValuesmax- If true, and there is more than one Metadatum for element, qualifier and language, then use the maximum value lexicographically; otherwise use the minimum value.
-
-
Method Detail
-
compare
public int compare(Object first, Object second)
Compare two Items by checking their DCValues for element, qualifier, and language.Return greater than or equal to 1 if the first is lexicographically greater than the second; less than or equal to -1 if the second is lexicographically greater than the first, and 0 otherwise.
- Specified by:
comparein interfaceComparator- Parameters:
first- The first object to compare. Must be an object of type org.dspace.content.Item.second- The second object to compare. Must be an object of type org.dspace.content.Item.- Returns:
- greater than or equal 1 if the first is lexicographically greater than the second; less than or equal -1 if the second is lexicographically greater than the first, and 0 otherwise.
-
equals
public boolean equals(Object obj)
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 same values for element, qualifier, language, and max.- Specified by:
equalsin interfaceComparator- Overrides:
equalsin classObject- Parameters:
obj- The object to compare to.- Returns:
- True if the other object is equal to this one, false otherwise.
-
equalsWithNull
protected boolean equalsWithNull(String first, String second)
- Parameters:
first- first operandsecond- second operand- Returns:
- true if the first string is equal to the second. Either or both may be null.
-
getValue
protected String getValue(Item item)
Choose the canonical value from an item for comparison. If there are no values, null is returned. If there is exactly one value, then it is returned. Otherwise, either the maximum or minimum lexicographical value is returned; the parameter to the constructor says which.- Parameters:
item- The item to check- Returns:
- The chosen value, or null
-
normalizeTitle
protected String normalizeTitle(MetadataValue value)
Normalize the title of a Metadatum.- Parameters:
value- metadata value- Returns:
- normalized title
-
-