git://wamblee.org
/
xmlrouter
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
First version after introduction of meaningful ids and Identifiable interface.
[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 789f75c5178db2da3579c10cd14f1fd96c193932..c561e364b287958a169a90eb611baa58769ed3fc 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,14
+15,14
@@
*/
package org.wamblee.xmlrouter.impl;
*/
package org.wamblee.xmlrouter.impl;
-import java.util.
Collection
;
+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.
@@
-31,17
+31,24
@@
import org.wamblee.xmlrouter.config.Config;
*
* @param <T>
*/
*
* @param <T>
*/
-public abstract class ConfigImpl<T> implements Config<T> {
+public abstract class ConfigImpl<T extends Identifiable> implements
+ ExtendedConfig<T> {
- 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() {
- next = new AtomicLong(1);
- 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;
}
/*
}
/*
@@
-50,15
+57,20
@@
public abstract class ConfigImpl<T> implements Config<T> {
* @see org.wamblee.xmlrouter.config.Config#add(T)
*/
@Override
* @see org.wamblee.xmlrouter.config.Config#add(T)
*/
@Override
- public 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));
- return id;
+ registered.add(wrap(aT));
}
}
- public abstract T wrap(Id<T> aId, T aT);
+ /**
+ * This is called to wrap the given object by a safer version.
+ *
+ * @param aT
+ * Object to wrap.
+ * @return Wrapped object.
+ */
+ public abstract T wrap(T aT);
/*
* (non-Javadoc)
/*
* (non-Javadoc)
@@
-68,31
+80,22
@@
public abstract class ConfigImpl<T> implements Config<T> {
* .Id)
*/
@Override
* .Id)
*/
@Override
- public boolean remove(Id<T> aId) {
+ public
synchronized
boolean remove(Id<T> aId) {
notNull(aId);
notNull(aId);
- return registered.remove(aId) != null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.wamblee.xmlrouter.config.Config#ids()
- */
- @Override
- public Collection<Id<T>> ids() {
- return Collections.unmodifiableCollection(registered.keySet());
+ Iterator<T> i = registered.iterator();
+ while (i.hasNext()) {
+ T t = i.next();
+ if (t.getId().equals(aId)) {
+ i.remove();
+ return true;
+ }
+ }
+ return false;
}
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.wamblee.xmlrouter.config.Config#get(org.wamblee.xmlrouter.common.Id)
- */
@Override
@Override
- public T get(Id<T> aId) {
- notNull(aId);
- return registered.get(aId);
+ public List<T> values() {
+ return Collections.unmodifiableList(registered);
}
private void notNull(T aT) {
}
private void notNull(T aT) {