Class 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.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface android.os.Parcelable

        android.os.Parcelable.ClassLoaderCreator<T extends java.lang.Object>, android.os.Parcelable.Creator<T extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static android.os.Parcelable.Creator<URL> CREATOR  
      static URL EMPTY  
      • Fields inherited from interface android.os.Parcelable

        CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
    • 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()
      Returns value if isAbsolute(), or SERVER_URL + value if isRelative().
      java.net.URL asURL()
      Returns current URL as a URL.
      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 constructor
      int hashCode()  
      java.lang.String host()
      Wrap of asURL() and method URL.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 of asURL() and method URL.getProtocol()
      java.lang.String toString()  
      void writeToParcel​(android.os.Parcel dest, int flags)  
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • EMPTY

        public static final URL EMPTY
      • CREATOR

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

      • URL

        public URL​(@NonNull
                   java.lang.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 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 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 java.net.URL asURL()
                           throws java.net.MalformedURLException
        Returns current URL as a URL. If url is relative, host with port is current URLs.SERVER
        Returns:
        URL
        Throws:
        java.net.MalformedURLException - exception thrown by URL when created
      • asStringURL

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

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

        @NonNull
        public java.lang.String host()
                              throws java.net.MalformedURLException
        Wrap of asURL() and method URL.getHost()
        Returns:
        String
        Throws:
        java.net.MalformedURLException - exception thrown by URL 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. If URL has no default port to this protocol, then -1 is returned.
        Returns:
        the port number
        Throws:
        java.net.MalformedURLException - exception thrown by URL 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 class java.lang.Object
      • toString

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

        public int hashCode()
        Overrides:
        hashCode in class java.lang.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