Package es.situm.sdk.model
Class URL
- java.lang.Object
-
- es.situm.sdk.model.URL
-
- All Implemented Interfaces:
android.os.Parcelable
public final class URL extends java.lang.Object implements android.os.Parcelable
Abstraction of URL. Unifies management of both absolutes and relatives URLs.
-
-
Constructor Summary
Constructors Constructor Description URL(java.lang.String value)
Create a URL object with an absolute or relative URL.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
asStringURL()
java.net.URL
asURL()
Returns current URL as aURL
.int
describeContents()
boolean
equals(java.lang.Object o)
java.lang.String
getLastTerm()
Returns las part of provided value, separated by '/'.java.lang.String
getValue()
Original value provided to de constructorint
hashCode()
java.lang.String
host()
Wrap ofasURL()
and methodURL.getHost()
boolean
isAbsolute()
Return true if the value used to construct the URL doesn't start by '/', meaning it has a specific host.boolean
isRelative()
Return true if the value used to construct the URL starts by '/', meaning it has no specific host nor port.java.lang.String
path()
int
port()
Gets the port number of this URL.java.lang.String
protocol()
Wrap ofasURL()
and methodURL.getProtocol()
java.lang.String
toString()
void
writeToParcel(android.os.Parcel dest, int flags)
-
-
-
Method Detail
-
getValue
@NonNull public java.lang.String getValue()
Original value provided to de constructor- Returns:
- constructor's value param
-
getLastTerm
@NonNull public java.lang.String getLastTerm()
Returns las part of provided value, separated by '/'. Useful if the URL represents de location of a file, to obtain its name.- Returns:
- string, empty if path is empty
-
isAbsolute
public boolean isAbsolute()
Return true if the value used to construct the URL doesn't start by '/', meaning it has a specific host. False ifisRelative()
- Returns:
- true | false
-
isRelative
public boolean isRelative()
Return true if the value used to construct the URL starts by '/', meaning it has no specific host nor port. False ifisAbsolute()
- Returns:
- true | false
-
asURL
@NonNull public java.net.URL asURL() throws java.net.MalformedURLException
Returns current URL as aURL
. If url is relative, host with port is currentURLs.SERVER
- Returns:
URL
- Throws:
java.net.MalformedURLException
- exception thrown byURL
when created
-
asStringURL
@NonNull public java.lang.String asStringURL()
- Returns:
String
-
protocol
@NonNull public java.lang.String protocol() throws java.net.MalformedURLException
Wrap ofasURL()
and methodURL.getProtocol()
- Returns:
String
- Throws:
java.net.MalformedURLException
- exception thrown byURL
when created
-
host
@NonNull public java.lang.String host() throws java.net.MalformedURLException
Wrap ofasURL()
and methodURL.getHost()
- Returns:
String
- Throws:
java.net.MalformedURLException
- exception thrown byURL
when created
-
port
public int port() throws java.net.MalformedURLException
Gets the port number of this URL. If the port is not set, returns the port number of the protocol associated with this URL. IfURL
has no default port to this protocol, then -1 is returned.- Returns:
- the port number
- Throws:
java.net.MalformedURLException
- exception thrown byURL
when created
-
path
@NonNull public java.lang.String path() throws java.net.MalformedURLException
- Throws:
java.net.MalformedURLException
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
describeContents
public int describeContents()
- Specified by:
describeContents
in interfaceandroid.os.Parcelable
-
writeToParcel
public void writeToParcel(android.os.Parcel dest, int flags)
- Specified by:
writeToParcel
in interfaceandroid.os.Parcelable
-
-