From add8c58e2f4b099cbf49bb7cc88c334f9a3aa1e5 Mon Sep 17 00:00:00 2001 From: uhensler <none@none> Date: Wed, 28 Jun 2017 09:48:50 +0200 Subject: [PATCH] OO-2723: Overwrite equals() and hashCode() for serializable classes --- .../java/org/olat/modules/webFeed/Feed.java | 10 +++------- .../java/org/olat/modules/webFeed/Item.java | 10 +++------- .../olat/modules/webFeed/model/FeedImpl.java | 20 +++++++++++-------- .../olat/modules/webFeed/model/ItemImpl.java | 9 ++------- 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/olat/modules/webFeed/Feed.java b/src/main/java/org/olat/modules/webFeed/Feed.java index aea3f64fbec..35b063a08e3 100644 --- a/src/main/java/org/olat/modules/webFeed/Feed.java +++ b/src/main/java/org/olat/modules/webFeed/Feed.java @@ -21,6 +21,8 @@ package org.olat.modules.webFeed; import java.util.Date; +import org.olat.core.id.CreateInfo; +import org.olat.core.id.ModifiedInfo; import org.olat.core.id.OLATResourceable; /** @@ -31,7 +33,7 @@ import org.olat.core.id.OLATResourceable; * @author uhensler, urs.hensler@frentix.com, http://www.frentix.com * */ -public interface Feed extends OLATResourceable { +public interface Feed extends OLATResourceable, CreateInfo, ModifiedInfo { public Long getKey(); @@ -51,14 +53,8 @@ public interface Feed extends OLATResourceable { @Override public String getResourceableTypeName(); - public Date getCreationDate(); - public void setCreationDate(Date creationDate); - public Date getLastModified(); - - public void setLastModified(Date date); - public String getTitle(); public void setTitle(String title); diff --git a/src/main/java/org/olat/modules/webFeed/Item.java b/src/main/java/org/olat/modules/webFeed/Item.java index 86847195e97..253f0ffa8f0 100644 --- a/src/main/java/org/olat/modules/webFeed/Item.java +++ b/src/main/java/org/olat/modules/webFeed/Item.java @@ -23,6 +23,8 @@ import java.util.Date; import org.olat.core.commons.controllers.navigation.Dated; import org.olat.core.gui.components.form.flexible.elements.FileElement; +import org.olat.core.id.CreateInfo; +import org.olat.core.id.ModifiedInfo; /** * @@ -30,7 +32,7 @@ import org.olat.core.gui.components.form.flexible.elements.FileElement; * @author uhensler, urs.hensler@frentix.com, http://www.frentix.com * */ -public interface Item extends Dated { +public interface Item extends Dated, CreateInfo, ModifiedInfo { public Long getKey(); @@ -39,14 +41,8 @@ public interface Item extends Dated { @Override public Date getDate(); - public Date getCreationDate(); - public void setCreationDate(Date date); - public Date getLastModified(); - - public void setLastModified(Date updatedDate); - public String getTitle(); public void setTitle(String title); diff --git a/src/main/java/org/olat/modules/webFeed/model/FeedImpl.java b/src/main/java/org/olat/modules/webFeed/model/FeedImpl.java index e2a95a66894..65a9e38df9b 100644 --- a/src/main/java/org/olat/modules/webFeed/model/FeedImpl.java +++ b/src/main/java/org/olat/modules/webFeed/model/FeedImpl.java @@ -260,17 +260,21 @@ public class FeedImpl implements Feed, Serializable { public int getModelVersion() { return modelVersion; } + + @Override + public int hashCode() { + return getKey() == null ? 43254 : getKey().hashCode(); + } - /** - * Overwrite equals method so that different object that actually - * represent the same item are recognized as such. - */ @Override public boolean equals(Object obj) { - if (!(obj instanceof FeedImpl)) return false; - FeedImpl otherFeed = (FeedImpl) obj; - return this.getResourceableId().equals(otherFeed.getResourceableId()) && - this.getResourceableTypeName().equals(otherFeed.getResourceableTypeName()); + if(this == obj) { + return true; + } else if(obj instanceof FeedImpl) { + FeedImpl feed = (FeedImpl)obj; + return getKey() != null && getKey().equals(feed.getKey()); + } + return false; } } diff --git a/src/main/java/org/olat/modules/webFeed/model/ItemImpl.java b/src/main/java/org/olat/modules/webFeed/model/ItemImpl.java index 3b02d6db3a5..3ff58f6f9e5 100644 --- a/src/main/java/org/olat/modules/webFeed/model/ItemImpl.java +++ b/src/main/java/org/olat/modules/webFeed/model/ItemImpl.java @@ -366,21 +366,16 @@ public class ItemImpl implements Item, Serializable { @Override public int hashCode() { - return guid == null ? 39745 : guid.hashCode(); + return getKey() == null ? 39745 : getKey().hashCode(); } - /** - * Overwrite equals method so that different object that actually - * represent the same item are recognized as such, - * e.g. in the remove method of the feed. - */ @Override public boolean equals(Object obj) { if(this == obj) { return true; } else if(obj instanceof ItemImpl) { ItemImpl item = (ItemImpl)obj; - return guid != null && guid.equals(item.guid); + return getKey() != null && getKey().equals(item.getKey()); } return false; } -- GitLab