org.qedeq.base.io
Class Path

java.lang.Object
  extended by org.qedeq.base.io.Path

public final class Path
extends java.lang.Object

A file path that leads to a directory or file and is absolute or relative. This abstraction of a file location was done to create relative file paths. This class makes some assumptions about a file path: "/" is the directory separator, "/" is also the root directory and ".." specifies the parent directory. "." is the current directory. A directory path must end with a "/" if a path ends not with a "/" it will be a file path (but the empty path "" is a directory).

Author:
Michael Meyling

Constructor Summary
Path(java.lang.String filePath)
          Create file with given path and name.
Path(java.lang.String[] dirNames, java.lang.String fileName)
          Create file with given path and name.
Path(java.lang.String dirPath, java.lang.String fileName)
          Create file with given path and name.
 
Method Summary
 Path createRelative(java.lang.String filePath)
          Create new file path relative to given one.
 boolean equals(java.lang.Object obj)
           
 java.lang.String getDirectory()
          Get directory of this path.
 java.lang.String getFileName()
          Get filename.
 int hashCode()
           
 boolean isAbsolute()
          Is this an absolute path? If first path directory name is empty or ends with ":" (MS windows tribute) this is the case.
 boolean isDirectory()
          Describes this path a directory?
 boolean isFile()
          Describes this path a file (and not a directory)?
 boolean isRelative()
          Is this a relative path?
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Path

public Path(java.lang.String filePath)
Create file with given path and name.

Parameters:
filePath - Path to file with "/" as directory name separator. Relative directories are removed from the file path if possible. Must not be null. Might be "" this is called the empty path.

Path

public Path(java.lang.String dirPath,
            java.lang.String fileName)
Create file with given path and name. Relative directories are removed from the file path if possible.

Parameters:
dirPath - Directory path to file with "/" as directory name separator. This value can end with a "/" but it must not be null.
fileName - File name. It should not contain "/" but this is not checked.

Path

public Path(java.lang.String[] dirNames,
            java.lang.String fileName)
Create file with given path and name. Relative directories are removed from the file path if possible.

Parameters:
dirNames - Directory names. If this is an absolute path the first name is empty. Must not be null.
fileName - File name. It should not contain "/" but this is not checked.
Method Detail

createRelative

public Path createRelative(java.lang.String filePath)
Create new file path relative to given one. If the original path or filePath is a relative path it will return filePath.

Parameters:
filePath - Path to file relative to this.
Returns:
Relative file path (if possible).

isDirectory

public boolean isDirectory()
Describes this path a directory?

Returns:
Is directory?

isFile

public boolean isFile()
Describes this path a file (and not a directory)?

Returns:
Is this a path to a file?

isAbsolute

public boolean isAbsolute()
Is this an absolute path? If first path directory name is empty or ends with ":" (MS windows tribute) this is the case.

Returns:
Is absolute path?

isRelative

public boolean isRelative()
Is this a relative path?

Returns:
Is this a relative path?

getFileName

public java.lang.String getFileName()
Get filename. Is "" if this is a pure directory path.

Returns:
File name. Might be "" but not null.

getDirectory

public java.lang.String getDirectory()
Get directory of this path. This might be a relative or absolute path and ends with "/". (Only the empty path "" has no ending "/".)

Returns:
Directory this path points to. Will end with "/" if this is not an empty path.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object


Copyright © 2014. All Rights Reserved.