public List<SelectorConfig> toConfig(final Map<String, SelectorGroupXBean> groups) { validate(); final List<SelectorConfig> result = new ArrayList<SelectorConfig>(selectors.size()); for (final SimpleSelectorXBean item : getAllSelectors(groups)) { result.add(item.toConfig()); } return result; }
private Map<String, List<SelectorConfig>> configureSelectorGroups(final List<SelectorGroupXBean> items) { final Map<String, SelectorGroupXBean> groups = new HashMap<>(items != null ? items.size() : 0); if (items != null) { for (final SelectorGroupXBean item : items) { if (groups.containsKey(item.getName())) { throw new ConfigurationException("Two selector groups with the same name \"" + item.getName() + "\""); } groups.put(item.getName(), item); } } final Map<String, List<SelectorConfig>> result = new HashMap<>(); for (final SelectorGroupXBean item : groups.values()) { result.put(item.getName(), item.toConfig(groups)); } return result; }
private List<SimpleSelectorXBean> getAllSelectors(final Map<String, SelectorGroupXBean> groups) { if (beingResolved) { throw new ConfigurationException("Selector group \"" + getName() + "\" is part of a dependency cycle"); } if (resolvedSimpleSelectors == null) { beingResolved = true; resolvedSimpleSelectors = new LinkedList<SimpleSelectorXBean>(); for (final SelectorXBean child : selectors) { if (child instanceof SelectorGroupRefXBean) { final String name = ((SelectorGroupRefXBean) child).getName(); final SelectorGroupXBean referencedGroup = groups.get(name); if (referencedGroup != null) { resolvedSimpleSelectors.addAll(referencedGroup.getAllSelectors(groups)); } else { throw new ConfigurationException("Could not find referenced selector group named \"" + name + "\""); } } else if (child instanceof SimpleSelectorXBean) { resolvedSimpleSelectors.add((SimpleSelectorXBean) child); } else { throw new ConfigurationException("Unsupported selector "+child); } } beingResolved = false; return resolvedSimpleSelectors; } else { // we do not really want to compute that multiple times return resolvedSimpleSelectors; } } }
private List<SimpleSelectorXBean> getAllSelectors(final Map<String, SelectorGroupXBean> groups) { if (beingResolved) { throw new ConfigurationException("Selector group \"" + getName() + "\" is part of a dependency cycle"); } if (resolvedSimpleSelectors == null) { beingResolved = true; resolvedSimpleSelectors = new LinkedList<SimpleSelectorXBean>(); for (final SelectorXBean child : selectors) { if (child instanceof SelectorGroupRefXBean) { final String name = ((SelectorGroupRefXBean) child).getName(); final SelectorGroupXBean referencedGroup = groups.get(name); if (referencedGroup != null) { resolvedSimpleSelectors.addAll(referencedGroup.getAllSelectors(groups)); } else { throw new ConfigurationException("Could not find referenced selector group named \"" + name + "\""); } } else if (child instanceof SimpleSelectorXBean) { resolvedSimpleSelectors.add((SimpleSelectorXBean) child); } else { throw new ConfigurationException("Unsupported selector "+child); } } beingResolved = false; return resolvedSimpleSelectors; } else { // we do not really want to compute that multiple times return resolvedSimpleSelectors; } } }
public List<SelectorConfig> toConfig(final Map<String, SelectorGroupXBean> groups) { validate(); final List<SelectorConfig> result = new ArrayList<SelectorConfig>(selectors.size()); for (final SimpleSelectorXBean item : getAllSelectors(groups)) { result.add(item.toConfig()); } return result; }
private Map<String, List<SelectorConfig>> configureSelectorGroups(final List<SelectorGroupXBean> items) { final Map<String, SelectorGroupXBean> groups = new HashMap<>(items != null ? items.size() : 0); if (items != null) { for (final SelectorGroupXBean item : items) { if (groups.containsKey(item.getName())) { throw new ConfigurationException("Two selector groups with the same name \"" + item.getName() + "\""); } groups.put(item.getName(), item); } } final Map<String, List<SelectorConfig>> result = new HashMap<>(); for (final SelectorGroupXBean item : groups.values()) { result.put(item.getName(), item.toConfig(groups)); } return result; }