
de.mhus.lib.core.MProperties Maven / Gradle / Ivy
package de.mhus.lib.core;
import java.io.Externalizable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import de.mhus.lib.core.logging.MLogUtil;
import de.mhus.lib.core.util.SetCast;
/**
* MProperties class.
*
* @author mikehummel
* @version $Id: $Id
*/
public class MProperties extends IProperties implements Externalizable {
protected Properties properties = null;
/**
* Constructor for MProperties.
*/
public MProperties() {
this(new Properties());
}
/**
* Constructor for MProperties.
*
* @param values a {@link java.lang.String} object.
*/
public MProperties(String ... values) {
this(new Properties());
if (values != null) {
for (int i = 0; i < values.length; i+=2) {
if (i+1 < values.length)
setString(values[i], values[i+1]);
}
}
}
/**
* Constructor for MProperties.
*
* @param config a {@link java.util.Dictionary} object.
*/
public MProperties(Dictionary, ?> config) {
this.properties = new Properties();
for (Enumeration> enu = config.keys(); enu.hasMoreElements();) {
Object next = enu.nextElement();
this.properties.put(String.valueOf( next ), config.get(next));
}
}
/**
* Constructor for MProperties.
*
* @param in a {@link java.util.Map} object.
*/
public MProperties(Map, ?> in) {
this.properties = new Properties();
for (Map.Entry, ?> e : in.entrySet())
if (e.getKey() != null && e.getValue() != null)
this.properties.put(String.valueOf( e.getKey() ), e.getValue());
}
/**
* Constructor for MProperties.
*
* @param properties a {@link java.util.Properties} object.
*/
public MProperties(Properties properties) {
this.properties = properties;
}
/** {@inheritDoc} */
@Override
public Object getProperty(String name) {
return properties.get(name);
}
/** {@inheritDoc} */
@Override
public boolean isProperty(String name) {
return properties.containsKey(name);
}
/** {@inheritDoc} */
@Override
public void removeProperty(String key) {
properties.remove(key);
}
/** {@inheritDoc} */
@Override
public void setProperty(String key, Object value) {
if (value == null)
properties.remove(key);
else
properties.put(key, value );
}
/** {@inheritDoc} */
@Override
public boolean isEditable() {
return true;
}
/** {@inheritDoc} */
@Override
public Set keys() {
return new SetCast
© 2015 - 2025 Weber Informatics LLC | Privacy Policy