@@ -0,0 +1,2364 @@
+/*%0A * FindBugs - Find Bugs in Java programs%0A * Copyright (C) 2006, University of Maryland%0A * %0A * This library is free software; you can redistribute it and/or%0A * modify it under the terms of the GNU Lesser General Public%0A * License as published by the Free Software Foundation; either%0A * version 2.1 of the License, or (at your option) any later version.%0A * %0A * This library is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A * Lesser General Public License for more details.%0A * %0A * You should have received a copy of the GNU Lesser General Public%0A * License along with this library; if not, write to the Free Software%0A * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA%0A */%0A%0Apackage edu.umd.cs.findbugs.util;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.HashSet;%0Aimport java.util.List;%0A%0Aimport edu.umd.cs.findbugs.ba.AnalysisContext;%0Aimport edu.umd.cs.findbugs.ba.ch.Subtypes;%0Aimport edu.umd.cs.findbugs.classfile.CheckedAnalysisException;%0Aimport edu.umd.cs.findbugs.classfile.ClassDescriptor;%0Aimport edu.umd.cs.findbugs.classfile.Global;%0Aimport edu.umd.cs.findbugs.classfile.analysis.ClassInfo;%0A%0A/**%0A * @author pugh%0A */%0Apublic class TopologicalSort %7B%0A    %0A    public interface OutEdges%3CE%3E %7B%0A        Collection%3CE%3E getOutEdges(E e);%0A    %7D%0A    %0A    public static %3CE%3E List%3CE%3E sortByCallGraph(Collection%3CE%3E elements, OutEdges%3CE%3E outEdges) %7B%0A        List%3CE%3E result = new ArrayList%3CE%3E(elements.size());%0A        Foo%3CE%3E instance = new Foo%3CE%3E(result, outEdges);%0A        instance.consider.addAll(elements);%0A        for (E e : elements)%0A            instance.visit(e);%0A        return result;%0A    %7D%0A%0A    static class Foo%3CE%3E %7B%0A        Foo(List%3CE%3E result, OutEdges%3CE%3E outEdges) %7B%0A            this.result = result;%0A            this.outEdges = outEdges;%0A%0A        %7D%0A        OutEdges%3CE%3E outEdges;%0A        %0A        List%3CE%3E result;%0A%0A        HashSet%3CE%3E visited = new HashSet%3CE%3E();%0A        HashSet%3CE%3E consider = new HashSet%3CE%3E();%0A%0A        void visit(E e) %7B%0A            if (!consider.contains(e)) return;%0A            if (!visited.add(e))%0A                return;%0A             for(E e2  :outEdges.getOutEdges(e))%0A                visit(e2);%0A           %0A            result.add(e);%0A        %7D%0A    %7D%0A%0A%7D%0A

generalize topological sort