// --------------------------------------------------------------------------- private void addRule(String key, Rule rule) throws TablesawException { Debug.print("Adding rule for " + key); Rule old = m_targetRuleMap.put(key, rule); if ((old != null) && (!rule.getOverride()) && (!(old instanceof Overridable))) throw new TablesawException( "Duplicate rules for " + key + " rule1: " + old + " rule2: " + rule, 1); }
/** * This fills in the m_targetRuleMap. The keys are the names of the rules and the targets they * produce */ private void resolveRules() throws TablesawException { for (Rule rule : m_ruleList) { // Add rule by name if it has one String name = rule.getName(); if (name != null) { Debug.print("Adding rule name: " + name); Rule namedRule = m_nameRuleMap.get(name); if (namedRule == null) { m_nameRuleMap.put(name, rule); } /*else if (namedRule instanceof CompoundNameRule) { ((CompoundNameRule)namedRule).addDepends(rule); }*/ else if ((namedRule instanceof Overridable) || (rule.getOverride())) { m_nameRuleMap.put(name, rule); } else { throw new TablesawException( "Multiple rules exist for '" + name + "'. Call Rule.override() if you wish to override an existing rule."); /*System.out.println("GGGGGGGGGGGGGGGGGGGAAAAAAAAAAAAAHHHHHHHHHHH"); CompoundNameRule cnr = new CompoundNameRule(name); cnr.addDepends(namedRule); cnr.addDepends(rule); m_nameRuleMap.put(name, cnr);*/ } } // Add rule by each target it declares Iterable<String> targets = rule.getTargets(); for (String t : targets) { Debug.print("Add target " + t); addRule(t, rule); } } m_resolved = true; }