/*
 * Copyright 2012 Erwin Müller <erwin.mueller@deventm.org>
 *
 * This file is part of sscontrol-core.
 *
 * sscontrol-core is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * sscontrol-core is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with sscontrol-core. If not, see <http://www.gnu.org/licenses/>.
 */
package com.anrisoftware.sscontrol.core.registry;

import static org.apache.commons.collections.list.UnmodifiableList.decorate;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import org.apache.commons.collections.collection.UnmodifiableCollection;
import org.apache.commons.collections.map.MultiValueMap;
import org.apache.commons.collections.set.UnmodifiableSet;
import org.apache.commons.lang3.builder.ToStringBuilder;

import com.anrisoftware.sscontrol.core.api.Service;
import com.anrisoftware.sscontrol.core.api.ServicesRegistry;

/**
 * Stores the services.
 * 
 * @author Erwin Mueller, erwin.mueller@deventm.org
 * @since 0.1
 */
class ServicesRegistryImpl implements ServicesRegistry {

	/**
	 * 
	 * @version 0.1
	 */
	private static final long serialVersionUID = -5209241548874285959L;

	private final MultiValueMap services;

	ServicesRegistryImpl() {
		this.services = new MultiValueMap();
	}

	@Override
	public void addService(Service service) {
		services.put(service.getName(), service);
	}

	@SuppressWarnings({ "unchecked" })
	@Override
	public List<Service> getService(String name) {
		return decorate(new ArrayList<Object>(services.getCollection(name)));
	}

	@SuppressWarnings("unchecked")
	@Override
	public Collection<Service> getAllServices() {
		List<Service> services = new ArrayList<Service>();
		for (String name : getServiceNames()) {
			services.addAll(getService(name));
		}
		return UnmodifiableCollection.decorate(services);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Set<String> getServiceNames() {
		return UnmodifiableSet.decorate(services.keySet());
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("services", services.keySet())
				.toString();
	}
}

@@ -841,36 +841,27 @@
  static 
-org.apache.commons.c
+java.util.C
 ollectio
@@ -867,14 +867,9 @@
 ons.
-list.U
+u
 nmod
@@ -879,25 +879,69 @@
 ableList
-.decorate
+;%0Aimport static java.util.Collections.unmodifiableSet
 ;%0A%0Aimpor
@@ -1080,157 +1080,25 @@
 ons.
-collection.UnmodifiableCollection;%0Aimport org.apache.commons.collections.map.MultiValueMap;%0Aimport org.apache.commons.collections.set.UnmodifiableSet
+map.MultiValueMap
 ;%0Aim
@@ -1361,19 +1361,19 @@
  @since 
-0.1
+1.0
 %0A */%0Acla
@@ -1436,13 +1436,8 @@
 /**%0A
-%09 * %0A
 %09 * 
@@ -1449,11 +1449,11 @@
 ion 
-0.1
+1.0
 %0A%09 *
@@ -1758,10 +1758,8 @@
 ngs(
-%7B 
 %22unc
@@ -1769,10 +1769,8 @@
 ked%22
- %7D
 )%0A%09@
@@ -1835,24 +1835,32 @@
 %09return 
-decorate
+unmodifiableList
 (new Arr
@@ -1870,16 +1870,22 @@
 ist%3C
-Object%3E(
+Service%3E(%0A%09%09%09%09
 serv
@@ -1920,40 +1920,8 @@
 %09%7D%0A%0A
-%09@SuppressWarnings(%22unchecked%22)%0A
 %09@Ov
@@ -2112,33 +2112,33 @@
 );%0A%09%09%7D%0A%09%09return 
-U
+u
 nmodifiableColle
@@ -2136,27 +2136,12 @@
 able
-Collection.decorate
+List
 (ser
@@ -2244,17 +2244,17 @@
 %09return 
-U
+u
 nmodifia
@@ -2263,17 +2263,8 @@
 eSet
-.decorate
 (ser

Use Java Collections class