public class FilePath extends java.lang.Object implements Copyable
FilePath
represents a path that is made
up entire of File
s. Use of FilePath
should be
limited to classes or tools that absolutely require that
the path (whether class path, source path, doc path, etc.) operate
only on resources that are accessible through the local machine's
file system (e.g. physically local files, NFS-mounted files, files
mounted via virtual file systems, etc.).
In order to support functionality that is available through the
URLFileSystem
, developers should give preference to using
URLPath
instead of FilePath
whenever possible,
since code written using FilePath
will not interoperate
with the variety of URL protocols that are integrated now and in
the future.
Constructor and Description |
---|
FilePath()
Creates a
FilePath that is initially empty. |
FilePath(java.io.File entry)
Creates a
FilePath that initially contains the
specified File as its sole entry. |
FilePath(java.io.File[] entries)
Creates a
FilePath initialized with the specified
array of File objects. |
FilePath(FilePath filePath)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addEntries(java.io.File[] entries)
Adds the given
File objects in order to the end of the
FilePath . |
void |
addEntries(FilePath filePath)
Adds the entries from the specified
FilePath to this
instance. |
void |
addEntry(java.io.File entry)
Adds the given
File to the end of the FilePath ,
if it is not already on the FilePath . |
java.lang.Object |
copyTo(java.lang.Object object)
Copies the internal state of
this object to the
specified copy . |
protected void |
copyToImpl(FilePath copy)
Design pattern for supporting strongly typed copying.
|
boolean |
equals(java.lang.Object o) |
protected boolean |
equalsImpl(FilePath filePath)
This is a helper method for
equals(Object) that can
also be used by subclasses that implement equals(Object) . |
java.io.File[] |
getEntries()
Returns the path represented by this
FilePath
instance as an array of File s. |
protected java.util.List |
getEntriesListDirectly()
This accessor is intended to support subclass extension of
FilePath behavior by providing direct access to the
List used to hold the FilePath data. |
static FilePath |
newFilePathFromString(java.lang.String entries)
Factory method that creates a new
FilePath from
a String representing the path entries. |
void |
setEntries(java.io.File[] entries)
Sets the path represented by this
FilePath instance
to be equivalent to the specified array of File s. |
java.lang.String |
toString() |
URLPath |
toURLPath()
Produces an
URLPath that represents a path that is
equivalent to this FilePath . |
public FilePath()
FilePath
that is initially empty.public FilePath(java.io.File entry)
FilePath
that initially contains the
specified File
as its sole entry. If the entry is
null
, then the FilePath
created
is initially empty.public FilePath(java.io.File[] entries)
FilePath
initialized with the specified
array of File
objects. If the entries
array is null
or empty, then the
FilePath
created is initially empty.public FilePath(FilePath filePath)
public java.lang.Object copyTo(java.lang.Object object)
Copyable
this
object to the
specified copy
. If copy
is
null
, then this method should create a new instance
of this
class and proceed to copy the internal state
to the newly created object. Generally, only the persistent
state of the object should be copied, but whether or not it is
appropriate to copy transient properties is at the discretion
of the individual implementor.
Regardless of whether the copy occurs to an existing object or to
a newly created object, the return value is object to which
this
object's state was copied.
There is a standard implementation pattern for the
copyTo
method that helps avoid problems that arise
when a Copyable
object is subclassed. The pattern
is:
The parameter passed into thepublic Object copyTo( Object target ) { final <this_class> copy = target != null ? (<this_class>) target : new <this_class>(); copyToImpl( copy ); return copy; } protected final void copyToImpl( <this_class> copy ) { super.copyToImpl( copy ); // if necessary // put code here for copying the properties of <this_class> }
copyToImpl
method is
the same type of this
class. The responsibility of
copyToImpl
is to copy the state of this
class through direct access of the fields. The
copyToImpl
method should not use getters and setters
since these may be overridden, causing the state of
this
class to be incompletely copied.copyTo
in interface Copyable
object
- The target object to which the state of
this
object should be copied. If target
is null
, then the copyTo
method will
return a new instance of this
class.this
object was copied. If the target
was
non-null
, then the return value is the same as the
target
object that was passed in; otherwise, the
return value is a new instance of this
class.protected final void copyToImpl(FilePath copy)
public java.io.File[] getEntries()
FilePath
instance as an array of File
s. If the
FilePath
is empty, then then this method returns a
File
array of size 0.public void setEntries(java.io.File[] entries)
FilePath
instance
to be equivalent to the specified array of File
s. If the
argument is null
, then the FilePath
is
cleared; subsequent calls to getEntries()
would then
return an empty File
array.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
protected final boolean equalsImpl(FilePath filePath)
equals(Object)
that can
also be used by subclasses that implement equals(Object)
.
It assumes that the argument is not null
.public java.lang.String toString()
toString
in class java.lang.Object
public void addEntry(java.io.File entry)
File
to the end of the FilePath
,
if it is not already on the FilePath
. If the
parameter is null
, then this method returns without
doing anything.public void addEntries(java.io.File[] entries)
File
objects in order to the end of the
FilePath
. Each File
is added only if it is
not already on the FilePath
. Any null
entries are ignored. If the entries
array itself
is null, then this method returns without doing anything.public void addEntries(FilePath filePath)
FilePath
to this
instance.public URLPath toURLPath()
URLPath
that represents a path that is
equivalent to this FilePath
.public static FilePath newFilePathFromString(java.lang.String entries)
FilePath
from
a String
representing the path entries. The specified
entries
must use File.pathSeparator
to
separate path elements and File.separator
within
each path element. That is, the specified entries
should be expressed in the platform-specific notation of the
current Java VM.protected final java.util.List getEntriesListDirectly()
FilePath
behavior by providing direct access to the
List
used to hold the FilePath
data.