
leap.lang.extension.ExProperties Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2014 the original author or authors.
*
* 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 leap.lang.extension;
import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import leap.lang.Props;
import leap.lang.Strings;
import leap.lang.accessor.PropertyGetter;
import leap.lang.beans.BeanProperty;
import leap.lang.beans.BeanType;
import leap.lang.convert.Converts;
import leap.lang.exception.NestedIOException;
import leap.lang.text.PlaceholderResolver;
public class ExProperties extends Properties implements PropertyGetter {
private static final long serialVersionUID = -7225067603324341854L;
/**
* Load a new {@link ExProperties} object from the given file.
*/
public static ExProperties load(File file) {
return Props.load(file);
}
/**
* Load a new {@link ExProperties} object from the given file.
*/
public static ExProperties load(File file,Properties defaults) {
return Props.load(file);
}
/**
* Creates a new {@link ExProperties} and put all the given {@link Map} properties as defaults.
*/
public static ExProperties create(Map defaults){
ExProperties p = new ExProperties();
p.putAll(defaults);
return p;
}
/**
* Creates a new {@link ExProperties} that wrapped a {@link Properties} as default values.
*/
public static ExProperties create(Properties properties){
return new ExProperties(properties);
}
private File file;
public ExProperties() {
super();
}
public ExProperties(Properties defaults) {
super(defaults);
}
public ExProperties(File file){
this.file = file;
}
public ExProperties(File file,Properties defaults){
super(defaults);
this.file = file;
}
/**
* Returns the {@link File} stores this properties or null
if not load from file.
*/
public File getFile() {
return file;
}
public String removeProperty(String name) {
return (String)this.remove(name);
}
public boolean hasProperty(String name) {
return this.containsKey(name);
}
/**
* Converts this properties object to a {@link Map}.
*/
public Map toMap() {
Map map = new LinkedHashMap<>();
for(Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy