我有 2 个枚举(模块、UniqueChars)
模块有所有的钥匙
UniqueChars 具有所有值。
如何使用 HashMap 或 EnumMap 映射这些?
首先,是否可以从 2 个单独的枚举中读取键和值?
public enum modules {
MODULE("MTREE, VTL_POOL, VTL_ACCESS, SNAPSHOT, NFS_EXPORT, CIFS_SHARE, REPORTS, LOCAL_USERS ");
private String validModules;
private modules(String validModules) {
this.validModules= validModules;
}
}
public enum UniqueChars {
LOWER_CASE_LETTERS("abcdefghijklmnopqrstuvwxyz"),
UPPER_CASE_LETTERS("ABCDEFGHIJKLMNOPQRSTUVWXYZ"),
NUMBERS("0123456789"),
PUNCTUATION(".-_"),
MTREE("*/:<>?\\|"),
VTL_POOL("*'?:/\\,"),
VTL_ACCESS("*'?:/\\,"),
SNAPSHOT("`~!@#$%^&*()_+-={}|[]\\:\";'<>?,.'"),
NFS_EXPORT("_-"),
CIFS_SHARE("\\/:*?\"<>|+[];,="),
REPORTS("`~!@#$%^&*()_+-={}|[]\\:\";'<>?,.'"),
LOCAL_USERS("._-");
private String validChars;
private UniqueChars(String validChars) {
this.validChars = validChars;
}
public String getValidChars() {
return validChars;
}
public static String getValidCharStrings(UniqueChars... uniqueChars) {
StringBuilder validCharsSB = new StringBuilder();
for (UniqueChars chars : uniqueChars) {
validCharsSB.append(chars.getValidChars());
}
return validCharsSB.toString();
}
}