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-94f89814c4df
pull/2/head
jensp 2016-10-19 08:39:22 +00:00
parent 98b59e8f1f
commit a87adf35fa
2 changed files with 30 additions and 3 deletions

View File

@ -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;

View File

@ -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;