1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.codehaus.plexus.archiver.zip;
18
19 import java.util.ArrayDeque;
20 import java.util.Deque;
21 import java.util.HashSet;
22 import java.util.Set;
23 import java.util.Stack;
24
25
26
27
28 public class AddedDirs {
29
30 private final Set<String> addedDirs = new HashSet<String>();
31
32
33
34
35 @Deprecated
36 public Stack<String> asStringStack(String entry) {
37 Stack<String> directories = new Stack<>();
38
39
40
41 int slashPos = entry.length() - (entry.endsWith("/") ? 1 : 0);
42
43 while ((slashPos = entry.lastIndexOf('/', slashPos - 1)) != -1) {
44 String dir = entry.substring(0, slashPos + 1);
45
46 if (addedDirs.contains(dir)) {
47 break;
48 }
49
50 directories.push(dir);
51 }
52 return directories;
53 }
54
55 public Deque<String> asStringDeque(String entry) {
56 Deque<String> directories = new ArrayDeque<>();
57
58
59
60 int slashPos = entry.length() - (entry.endsWith("/") ? 1 : 0);
61
62 while ((slashPos = entry.lastIndexOf('/', slashPos - 1)) != -1) {
63 String dir = entry.substring(0, slashPos + 1);
64
65 if (addedDirs.contains(dir)) {
66 break;
67 }
68
69 directories.push(dir);
70 }
71 return directories;
72 }
73
74 public void clear() {
75 addedDirs.clear();
76 }
77
78
79
80
81
82
83
84
85 public boolean update(String vPath) {
86 return !addedDirs.add(vPath);
87 }
88
89 public Set<String> allAddedDirs() {
90 return new HashSet<String>(addedDirs);
91 }
92 }