public final class DbxPath extends java.lang.Object implements java.lang.Comparable<DbxPath>
Dropbox paths always begin with a forward-slash, representing either the root of a user's Dropbox or the root of your app folder. Paths use forward-slashes to separate components. Mixed-case is allowed, but comparisons are case-insensitive.
Some special names, characters, or encodings aren't allowed in a Dropbox path, and will result in an InvalidPathException. Others are allowed, but may not sync properly to all platforms. For more details see this article.
Modifier and Type | Class and Description |
---|---|
static class |
DbxPath.InvalidPathException
Thrown when a given string isn't a valid Dropbox path, due to
invalid characters, names, or encodings.
|
Modifier and Type | Field and Description |
---|---|
static DbxPath |
ROOT
Dropbox paths always begin with a forward-slash and ROOT is always a
single forward-slash.
|
Constructor and Description |
---|
DbxPath(DbxPath parent,
java.lang.String childName)
Creates a new
DbxPath representing a child or descendant
of a parent path. |
DbxPath(java.lang.String path)
Creates a new
DbxPath . |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(DbxPath other) |
boolean |
equals(java.lang.Object o) |
DbxPath |
getChild(java.lang.String name)
Treats this path as a folder and returns the path of a
child file or folder with the given name.
|
java.lang.String |
getName()
Returns the unqualified name of the file or folder at this path.
|
DbxPath |
getParent()
Returns the path of the folder containing this path, or
null if the path is "/" . |
int |
hashCode() |
boolean |
isDescendantOf(DbxPath path)
Returns whether the given path is a descendant of this one.
|
boolean |
isSameOrDescendantOf(DbxPath path)
Returns whether the given path is the same as or a descendant of this
one.
|
java.lang.String |
log()
Gets a version of this path suitable for logging.
|
java.lang.String |
toString()
Returns the path as a string, in the original form provided to the
constructor.
|
public static final DbxPath ROOT
public DbxPath(java.lang.String path) throws DbxPath.InvalidPathException
DbxPath
.path
- the path, beginning with '/'DbxPath.InvalidPathException
- if path
isn't a legal Dropbox pathpublic DbxPath(DbxPath parent, java.lang.String childName) throws DbxPath.InvalidPathException
DbxPath
representing a child or descendant
of a parent path.
DbxPath(ROOT, "Photos")
→ "/Photos"DbxPath(DbxPath("/Photos/Recent"), "Home.jpg")
→
"/Photos/Recent/Home.jpg"
DbxPath(DbxPath("/Photos"), "Recent/Home.jpg")
→
"/Photos/Recent/Home.jpg"
parent
- the parent pathchildName
- the name or sub-path for the new childDbxPath.InvalidPathException
- if name
isn't a legal Dropbox pathpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int compareTo(DbxPath other)
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
DbxPath.DbxPath(String)
to create DbxPath objects.toString
in class java.lang.Object
public java.lang.String log()
public java.lang.String getName()
getName("/")
→ ""
getName("/Photos")
→ "Photos"
getName("/Photos/Recent/Home.jpg")
→
"Home.jpg"
public DbxPath getParent()
null
if the path is "/"
.
getParent("/")
→ null
getParent("/Photos")
→ "/"
getParent("/Photos/Recent/Home.jpg")
→
"/Photos/Recent"
public DbxPath getChild(java.lang.String name)
name
- the unqualified name of the child.DbxPath.InvalidPathException
- if the child name isn't legal for a Dropbox path.public boolean isDescendantOf(DbxPath path)
public boolean isSameOrDescendantOf(DbxPath path)