/* * IdentifiableBase.java Created on 7. duben 2004, 18:46 */ package net.sf.tomp.general; /** * Base class for identifiable objects, overrides equals(), hashCode() * in order to test equality * * @author tomp */ public class IdentifiableBase implements Identifiable { private String id; /** Creates a new instance of IdentifiableBase */ public IdentifiableBase(String i) { if ((i == null) || (i.length() == 0)) { throw new IllegalArgumentException("Cannot create " + getClass().getName() + " with id==null or empty"); } id = i; } /** @return the ID of the object */ public String getId() { return id; } /** sets the ID to the object */ public void setId(String s) { id = s; } public int hashCode() { return id.hashCode(); } /** Compares objects on the IDs. */ public boolean equals(Object o) { if (o instanceof IdentifiableBase) { IdentifiableBase ui = (IdentifiableBase) o; return id.equals(ui.getId()); } else { return false; } } }