Subversion Repository Public Repository

litesoft

Diff Revisions 312 vs 313 for /trunk/Java/ScarPlus/src/com/esotericsoftware/filesystem/RootedPaths.java

Diff revisions: vs.
  @@ -3,26 +3,85 @@
3 3 import java.io.*;
4 4 import java.util.*;
5 5
6 - public class RootedPaths
6 + import com.esotericsoftware.scar.*;
7 +
8 + public final class RootedPaths
7 9 {
8 10 private long mGreatestLastModified;
9 11 private File mCanonicalRootDirectory;
10 - private Set<String> mCanonicalRelativePaths = new HashSet<String>( );
12 + private Set<String> mCanonicalRelativePaths = new HashSet<String>();
11 13
12 14 public RootedPaths( File pCanonicalRootDirectory )
13 15 {
14 - mCanonicalRootDirectory = pCanonicalRootDirectory;
16 + Utils.assertNotNull( "CanonicalRootDirectory", mCanonicalRootDirectory = pCanonicalRootDirectory );
15 17 }
16 18
17 - public static RootedPaths createForFile( File pCanonicalRootDirectory )
19 + public void addCanonicalRelativePath( String pPath )
18 20 {
19 - // mCanonicalRootDirectory = pCanonicalRootDirectory;
20 - return null; // todo...
21 + mGreatestLastModified = Math.max( mGreatestLastModified, new File( mCanonicalRootDirectory, pPath = Utils.assertNotEmpty( "Path", pPath ) ).lastModified() );
22 + addPathWithDupCheck( pPath );
21 23 }
22 24
23 - public void addCanonicalRelativePath( String pPath )
25 + public long getGreatestLastModified()
26 + {
27 + return mGreatestLastModified;
28 + }
29 +
30 + public File getCanonicalRootDirectory()
24 31 {
25 - mCanonicalRelativePaths.add( pPath );
32 + return mCanonicalRootDirectory;
33 + }
26 34
35 + public String[] getCanonicalRelativePaths()
36 + {
37 + return mCanonicalRelativePaths.toArray( new String[mCanonicalRelativePaths.size()] );
38 + }
39 +
40 + public int count()
41 + {
42 + return mCanonicalRelativePaths.size();
43 + }
44 +
45 + public void collectPaths( List<FilePath> pPaths )
46 + {
47 + for ( String zPath : mCanonicalRelativePaths )
48 + {
49 + pPaths.add( FilePath.canonical( mCanonicalRootDirectory, zPath ) );
50 + }
51 + }
52 +
53 + @Override
54 + public int hashCode()
55 + {
56 + return mCanonicalRootDirectory.hashCode();
57 + }
58 +
59 + public boolean equals( RootedPaths them )
60 + {
61 + return (them != null) && this.mCanonicalRootDirectory.equals( them.mCanonicalRootDirectory );
62 + }
63 +
64 + @Override
65 + public boolean equals( Object o )
66 + {
67 + return (o instanceof RootedPaths) && equals( (RootedPaths) o );
68 + }
69 +
70 + /* Package Friendly */
71 + void mergeIn( RootedPaths them ) // Assume only called by the RootedPathsCollection when the mCanonicalRootDirectory(s) are equal!
72 + {
73 + this.mGreatestLastModified = Math.max( this.mGreatestLastModified, them.mGreatestLastModified );
74 + for ( String zPath : them.getCanonicalRelativePaths() )
75 + {
76 + addPathWithDupCheck( zPath );
77 + }
78 + }
79 +
80 + private void addPathWithDupCheck( String zPath )
81 + {
82 + if ( !mCanonicalRelativePaths.add( zPath ) )
83 + {
84 + throw new IllegalArgumentException( "Duplicate Entry in (" + mCanonicalRootDirectory.getPath() + "): " + zPath );
85 + }
27 86 }
28 87 }