DFS java pathfinding problems
<p>I'm developing a search algorithm for finding paths in a graph. In this algorithm i need to find all the paths in an undirected, not weighted graph that go trough each graph connection only once. 
Currently, what my prgoram is doing, is finding all the paths that go trough each node only once. I need connections and not nodes.</p>

<p>Here is my code:</p>

<pre><code>import java.util.*;

public class dfs {

    private static Map&lt;Integer, LinkedHashSet&lt;Integer&gt;&gt; map = new HashMap&lt;Integer, LinkedHashSet&lt;Integer&gt;&gt;();
    private int startNode;
    private int numLinks;

    public dfs(int startNode, int numLinks) {
        super();
        this.startNode = startNode;
        this.numLinks = numLinks;
    }

    public int getNumLinks(){
        return numLinks;    
    }

    public void addEdge(int source, int destiny) {
        LinkedHashSet&lt;Integer&gt; adjacente = map.get(source);
        if(adjacente==null) {
            adjacente = new LinkedHashSet&lt;Integer&gt;();
            map.put(source, adjacente);
        }
        adjacente.add(destiny);
    }

    public void addLink(int source, int destiny) {
        addEdge(source, destiny);
        addEdge(destiny, source);
    }

    public LinkedList&lt;Integer&gt; adjacentNodes(int adj) {
        LinkedHashSet&lt;Integer&gt; adjacente = map.get(adj);
        System.out.println("adjacentes:" + adjacente);
        if(adjacente==null) {
            return new LinkedList&lt;Integer&gt;();
        }
        return new LinkedList&lt;Integer&gt;(adjacente);
    }


public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    int numVertices = input.nextInt();
    int numLinks = input.nextInt();
    int startNode = input.nextInt();
    int endNode = startNode;

    dfs mapa = new dfs(startNode, numLinks);

    for(int i = 0; i&lt;numLinks; i++){
        mapa.addLink(input.nextInt(), input.nextInt());
    }

    List&lt;ArrayList&lt;Integer&gt;&gt; paths = new ArrayList&lt;ArrayList&lt;Integer&gt;&gt;();
    List&lt;Integer&gt; visited = new ArrayList&lt;Integer&gt;();
    visited.add(startNode);
    Integer currentNode = 0;

    Iterator it = map.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pairs = (Map.Entry)it.next();
        currentNode = (Integer) pairs.getKey(); 

        mapa.findAllPaths(mapa, visited, paths, currentNode);
    }
}

private void findAllPaths(dfs mapa, List&lt;Integer&gt; visited,
        List&lt;ArrayList&lt;Integer&gt;&gt; paths, Integer currentNode) {

    if (currentNode.equals(startNode)) { 
        paths.add(new ArrayList&lt;Integer&gt;(visited));

        LinkedList&lt;Integer&gt; nodes = mapa.adjacentNodes(currentNode); 

        for (Integer node : nodes) {
            List&lt;Integer&gt; temp = new ArrayList&lt;Integer&gt;();
            temp.addAll(visited);
            temp.add(node);  
            System.out.println("temp:" + temp);

            findAllPaths(mapa, temp, paths, node);
        }   
    }
    else {
        LinkedList&lt;Integer&gt; nodes = mapa.adjacentNodes(currentNode);  
        System.out.println("currentNode:" + currentNode);

        List&lt;Integer&gt; inseridos = new ArrayList&lt;Integer&gt;();

        for (Integer node : nodes) {   
            if (visited.contains(node)) {
                continue;
            } 
            List&lt;Integer&gt; temp = new ArrayList&lt;Integer&gt;();
            inseridos.add(currentNode);
            temp.addAll(visited);
            System.out.println("visited:" + visited);

            temp.add(node);

            findAllPaths(mapa, temp, paths, node);
        }
    }
} 
}
</code></pre>

<p>Right now, i think the following code:</p>

<pre><code>if (visited.contains(node)) {
   continue;
 }
</code></pre>

<p>is making that the program not going through each node more than once. 
I need helping transforming my program to go trough each connection only once, and not through each node only once.</p>

<p>(I'm sorry about my english, i'm not a native) </p>
