Subversion Repository Public Repository

litesoft

Diff Revisions 943 vs 959 for /trunk/Java/ScarPlus/src/com/esotericsoftware/filesystem/FilePath.java

Diff revisions: vs.
  @@ -4,109 +4,89 @@
4 4
5 5 import java.io.*;
6 6
7 - public final class FilePath
8 - {
7 + public final class FilePath {
9 8 private final File mSomeParentDir;
10 9 private final String mFileSubPath;
11 10 private final File mCanonicalPath;
12 11
13 - private FilePath( File pSomeParentDir, String pFileSubPath, File pCanonicalPath )
14 - {
12 + private FilePath( File pSomeParentDir, String pFileSubPath, File pCanonicalPath ) {
15 13 mSomeParentDir = pSomeParentDir;
16 14 mFileSubPath = pFileSubPath;
17 15 mCanonicalPath = pCanonicalPath;
18 16 }
19 17
20 - public FilePath( File pSomeParentDir, String pFileSubPath )
21 - {
18 + public FilePath( File pSomeParentDir, String pFileSubPath ) {
22 19 this( pSomeParentDir, pFileSubPath, Utils.canonical( new File( pSomeParentDir, pFileSubPath ) ) );
23 20 }
24 21
25 - public static FilePath canonical( File pSomeParentDir, String pFileSubPath )
26 - {
22 + public static FilePath canonical( File pSomeParentDir, String pFileSubPath ) {
27 23 return new FilePath( pSomeParentDir, pFileSubPath, new File( pSomeParentDir, pFileSubPath ) );
28 24 }
29 25
30 - private static FilePath innerAlreadyCanonical( File pFilePath )
31 - {
26 + private static FilePath innerAlreadyCanonical( File pFilePath ) {
32 27 return new FilePath( pFilePath.getParentFile(), pFilePath.getName(), pFilePath );
33 28 }
34 29
35 - public static FilePath canonicalize( File pFilePath )
36 - {
30 + public static FilePath canonicalize( File pFilePath ) {
37 31 return innerAlreadyCanonical( Utils.canonical( pFilePath ) );
38 32 }
39 33
40 - public File getSomeParentDir()
41 - {
34 + public File getSomeParentDir() {
42 35 return mSomeParentDir;
43 36 }
44 37
45 - public String getFileSubPath()
46 - {
38 + public String getFileSubPath() {
47 39 return mFileSubPath;
48 40 }
49 41
50 - public String canonical()
51 - {
42 + public String canonical() {
52 43 return mCanonicalPath.getPath();
53 44 }
54 45
55 - public File file()
56 - {
46 + public File file() {
57 47 return mCanonicalPath;
58 48 }
59 49
60 - public String relativeFromDir(File pCanonicalJarDir)
61 - {
62 - File zCommonDirPath = Utils.findCommonDirPathFromCanonicalDirPaths(pCanonicalJarDir, mCanonicalPath.getParentFile());
63 - if ( zCommonDirPath == null )
64 - {
50 + public String relativeFromDir( File pCanonicalJarDir ) {
51 + File zCommonDirPath = Utils.findCommonDirPathFromCanonicalDirPaths( pCanonicalJarDir, mCanonicalPath.getParentFile() );
52 + if ( zCommonDirPath == null ) {
65 53 throw new IllegalStateException( "Unable to create Relative path from '" + pCanonicalJarDir + "' to: " + this );
66 54 }
67 - String zJarDir = normalize(pCanonicalJarDir, zCommonDirPath);
68 - String zFilePath = normalize(mCanonicalPath, zCommonDirPath);
69 - while ( zJarDir.length() != 0 )
70 - {
55 + String zJarDir = normalize( pCanonicalJarDir, zCommonDirPath );
56 + String zFilePath = normalize( mCanonicalPath, zCommonDirPath );
57 + while ( zJarDir.length() != 0 ) {
71 58 zFilePath = "../" + zFilePath;
72 - int zAt = zJarDir.lastIndexOf("/");
73 - if ( zAt == -1 )
74 - {
59 + int zAt = zJarDir.lastIndexOf( "/" );
60 + if ( zAt == -1 ) {
75 61 zJarDir = "";
76 - }
77 - else
78 - {
79 - zJarDir = zJarDir.substring(0,zAt);
62 + } else {
63 + zJarDir = zJarDir.substring( 0, zAt );
80 64 }
81 65 }
82 66 return zFilePath;
83 67 }
84 68
85 - private String normalize(File pPath, File pCommonDirPath) {
86 - String zPath = pPath.getPath().substring(pCommonDirPath.getPath().length()).replace('\\', '/');
87 - return zPath.startsWith("/") ? zPath.substring(1) : zPath;
69 + private String normalize( File pPath, File pCommonDirPath ) {
70 + String zPath = pPath.getPath().substring( pCommonDirPath.getPath().length() ).replace( '\\', '/' );
71 + return zPath.startsWith( "/" ) ? zPath.substring( 1 ) : zPath;
88 72 }
89 73
90 - public boolean equals( FilePath them )
91 - {
74 + public boolean equals( FilePath them ) {
92 75 return this == them || ((them != null) && this.canonical().equals( them.canonical() ));
93 76 }
94 77
95 78 @Override
96 - public boolean equals( Object obj )
97 - {
79 + public boolean equals( Object obj ) {
98 80 return (this == obj) || ((obj instanceof FilePath) && equals( (FilePath) obj ));
99 81 }
100 82
101 83 @Override
102 - public int hashCode()
103 - {
84 + public int hashCode() {
104 85 return canonical().hashCode();
105 86 }
106 87
107 88 @Override
108 - public String toString()
109 - {
89 + public String toString() {
110 90 return canonical();
111 91 }
112 92 }