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

com.wassilak.configuration_service.configuration.ConfigurationImpl Maven / Gradle / Ivy

The newest version!
package com.wassilak.configuration_service.configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * The ConfigurationImpl class serves as the reference implementation of the
 * Configuration interface. This object is a container for users to place
 * application specific properties. This implementation uses a HashMap to
 * store generic application properties.
 * 

* Copyright (C) 2014 John Wassilak ([email protected]) *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. *

* This program 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 General Public License for more details. *

* You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ final class ConfigurationImpl implements Configuration { /** * The applicationName property contains the name of the application that * this configuration was created for. */ private final String applicationName; /** * The applicationVersion property contains the version of the application * that this configuration was created for. */ private final String applicationVersion; /** * The properties property contains the actual key/value mapping of * configuration properties. */ private final Map properties; /** * The ConfigurationImpl constructor creates a ConfigurationImpl object * after validating the given parameters. * * @param applicationName The name of the application that this * configuration is for. This must be provided. * @param applicationVersion The version of the application that this * configuration is for. This must be provided. * @throws ConfigurationException If the Configuration is being created * with invalid parameters. */ ConfigurationImpl(String applicationName, String applicationVersion) throws ConfigurationException { if (applicationName == null || applicationName.length() < 1) { throw new ConfigurationException( "applicationName must be provided." ); } else { this.applicationName = applicationName; } if (applicationVersion == null || applicationVersion.length() < 1) { throw new ConfigurationException( "applicationVersion must be provided." ); } else { this.applicationVersion = applicationVersion; } properties = new HashMap(); } /** * The getApplicationName method returns the name of the application that * the configuration was created for. * * @return The name of the application that the configuration was created * for. */ public String getApplicationName() { return applicationName; } /** * The getApplicationVersion method returns the version of the application * that the configuration was created for. * * @return The version of the application that the configuration was * created for. */ public String getApplicationVersion() { return applicationVersion; } /** * The getProperty method returns the value to which the specified key is * mapped, or null if this configuration contains no mapping for the key. * * @param key The key whose associated value is to be returned. * @return The value to which the specified key is mapped, or null if this * configuration contains no mapping for the key. */ public synchronized Object getProperty(String key) { return properties.get(key); } /** * The setProperty method associates the specified value with the * specified key in this configuration. If the configuration previously * contained a mapping for the key, the old value is replaced by the * specified value. * * @param key The key with which the specified value is to be associated. * @param value The value to be associated with the specified key. */ public synchronized void setProperty(String key, Object value) { properties.put(key, value); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy