List<Namespace> () { if (getParentElement() == null) { // we introduce everything... except Namespace.XML_NAMESPACE List<Namespace> ret = new ArrayList<>(getNamespacesInScope()); ret.removeIf(ns -> ns == Namespace.XML_NAMESPACE || ns == Namespace.NO_NAMESPACE); return Collections.unmodifiableList(ret); } // OK, the things we introduce are the prefixes we have in scope that // are *not* in our parent's scope. HashMap<String, Namespace> parents = new HashMap<>(); for (Namespace ns : getParentElement().getNamespacesInScope()) { parents.put(ns.getPrefix(), ns); } ArrayList<Namespace> al = new ArrayList<>(); for (Namespace ns : getNamespacesInScope()) { if (!parents.containsKey(ns.getPrefix()) || ns != parents.get(ns.getPrefix())) { // introduced al.add(ns); } } return Collections.unmodifiableList(al); }