git://wamblee.org
/
xmlrouter
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
equality based on the ids of the contents of SingleRouterConfig.
[xmlrouter]
/
impl
/
src
/
main
/
java
/
org
/
wamblee
/
xmlrouter
/
impl
/
ConfigImpl.java
diff --git
a/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java
b/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java
index c561e364b287958a169a90eb611baa58769ed3fc..a1733ab41bf84a9b84cb3986f460586871bd763e 100644
(file)
--- a/
impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java
+++ b/
impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java
@@
-15,13
+15,16
@@
*/
package org.wamblee.xmlrouter.impl;
*/
package org.wamblee.xmlrouter.impl;
-import java.util.ArrayList;
+import static org.wamblee.xmlrouter.impl.MessageUtil.*;
+
+import java.util.Collection;
import java.util.Collections;
import java.util.Collections;
-import java.util.
Iterator
;
-import java.util.
List
;
+import java.util.
HashMap
;
+import java.util.
Map
;
import org.wamblee.xmlrouter.common.Id;
import org.wamblee.xmlrouter.config.Config;
import org.wamblee.xmlrouter.common.Id;
import org.wamblee.xmlrouter.config.Config;
+import org.wamblee.xmlrouter.config.ConfigException;
import org.wamblee.xmlrouter.config.Identifiable;
/**
import org.wamblee.xmlrouter.config.Identifiable;
/**
@@
-31,19
+34,19
@@
import org.wamblee.xmlrouter.config.Identifiable;
*
* @param <T>
*/
*
* @param <T>
*/
-public abstract class ConfigImpl<T extends Identifiable> implements
+public abstract class ConfigImpl<T extends Identifiable
<T>
> implements
ExtendedConfig<T> {
private Id<Config> id;
ExtendedConfig<T> {
private Id<Config> id;
- private
List<
T> registered;
+ private
Map<Id<T>,
T> registered;
/**
* Constructs the object.
*/
public ConfigImpl(Id<Config> aId) {
/**
* Constructs the object.
*/
public ConfigImpl(Id<Config> aId) {
- // TODO test for null.
+ notNull("id", aId);
id = aId;
id = aId;
- registered = new
ArrayList<
T>();
+ registered = new
HashMap<Id<T>,
T>();
}
@Override
}
@Override
@@
-58,9
+61,11
@@
public abstract class ConfigImpl<T extends Identifiable> implements
*/
@Override
public synchronized void add(T aT) {
*/
@Override
public synchronized void add(T aT) {
- // TODO test duplicate ids.
- notNull(aT);
- registered.add(wrap(aT));
+ notNull("aT", aT);
+ if (registered.containsKey(aT.getId())) {
+ throw new ConfigException("Duplicate id '" + aT.getId() + "'");
+ }
+ registered.put(aT.getId(), wrap(id.getId() + ".", aT));
}
/**
}
/**
@@
-70,7
+75,7
@@
public abstract class ConfigImpl<T extends Identifiable> implements
* Object to wrap.
* @return Wrapped object.
*/
* Object to wrap.
* @return Wrapped object.
*/
- public abstract T wrap(T aT);
+ public abstract T wrap(
String aPrefix,
T aT);
/*
* (non-Javadoc)
/*
* (non-Javadoc)
@@
-81,32
+86,34
@@
public abstract class ConfigImpl<T extends Identifiable> implements
*/
@Override
public synchronized boolean remove(Id<T> aId) {
*/
@Override
public synchronized boolean remove(Id<T> aId) {
- notNull(aId);
- Iterator<T> i = registered.iterator();
- while (i.hasNext()) {
- T t = i.next();
- if (t.getId().equals(aId)) {
- i.remove();
- return true;
- }
+ notNull("aId", aId);
+ T value = registered.get(aId);
+ if (value != null) {
+ registered.remove(aId);
+ return true;
}
return false;
}
@Override
}
return false;
}
@Override
- public
List
<T> values() {
- return Collections.unmodifiable
List(registered
);
+ public
Collection
<T> values() {
+ return Collections.unmodifiable
Collection(registered.values()
);
}
}
- private void notNull(T aT) {
- if (aT == null) {
- throw new NullPointerException("Object is null");
+ @Override
+ public boolean equals(Object aObj) {
+ if (aObj == null) {
+ return false;
}
}
+ if (!(aObj instanceof ConfigImpl)) {
+ return false;
+ }
+ ConfigImpl obj = (ConfigImpl) aObj;
+ return registered.keySet().equals(obj.registered.keySet());
}
}
- private void notNull(Id<T> aId) {
- if (aId == null) {
- throw new NullPointerException("Id is null");
- }
+ @Override
+ public int hashCode() {
+ return registered.keySet().hashCode();
}
}
}
}