2 * Copyright 2005-2011 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.xmlrouter.impl;
18 import java.util.Collection;
19 import java.util.Collections;
20 import java.util.LinkedHashMap;
22 import java.util.concurrent.atomic.AtomicLong;
24 import org.wamblee.xmlrouter.common.Id;
25 import org.wamblee.xmlrouter.config.Config;
28 * Default implementation of the {@link Config} interface.
30 * @author Erik Brakkee
34 public abstract class ConfigImpl<T> implements Config<T> {
36 private AtomicLong next;
37 private Map<Id<T>, T> registered;
40 * Constructs the object.
43 next = new AtomicLong(1);
44 registered = new LinkedHashMap<Id<T>, T>();
50 * @see org.wamblee.xmlrouter.config.Config#add(T)
53 public Id<T> add(T aT) {
55 long seqno = next.incrementAndGet();
56 Id<T> id = new Id<T>(seqno);
57 registered.put(id, wrap(id, aT));
61 public abstract T wrap(Id<T> aId, T aT);
67 * org.wamblee.xmlrouter.config.Config#remove(org.wamblee.xmlrouter.common
71 public boolean remove(Id<T> aId) {
73 return registered.remove(aId) != null;
79 * @see org.wamblee.xmlrouter.config.Config#ids()
82 public Collection<Id<T>> ids() {
83 return Collections.unmodifiableCollection(registered.keySet());
90 * org.wamblee.xmlrouter.config.Config#get(org.wamblee.xmlrouter.common.Id)
93 public T get(Id<T> aId) {
95 return registered.get(aId);
98 private void notNull(T aT) {
100 throw new NullPointerException("Object is null");
104 private void notNull(Id<T> aId) {
106 throw new NullPointerException("Id is null");