|
|
@@ -371,6 +371,33 @@ public class Config { |
|
|
|
return get(new SubsectionNames(section)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @return the sections defined in this {@link Config} |
|
|
|
*/ |
|
|
|
public Set<String> getSections() { |
|
|
|
return get(new SectionNames()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param section |
|
|
|
* the section |
|
|
|
* @return the list of names defined for this section |
|
|
|
*/ |
|
|
|
public Set<String> getNames(String section) { |
|
|
|
return getNames(section, null); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param section |
|
|
|
* the section |
|
|
|
* @param subsection |
|
|
|
* the subsection |
|
|
|
* @return the list of names defined for this subsection |
|
|
|
*/ |
|
|
|
public Set<String> getNames(String section, String subsection) { |
|
|
|
return get(new NamesInSection(section, subsection)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Obtain a handle to a parsed set of configuration values. |
|
|
|
* |
|
|
@@ -1077,6 +1104,80 @@ public class Config { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static class NamesInSection implements SectionParser<Set<String>> { |
|
|
|
private final String section; |
|
|
|
|
|
|
|
private final String subsection; |
|
|
|
|
|
|
|
NamesInSection(final String sectionName, final String subSectionName) { |
|
|
|
section = sectionName; |
|
|
|
subsection = subSectionName; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public int hashCode() { |
|
|
|
final int prime = 31; |
|
|
|
int result = 1; |
|
|
|
result = prime * result + section.hashCode(); |
|
|
|
result = prime * result |
|
|
|
+ ((subsection == null) ? 0 : subsection.hashCode()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean equals(Object obj) { |
|
|
|
if (this == obj) |
|
|
|
return true; |
|
|
|
if (obj == null) |
|
|
|
return false; |
|
|
|
if (getClass() != obj.getClass()) |
|
|
|
return false; |
|
|
|
NamesInSection other = (NamesInSection) obj; |
|
|
|
if (!section.equals(other.section)) |
|
|
|
return false; |
|
|
|
if (subsection == null) { |
|
|
|
if (other.subsection != null) |
|
|
|
return false; |
|
|
|
} else if (!subsection.equals(other.subsection)) |
|
|
|
return false; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
public Set<String> parse(Config cfg) { |
|
|
|
final Set<String> result = new HashSet<String>(); |
|
|
|
while (cfg != null) { |
|
|
|
for (final Entry e : cfg.state.get().entryList) { |
|
|
|
if (e.name != null |
|
|
|
&& StringUtils.equalsIgnoreCase(e.section, section)) { |
|
|
|
if (subsection == null && e.subsection == null) |
|
|
|
result.add(StringUtils.toLowerCase(e.name)); |
|
|
|
else if (e.subsection != null |
|
|
|
&& e.subsection.equals(subsection)) |
|
|
|
result.add(StringUtils.toLowerCase(e.name)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
cfg = cfg.baseConfig; |
|
|
|
} |
|
|
|
return Collections.unmodifiableSet(result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static class SectionNames implements SectionParser<Set<String>> { |
|
|
|
public Set<String> parse(Config cfg) { |
|
|
|
final Set<String> result = new HashSet<String>(); |
|
|
|
while (cfg != null) { |
|
|
|
for (final Entry e : cfg.state.get().entryList) { |
|
|
|
if (e.section != null) |
|
|
|
result.add(StringUtils.toLowerCase(e.section)); |
|
|
|
} |
|
|
|
cfg = cfg.baseConfig; |
|
|
|
} |
|
|
|
return Collections.unmodifiableSet(result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static class State { |
|
|
|
final List<Entry> entryList; |
|
|
|
|