me.lachlanap.config.values.ValuesContainer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of config Show documentation
Show all versions of config Show documentation
Configuration is a Java library to manage application configuration with
compiled-in defaults and externally overridable config files, in a
Properties-like manner.
The newest version!
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package me.lachlanap.config.values;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import me.lachlanap.config.ConfigurationKeyNotFoundException;
/**
*
* @author lachlan
*/
public class ValuesContainer {
private final Map values;
public ValuesContainer() {
values = new HashMap<>();
}
public Value getValue(String key) throws ConfigurationKeyNotFoundException {
Value v = values.get(key);
if (v == null)
throw new ConfigurationKeyNotFoundException(key + " is not present");
return v;
}
public String getString(String key) throws ConfigurationKeyNotFoundException {
return getValue(key).stringValue();
}
public int getInt(String key) throws ConfigurationKeyNotFoundException {
return getValue(key).intValue();
}
public void put(String key, String value) {
put(key, Value.from(value));
}
public void put(String key, int value) {
put(key, Value.from(value));
}
public void put(String key, Value value) {
Value original = values.get(key);
if (original == null) {
values.put(key, value);
} else {
original.override(value);
}
}
public void reset(String key) {
getValue(key).reset();
}
public int getNumberOfKeys() {
return values.size();
}
public void deleteAll() {
values.clear();
}
public ValuesContainer overriden() {
ValuesContainer overriden = new ValuesContainer();
for (String key : getKeys()) {
Value val = getValue(key);
if (val.isOverriden()) {
overriden.put(key, val);
}
}
return overriden;
}
public Set getKeys() {
return values.keySet();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy