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.ParcelableAbstraction 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.StringasStringURL()java.net.URLasURL()Returns current URL as aURL.intdescribeContents()booleanequals(java.lang.Object o)java.lang.StringgetLastTerm()Returns las part of provided value, separated by '/'.java.lang.StringgetValue()Original value provided to de constructorinthashCode()java.lang.Stringhost()Wrap ofasURL()and methodURL.getHost()booleanisAbsolute()Return true if the value used to construct the URL doesn't start by '/', meaning it has a specific host.booleanisRelative()Return true if the value used to construct the URL starts by '/', meaning it has no specific host nor port.java.lang.Stringpath()intport()Gets the port number of this URL.java.lang.Stringprotocol()Wrap ofasURL()and methodURL.getProtocol()java.lang.StringtoString()voidwriteToParcel(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.MalformedURLExceptionReturns current URL as aURL. If url is relative, host with port is currentURLs.SERVER- Returns:
URL- Throws:
java.net.MalformedURLException- exception thrown byURLwhen created
-
asStringURL
@NonNull public java.lang.String asStringURL()
- Returns:
String
-
protocol
@NonNull public java.lang.String protocol() throws java.net.MalformedURLExceptionWrap ofasURL()and methodURL.getProtocol()- Returns:
String- Throws:
java.net.MalformedURLException- exception thrown byURLwhen created
-
host
@NonNull public java.lang.String host() throws java.net.MalformedURLExceptionWrap ofasURL()and methodURL.getHost()- Returns:
String- Throws:
java.net.MalformedURLException- exception thrown byURLwhen created
-
port
public int port() throws java.net.MalformedURLExceptionGets the port number of this URL. If the port is not set, returns the port number of the protocol associated with this URL. IfURLhas no default port to this protocol, then -1 is returned.- Returns:
- the port number
- Throws:
java.net.MalformedURLException- exception thrown byURLwhen 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:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
describeContents
public int describeContents()
- Specified by:
describeContentsin interfaceandroid.os.Parcelable
-
writeToParcel
public void writeToParcel(android.os.Parcel dest, int flags)- Specified by:
writeToParcelin interfaceandroid.os.Parcelable
-
-