|
16 | 16 | */ |
17 | 17 | package org.codehaus.plexus.archiver.zip; |
18 | 18 |
|
| 19 | +import java.util.ArrayDeque; |
| 20 | +import java.util.Deque; |
19 | 21 | import java.util.HashSet; |
20 | | -import java.util.Hashtable; |
21 | 22 | import java.util.Set; |
22 | 23 | import java.util.Stack; |
23 | 24 |
|
|
27 | 28 | public class AddedDirs |
28 | 29 | { |
29 | 30 |
|
30 | | - private final Hashtable<String, String> addedDirs = new Hashtable<String, String>(); |
| 31 | + private final Set<String> addedDirs = new HashSet<String>(); |
31 | 32 |
|
| 33 | + /** |
| 34 | + * @deprecated use {@link #asStringDeque(String)} instead. |
| 35 | + */ |
| 36 | + @Deprecated |
32 | 37 | public Stack<String> asStringStack( String entry ) |
33 | 38 | { |
34 | | - Stack<String> directories = new Stack<String>(); |
| 39 | + Stack<String> directories = new Stack<>(); |
| 40 | + |
| 41 | + // Don't include the last entry itself if it's |
| 42 | + // a dir; it will be added on its own. |
| 43 | + int slashPos = entry.length() - ( entry.endsWith( "/" ) ? 1 : 0 ); |
| 44 | + |
| 45 | + while ( ( slashPos = entry.lastIndexOf( '/', slashPos - 1 ) ) != -1 ) |
| 46 | + { |
| 47 | + String dir = entry.substring( 0, slashPos + 1 ); |
| 48 | + |
| 49 | + if ( addedDirs.contains( dir ) ) |
| 50 | + { |
| 51 | + break; |
| 52 | + } |
| 53 | + |
| 54 | + directories.push( dir ); |
| 55 | + } |
| 56 | + return directories; |
| 57 | + } |
| 58 | + |
| 59 | + public Deque<String> asStringDeque( String entry ) |
| 60 | + { |
| 61 | + Deque<String> directories = new ArrayDeque<>(); |
35 | 62 |
|
36 | 63 | // Don't include the last entry itself if it's |
37 | 64 | // a dir; it will be added on its own. |
@@ -65,19 +92,12 @@ public void clear() |
65 | 92 | */ |
66 | 93 | public boolean update( String vPath ) |
67 | 94 | { |
68 | | - if ( addedDirs.get( vPath ) != null ) |
69 | | - { |
70 | | - // don't add directories we've already added. |
71 | | - // no warning if we try, it is harmless in and of itself |
72 | | - return true; |
73 | | - } |
74 | | - addedDirs.put( vPath, vPath ); |
75 | | - return false; |
| 95 | + return !addedDirs.add( vPath ); |
76 | 96 | } |
77 | 97 |
|
78 | 98 | public Set<String> allAddedDirs() |
79 | 99 | { |
80 | | - return new HashSet<String>( addedDirs.keySet() ); |
| 100 | + return new HashSet<String>( addedDirs ); |
81 | 101 | } |
82 | 102 |
|
83 | 103 | } |
0 commit comments