Class Location


public abstract class Location
extends java.lang.Object
Handles various forms of location from where classes can be imported in a consistent way. Any location will be treated like a URI, thus there will not be any platform dependent file separator problems.

Examples for locations could be
  • file:///home/someuser/workspace/myproject/target/classes/myproject/Foo.class
  • jar:file:///home/someuser/.m2/repository/myproject/foolib.jar!/myproject/Foo.class
  • Method Summary

    Modifier and Type Method Description asURI()  
    boolean contains​(java.lang.String part)  
    boolean equals​(java.lang.Object obj)  
    int hashCode()  
    abstract boolean isArchive()
    This is a generalization of isJar().
    abstract boolean isJar()  
    boolean matches​(java.util.regex.Pattern pattern)  
    static Location of​( uri)  
    static Location of​( url)  
    static Location of​(java.nio.file.Path path)  
    static Location of​(java.util.jar.JarFile jar)  
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • asURI

      @PublicAPI(usage=ACCESS) public asURI()
    • contains

      @PublicAPI(usage=ACCESS) public boolean contains​(java.lang.String part)
      part - A part to check the respective location URI for
      true, if the respective URI contains the given part, false otherwise
    • matches

      @PublicAPI(usage=ACCESS) public boolean matches​(java.util.regex.Pattern pattern)
      pattern - A pattern to compare the respective location URI against
      true, if the respective URI matches the given pattern, false otherwise
    • isJar

      @PublicAPI(usage=ACCESS) public abstract boolean isJar()
    • isArchive

      @PublicAPI(usage=ACCESS) public abstract boolean isArchive()
      This is a generalization of isJar(). Before JDK 9, the only archives were Jar files, starting with JDK 9, we also have JRTs (the JDK modules).
      true, if this location represents an archive, like a JAR or JRT, false otherwise
    • hashCode

      public int hashCode()
      hashCode in class java.lang.Object
    • equals

      public boolean equals​(java.lang.Object obj)
      equals in class java.lang.Object
    • toString

      public java.lang.String toString()
      toString in class java.lang.Object
    • of

      @PublicAPI(usage=ACCESS) public static Location of​( url)
    • of

      @PublicAPI(usage=ACCESS) public static Location of​( uri)
    • of

      @PublicAPI(usage=ACCESS) public static Location of​(java.util.jar.JarFile jar)
    • of

      @PublicAPI(usage=ACCESS) public static Location of​(java.nio.file.Path path)