Skip to content
Snippets Groups Projects
Commit add8c58e authored by uhensler's avatar uhensler
Browse files

OO-2723: Overwrite equals() and hashCode() for serializable classes

parent a1340ebb
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,8 @@ package org.olat.modules.webFeed; ...@@ -21,6 +21,8 @@ package org.olat.modules.webFeed;
import java.util.Date; import java.util.Date;
import org.olat.core.id.CreateInfo;
import org.olat.core.id.ModifiedInfo;
import org.olat.core.id.OLATResourceable; import org.olat.core.id.OLATResourceable;
/** /**
...@@ -31,7 +33,7 @@ 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 * @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(); public Long getKey();
...@@ -51,14 +53,8 @@ public interface Feed extends OLATResourceable { ...@@ -51,14 +53,8 @@ public interface Feed extends OLATResourceable {
@Override @Override
public String getResourceableTypeName(); public String getResourceableTypeName();
public Date getCreationDate();
public void setCreationDate(Date creationDate); public void setCreationDate(Date creationDate);
public Date getLastModified();
public void setLastModified(Date date);
public String getTitle(); public String getTitle();
public void setTitle(String title); public void setTitle(String title);
......
...@@ -23,6 +23,8 @@ import java.util.Date; ...@@ -23,6 +23,8 @@ import java.util.Date;
import org.olat.core.commons.controllers.navigation.Dated; import org.olat.core.commons.controllers.navigation.Dated;
import org.olat.core.gui.components.form.flexible.elements.FileElement; 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; ...@@ -30,7 +32,7 @@ import org.olat.core.gui.components.form.flexible.elements.FileElement;
* @author uhensler, urs.hensler@frentix.com, http://www.frentix.com * @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(); public Long getKey();
...@@ -39,14 +41,8 @@ public interface Item extends Dated { ...@@ -39,14 +41,8 @@ public interface Item extends Dated {
@Override @Override
public Date getDate(); public Date getDate();
public Date getCreationDate();
public void setCreationDate(Date date); public void setCreationDate(Date date);
public Date getLastModified();
public void setLastModified(Date updatedDate);
public String getTitle(); public String getTitle();
public void setTitle(String title); public void setTitle(String title);
......
...@@ -260,17 +260,21 @@ public class FeedImpl implements Feed, Serializable { ...@@ -260,17 +260,21 @@ public class FeedImpl implements Feed, Serializable {
public int getModelVersion() { public int getModelVersion() {
return modelVersion; 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 @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof FeedImpl)) return false; if(this == obj) {
FeedImpl otherFeed = (FeedImpl) obj; return true;
return this.getResourceableId().equals(otherFeed.getResourceableId()) && } else if(obj instanceof FeedImpl) {
this.getResourceableTypeName().equals(otherFeed.getResourceableTypeName()); FeedImpl feed = (FeedImpl)obj;
return getKey() != null && getKey().equals(feed.getKey());
}
return false;
} }
} }
...@@ -366,21 +366,16 @@ public class ItemImpl implements Item, Serializable { ...@@ -366,21 +366,16 @@ public class ItemImpl implements Item, Serializable {
@Override @Override
public int hashCode() { 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 @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if(this == obj) { if(this == obj) {
return true; return true;
} else if(obj instanceof ItemImpl) { } else if(obj instanceof ItemImpl) {
ItemImpl item = (ItemImpl)obj; ItemImpl item = (ItemImpl)obj;
return guid != null && guid.equals(item.guid); return getKey() != null && getKey().equals(item.getKey());
} }
return false; return false;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment