| 16 | protected ArrayList<URI> forward = new ArrayList<>(); |
| 17 | |
| 18 | public void add(URI uri) { |
| 19 | if (current == null) { |
| 20 | // Init history |
| 21 | forward.clear(); |
| 22 | current = uri; |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | if (current.equals(uri)) { |
| 27 | // Already stored -> Nothing to do |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | if (uri.getPath().toString().equals(current.getPath().toString())) { |
| 32 | if ((uri.getFragment() == null) && (uri.getQuery() == null)) { |
| 33 | // Ignore |
| 34 | } else if ((current.getFragment() == null) && (current.getQuery() == null)) { |
| 35 | // Replace current URI |
| 36 | current = uri; |
| 37 | } else { |
| 38 | // Store URI |
| 39 | forward.clear(); |
| 40 | backward.add(current); |
| 41 | current = uri; |
| 42 | } |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | if (uri.toString().startsWith(current.toString())) { |
| 47 | // Replace current URI |
| 48 | current = uri; |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | if (current.toString().startsWith(uri.toString())) { |
| 53 | // Parent URI -> Nothing to do |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | // Store URI |
| 58 | forward.clear(); |
| 59 | backward.add(current); |
| 60 | current = uri; |
| 61 | } |
| 62 | |
| 63 | public URI backward() { |
| 64 | if (! backward.isEmpty()) { |