package com.pi4j.component;
/*
* #%L
* **********************************************************************
* ORGANIZATION : Pi4J
* PROJECT : Pi4J :: Device Abstractions
* FILENAME : ComponentBase.java
*
* This file is part of the Pi4J project. More information about
* this project can be found here: http://www.pi4j.com/
* **********************************************************************
* %%
* Copyright (C) 2012 - 2013 Pi4J
* %%
* 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.
* #L%
*/
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public abstract class ComponentBase implements Component {
private String name = null;
private Object tag = null;
private final Map<String, String> properties = new ConcurrentHashMap<String, String>();
@Override
public void setName(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
@Override
public void setTag(Object tag) {
this.tag = tag;
}
@Override
public Object getTag() {
return tag;
}
@Override
public void setProperty(String key, String value) {
properties.put(key, value);
}
@Override
public boolean hasProperty(String key) {
return properties.containsKey(key);
}
@Override
public String getProperty(String key, String defaultValue) {
if (properties.containsKey(key)) {
if(properties.get(key) == null || properties.get(key).isEmpty())
return defaultValue;
else
return properties.get(key);
}
return defaultValue;
}
@Override
public String getProperty(String key) {
return getProperty(key, null);
}
@Override
public Map<String, String> getProperties() {
return properties;
}
@Override
public void removeProperty(String key) {
if (properties.containsKey(key)) {
properties.remove(key);
}
}
@Override
public void clearProperties() {
properties.clear();
}
}