@Override protected final List<Pattern> flat(final Class<?>... types) { if (in(getClass(), types)) { return list((Pattern) this); } // >>> return sum([child.flat(*types) for child in self.children], []) { final List<Pattern> result = list(); for (final Pattern child : children) { result.addAll(child.flat(types)); } return result; } }
@Override protected final List<Pattern> flat(final Class<?>... types) { if (in(getClass(), types)) { return list((Pattern) this); } // >>> return sum([child.flat(*types) for child in self.children], []) { final List<Pattern> result = list(); for (final Pattern child : children) { result.addAll(child.flat(types)); } return result; } }
/** * Make pattern-tree tips point to same object if they are equal. */ private void fixIdentities(List<Pattern> uniq) { // >>> if not hasattr(self, 'children') if (!(this instanceof BranchPattern)) { return; } if (uniq == null) { uniq = list(set(flat())); } final List<Pattern> children = ((BranchPattern) this).getChildren(); for (int i = 0; i < children.size(); i++) { final Pattern child = children.get(i); if (!(child instanceof BranchPattern)) { assert uniq.contains(child); children.set(i, uniq.get(uniq.indexOf(child))); } else { child.fixIdentities(uniq); } } }
/** * Make pattern-tree tips point to same object if they are equal. */ private void fixIdentities(List<Pattern> uniq) { // >>> if not hasattr(self, 'children') if (!(this instanceof BranchPattern)) { return; } if (uniq == null) { uniq = list(set(flat())); } final List<Pattern> children = ((BranchPattern) this).getChildren(); for (int i = 0; i < children.size(); i++) { final Pattern child = children.get(i); if (!(child instanceof BranchPattern)) { assert uniq.contains(child); children.set(i, uniq.get(uniq.indexOf(child))); } else { child.fixIdentities(uniq); } } }