ecology_maven/aiyh/utils/fileUtil/ProperUtil.java

56 lines
1.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package aiyh.utils.fileUtil;
import java.util.*;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/29 0029 13:53
*/
public class ProperUtil extends Properties {
//LinkedHashSet有序可以保证读取出来顺序不变
private final LinkedHashSet<Object> keys = new LinkedHashSet<>();
/**
* 读取key集合
*/
@Override
public Set<String> stringPropertyNames() {
Set<String> set = new LinkedHashSet<>();
for (Object key : keys) {
set.add((String) key);
}
return set;
}
@Override
public Set<Object> keySet() {
return keys;
}
/**
* 枚举可以直接进行遍历但是和iterator一样遍历过程中不能进行修改删除等操作
* 若要在遍历过程中进行修改擦除等操作建议使用stringPropertyNames方法
*/
@Override
public synchronized Enumeration<Object> keys() {
return Collections.enumeration(keys);
}
@Override
public synchronized Object put(Object key, Object value) {
keys.add(key);
return super.put(key, value);
}
/**
* 若要移除元素要重写remove方法
*/
@Override
public Object remove(Object o) {
keys.remove(o);
return super.remove(o);
}
}