Class URL

java.lang.Object
es.situm.sdk.model.URL
All Implemented Interfaces:
android.os.Parcelable

public final class URL extends Object implements android.os.Parcelable
Abstraction of URL. Unifies management of both absolutes and relatives URLs.
  • Field Details

    • EMPTY

      public static final URL EMPTY
    • CREATOR

      public static final android.os.Parcelable.Creator<URL> CREATOR
  • Constructor Details

    • URL

      public URL(@NonNull String value)
      Create a URL object with an absolute or relative URL. If value starts with '/' is considered relative, and will take URLs.SERVER as host with port.
      Parameters:
      value - String
  • Method Details

    • getValue

      @NonNull public String getValue()
      Original value provided to de constructor
      Returns:
      constructor's value param
    • getLastTerm

      @NonNull public 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 if isRelative()
      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 if isAbsolute()
      Returns:
      true | false
    • asURL

      @NonNull public URL asURL() throws MalformedURLException
      Returns current URL as a URL. If url is relative, host with port is current URLs.SERVER
      Returns:
      URL
      Throws:
      MalformedURLException - exception thrown by URL when created
    • asStringURL

      @NonNull public String asStringURL()
      Returns value if isAbsolute(), or SERVER_URL + value if isRelative().
      Returns:
      String
    • protocol

      @NonNull public String protocol() throws MalformedURLException
      Wrap of asURL() and method URL.getProtocol()
      Returns:
      String
      Throws:
      MalformedURLException - exception thrown by URL when created
    • host

      @NonNull public String host() throws MalformedURLException
      Wrap of asURL() and method URL.getHost()
      Returns:
      String
      Throws:
      MalformedURLException - exception thrown by URL when created
    • port

      public int port() throws 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. If URL has no default port to this protocol, then -1 is returned.
      Returns:
      the port number
      Throws:
      MalformedURLException - exception thrown by URL when created
    • path

      @NonNull public String path() throws MalformedURLException
      Throws:
      MalformedURLException
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • describeContents

      public int describeContents()
      Specified by:
      describeContents in interface android.os.Parcelable
    • writeToParcel

      public void writeToParcel(android.os.Parcel dest, int flags)
      Specified by:
      writeToParcel in interface android.os.Parcelable