Add session to cache with both hostname and address.
[cyberduck.git] / source / ch / cyberduck / core / Navigation.java
blob24da2e470f5a54a270672068ee6794ca8bcd4836
1 package ch.cyberduck.core;
3 /*
4 * Copyright (c) 2013 David Kocher. All rights reserved.
5 * http://cyberduck.ch/
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to:
18 * dkocher@cyberduck.ch
21 import java.util.List;
23 /**
24 * @version $Id:$
26 public class Navigation {
28 /**
29 * Keeps a ordered backward history of previously visited paths
31 private List<Path> back = new Collection<Path>();
33 /**
34 * Keeps a ordered forward history of previously visited paths
36 private List<Path> forward = new Collection<Path>();
38 /**
39 * @param p Directory
41 public void add(final Path p) {
42 if(back.size() > 0) {
43 // Do not add if this was a reload
44 if(p.equals(back.get(back.size() - 1))) {
45 return;
48 back.add(p);
51 /**
52 * Returns the prevously browsed path and moves it to the forward history
54 * @return The previously browsed path or null if there is none
56 public Path back() {
57 int size = back.size();
58 if(size > 1) {
59 forward.add(back.get(size - 1));
60 Path p = back.get(size - 2);
61 //delete the fetched path - otherwise we produce a loop
62 back.remove(size - 1);
63 back.remove(size - 2);
64 return p;
66 else if(1 == size) {
67 forward.add(back.get(size - 1));
68 return back.get(size - 1);
70 return null;
73 /**
74 * @return The last path browsed before #back was called
75 * @see #back()
77 public Path forward() {
78 int size = forward.size();
79 if(size > 0) {
80 Path p = forward.get(size - 1);
81 forward.remove(size - 1);
82 return p;
84 return null;
87 /**
88 * @return The ordered array of previously visited directories
90 public List<Path> getBack() {
91 return back;
94 /**
95 * @return The ordered array of previously visited directories
97 public List<Path> getForward() {
98 return forward;
101 public void clear() {
102 back.clear();
103 forward.clear();