git://wamblee.org
/
xmlrouter
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
now making sure that ids re prefixed by the config id.
[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 54c0c6d2357604103284b1d818c754a2e1fdc551..5beeed5c12da92ece9bb9833d39bbe0c0bc2241e 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,14
@@
*/
package org.wamblee.xmlrouter.impl;
*/
package org.wamblee.xmlrouter.impl;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicLong;
+import java.util.Iterator;
+import java.util.List;
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.Identifiable;
/**
* Default implementation of the {@link Config} interface.
/**
* Default implementation of the {@link Config} interface.
@@
-30,19
+31,26
@@
import org.wamblee.xmlrouter.config.Config;
*
* @param <T>
*/
*
* @param <T>
*/
-public abstract class ConfigImpl<T> implements ExtendedConfig<T> {
+// TODO make sure that each item inside this config is prefixed with the id of
+// the config.
+public abstract class ConfigImpl<T extends Identifiable> implements
+ ExtendedConfig<T> {
- private boolean dirty;
- private AtomicLong next;
- private Map<Id<T>, T> registered;
+ private Id<Config> id;
+ private List<T> registered;
/**
* Constructs the object.
*/
/**
* Constructs the object.
*/
- public ConfigImpl(AtomicLong aNext) {
- dirty = false;
- next = aNext;
- registered = new LinkedHashMap<Id<T>, T>();
+ public ConfigImpl(Id<Config> aId) {
+ // TODO test for null.
+ id = aId;
+ registered = new ArrayList<T>();
+ }
+
+ @Override
+ public Id<Config> getId() {
+ return id;
}
/*
}
/*
@@
-51,25
+59,20
@@
public abstract class ConfigImpl<T> implements ExtendedConfig<T> {
* @see org.wamblee.xmlrouter.config.Config#add(T)
*/
@Override
* @see org.wamblee.xmlrouter.config.Config#add(T)
*/
@Override
- public synchronized Id<T> add(T aT) {
+ public synchronized void add(T aT) {
+ // TODO test duplicate ids.
notNull(aT);
notNull(aT);
- long seqno = next.incrementAndGet();
- Id<T> id = new Id<T>(seqno);
- registered.put(id, wrap(id, aT));
- dirty = true;
- return id;
+ registered.add(wrap(id.getId() + ".", aT));
}
/**
* This is called to wrap the given object by a safer version.
*
}
/**
* This is called to wrap the given object by a safer version.
*
- * @param aId
- * Id.
* @param aT
* Object to wrap.
* @return Wrapped object.
*/
* @param aT
* Object to wrap.
* @return Wrapped object.
*/
- public abstract T wrap(
Id<T> aId
, T aT);
+ public abstract T wrap(
String aPrefix
, T aT);
/*
* (non-Javadoc)
/*
* (non-Javadoc)
@@
-81,13
+84,20
@@
public abstract class ConfigImpl<T> implements ExtendedConfig<T> {
@Override
public synchronized boolean remove(Id<T> aId) {
notNull(aId);
@Override
public synchronized boolean remove(Id<T> aId) {
notNull(aId);
- dirty = true;
- return registered.remove(aId) != null;
+ Iterator<T> i = registered.iterator();
+ while (i.hasNext()) {
+ T t = i.next();
+ if (t.getId().equals(aId)) {
+ i.remove();
+ return true;
+ }
+ }
+ return false;
}
@Override
}
@Override
- public
Map<Id<T>, T> map
() {
- return Collections.unmodifiable
Map
(registered);
+ public
List<T> values
() {
+ return Collections.unmodifiable
List
(registered);
}
private void notNull(T aT) {
}
private void notNull(T aT) {
@@
-101,14
+111,4
@@
public abstract class ConfigImpl<T> implements ExtendedConfig<T> {
throw new NullPointerException("Id is null");
}
}
throw new NullPointerException("Id is null");
}
}
-
- @Override
- public boolean isDirty() {
- return dirty;
- }
-
- @Override
- public void resetDirty() {
- dirty = false;
- }
}
}