X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FRobustIdentifiable.java;h=2e63a9799901f2616e6fdc6fc1438c80adf570a1;hb=2e9a88b0478d074974818dc384ca45c2bf4fdaa5;hp=f3da5f401e98f0dd7ae252c8c04458c781a51ad9;hpb=e52385618670b54a5c6a4f2fbfab381bef43a905;p=xmlrouter diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustIdentifiable.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustIdentifiable.java index f3da5f4..2e63a97 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustIdentifiable.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustIdentifiable.java @@ -15,14 +15,18 @@ */ package org.wamblee.xmlrouter.impl; +import static org.wamblee.xmlrouter.impl.MessageUtil.*; + import java.util.logging.Level; import java.util.logging.Logger; import org.wamblee.xmlrouter.common.Id; +import org.wamblee.xmlrouter.config.ConfigException; import org.wamblee.xmlrouter.config.Identifiable; /** - * Robust identifiable provides robustness for identifiable objects. + * Robust identifiable provides robustness for identifiable objects. It adds + * equality based on the id. * * @author Erik Brakkee * @@ -34,33 +38,29 @@ public class RobustIdentifiable implements Identifiable { private Id id; - // TODO test this class. - // TODO test that id is constant even though delegated changes its id. - public RobustIdentifiable(Identifiable aIdentifiable) { - // TODO test id is null - // TODO getId() throws exception + notNull("identifiable", aIdentifiable); try { id = aIdentifiable.getId(); if (id == null) { - id = new Id(Constants.UNKNOWN_ID.toString()); - throw new RuntimeException( - "Temporary to catch nulls during refactoring"); + throwConfigException("identifiable.getId() returned null", null); } } catch (Exception e) { - LOGGER - .log(Level.WARNING, "Identifiable getId() threw exception", e); + throwConfigException("identifiable.getId() threw exception", e); } } + private void throwConfigException(String aMsg, Exception aException) { + LOGGER.log(Level.WARNING, aMsg, aException); + throw new ConfigException(aMsg); + } + @Override public Id getId() { return id; } - // TODO test equals, hashcode. - @Override public int hashCode() { return id.hashCode();