Class JarDuplicates

java.lang.Object
com.norconex.commons.lang.jar.JarDuplicates

public class JarDuplicates extends Object
Holds jar files that are considered duplicates. Jar duplicates are defined as having the same base name, which is the regular file name, minus the version information.
Since:
1.10.0
  • Constructor Details

    • JarDuplicates

      public JarDuplicates(@NonNull @NonNull JarFile... jarFiles)
      Creates a group of 2 or more JarFile duplicates.
      Parameters:
      jarFiles - duplicate jar files (must not be null)
      Throws:
      IllegalArgumentException - if jar file array contains less than 2 non-null jar files.
      Since:
      3.0.0
    • JarDuplicates

      public JarDuplicates(@NonNull @NonNull Collection<JarFile> jarFiles)
      Creates a group of 2 or more JarFile duplicates.
      Parameters:
      jarFiles - duplicate jar files (must not be null)
      Throws:
      IllegalArgumentException - if jar file collection contains less than 2 non-null jar files.
      Since:
      3.0.0
  • Method Details

    • getBaseName

      public String getBaseName()
      Returns:
      the file name, minus the version and file extension
      Since:
      3.0.0
    • getJarFiles

      public List<JarFile> getJarFiles()
      Gets the jar files being considered duplicates of each other. Since 3.0.0, returns a List instead of an array, sorted from greatest to lowest.
      Returns:
      jar files
    • getLatestVersion

      @Deprecated(since="3.0.0") public JarFile getLatestVersion()
      Deprecated.
      Use getGreatest() instead.
      Gets the jar file that is considered the greatest of the batch based on their version and last modified date (in case of equivalent versions). If two ore more jars are candidates to be greatest (equivalent versions and modified date), there are no guarantees as to which one will be returned. Versions are expected to follow semantic versioning. Otherwise, a best effort it made to identify and convert versions to semantic ones for the purpose of comparing them. Given non-semantic version patterns vary, there are no guarantees of 100% accuracy in such case.
      Returns:
      greatest jar file
    • getGreatest

      public JarFile getGreatest()
      Gets the duplicate jar file that is considered the greatest based on its version and last modified date (in case of equivalent versions). If two ore more jars are candidates to be greatest (equivalent versions and modified date), there are no guarantees as to which one will be returned. Versions are expected to follow semantic versioning. Otherwise, a best effort it made to identify and convert versions to semantic ones for the purpose of comparing them. Given non-semantic version patterns vary, there are no guarantees of 100% accuracy in such case.
      Returns:
      greatest jar file
      Since:
      3.0.0
    • getAllButGreatest

      public List<JarFile> getAllButGreatest()
      Gets all jar files of this duplicate batch except for the one considered the greatest, as per getGreatest(). The jar files are sorted from greatest to lowest.
      Returns:
      all but the greatest jar files
      Since:
      3.0.0
    • hasVersionConflict

      @Deprecated(since="3.0.0") public boolean hasVersionConflict()
      Deprecated.
      Use !areEquivalent() instead.
      Whether all jar files share the same version or if at least one of them have a different version.
      Returns:
      true if at least one jar file has a different version
    • areEquivalent

      public boolean areEquivalent()
      Gets whether all jar files in this duplicate are equivalent (equivalent versions and identical last modified dates).
      Returns:
      true if all jars are equivalent
      Since:
      3.0.0
    • get

      public Optional<JarFile> get(File file)
      Gets the JarFile corresponding to the supplied file by comparing their paths.
      Parameters:
      file - file to get its corresponding JarFile
      Returns:
      an optional with the matching jar file, or empty if none found
      Since:
      3.0.0
    • contains

      public boolean contains(File jarFile)
      Gets whether this duplicate batch contains the given jar file, by comparing their paths. Same as invoking isPresent() on the returned value of get(File).
      Parameters:
      jarFile - jar file
      Returns:
      true if this instance contains the given jar file
    • toString

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

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

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object