All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.csar.DefaultConcernRegistry Maven / Gradle / Ivy

Go to download

Csar (/zɑːr/) provides access to concerns (usually cross-cutting) configured globally or locally.

There is a newer version: 0.9.0
Show newest version
/*
 * Copyright © 2009 GlobalMentor, Inc. 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.csar;

import static java.util.Objects.*;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Default implementation of a registry of concerns. This class is concurrent thread-safe.
 * @author Garret Wilson
 * @see Csar
 */
public class DefaultConcernRegistry implements ConcernRegistry {

	/** The map of concerns keyed to their types. */
	private final Map, Concern> concerns = new ConcurrentHashMap, Concern>();

	@Override
	public final void registerConcerns(final Concern... concerns) {
		for(final Concern concern : concerns) {
			registerConcern(concern);
		}
	}

	@Override
	@SuppressWarnings("unchecked")
	public final  C registerConcern(final C concern) {
		return registerConcern((Class)concern.getClass(), concern);
	}

	@Override
	@SuppressWarnings("unchecked")
	public final  C registerConcern(final Class concernClass, final C concern) {
		return (C)concerns.put(concernClass, requireNonNull(concern, "Concern cannot be null."));
	}

	@Override
	@SuppressWarnings("unchecked")
	public  C getConcern(final Class concernClass) {
		return (C)concerns.get(concernClass);
	}

	@Override
	@SuppressWarnings("unchecked")
	public  C unregisterConcern(final Class concernClass) {
		return (C)concerns.remove(concernClass);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy