com.firenio.baseio.collection.MapParameters Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of baseio-all Show documentation
Show all versions of baseio-all Show documentation
The all in one project of baseio
/*
* Copyright 2015 The Baseio Project
*
* 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 com.firenio.baseio.collection;
import java.util.HashMap;
import java.util.Map;
import com.firenio.baseio.common.Util;
public class MapParameters implements Parameters {
private Map map;
public MapParameters() {
this(new HashMap());
}
public MapParameters(Map object) {
this.map = object;
}
@Override
public boolean getBooleanParameter(String key) {
if (map == null) {
return false;
}
return (boolean) map.get(key);
}
@Override
public int getIntegerParameter(String key) {
return getIntegerParameter(key, 0);
}
@Override
public int getIntegerParameter(String key, int defaultValue) {
if (map == null) {
return defaultValue;
}
Integer value = (Integer) map.get(key);
if (value == null) {
return defaultValue;
}
return value;
}
@Override
public long getLongParameter(String key) {
return getLongParameter(key, 0);
}
@Override
public long getLongParameter(String key, long defaultValue) {
if (map == null) {
return defaultValue;
}
Long value = (Long) map.get(key);
if (value == null) {
return defaultValue;
}
return value;
}
@Override
public Map getMap() {
return map;
}
@Override
public Object getObjectParameter(String key) {
if (map == null) {
return null;
}
return map.get(key);
}
@Override
public String getParameter(String key) {
return getParameter(key, null);
}
@Override
public String getParameter(String key, String defaultValue) {
if (map == null) {
return defaultValue;
}
String value = (String) map.get(key);
if (Util.isNullOrBlank(value)) {
return defaultValue;
}
return value;
}
@Override
public void put(String key, Object value) {
map.put(key, value);
}
@Override
public void putAll(Map params) {
map.putAll(params);
}
@Override
public int size() {
return map.size();
}
}