CCM NG/ccm-cms: AttachmentList and ItemAttachment now implement the Comparable interface
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4391 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
98b59e8f1f
commit
a87adf35fa
|
|
@ -55,7 +55,9 @@ import static org.librecms.CmsConstants.*;
|
|||
@Entity
|
||||
@Table(name = "ATTACHMENT_LISTS", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
public class AttachmentList implements Identifiable, Serializable {
|
||||
public class AttachmentList implements Comparable<AttachmentList>,
|
||||
Identifiable,
|
||||
Serializable {
|
||||
|
||||
private static final long serialVersionUID = -7931234562247075541L;
|
||||
|
||||
|
|
@ -201,6 +203,20 @@ public class AttachmentList implements Identifiable, Serializable {
|
|||
attachments.remove(attachment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final AttachmentList other) {
|
||||
if (other == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
final int nameCompare = name.compareTo(other.getName());
|
||||
if (nameCompare == 0) {
|
||||
return Long.compare(order, other.getOrder());
|
||||
} else {
|
||||
return nameCompare;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 3;
|
||||
|
|
|
|||
|
|
@ -46,8 +46,10 @@ import static org.librecms.CmsConstants.*;
|
|||
@Entity
|
||||
@Table(schema = DB_SCHEMA, name = "ATTACHMENTS")
|
||||
@Audited
|
||||
public class ItemAttachment<T extends Asset> implements Identifiable,
|
||||
Serializable {
|
||||
public class ItemAttachment<T extends Asset>
|
||||
implements Comparable<ItemAttachment<?>>,
|
||||
Identifiable,
|
||||
Serializable {
|
||||
|
||||
private static final long serialVersionUID = -9005379413315191984L;
|
||||
|
||||
|
|
@ -127,6 +129,15 @@ public class ItemAttachment<T extends Asset> implements Identifiable,
|
|||
this.sortKey = sortKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final ItemAttachment<?> other) {
|
||||
if (other == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
return Long.compare(sortKey, other.getSortKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 3;
|
||||
|
|
|
|||
Loading…
Reference in New Issue