Class DefaultImportPackages

java.lang.Object
org.apache.groovy.vmplugin.internal.DefaultImportPackages

public final class DefaultImportPackages extends Object
Orders default-import package prefixes by a caller-supplied precedence array. Iteration order of the returned sets is that array's order. Packages that are not in the array are dropped, so a HashSet walk cannot put a later package ahead of an earlier one.
Since:
7.0.0
  • Method Details

    • ordered

      public static Set<String> ordered(Collection<String> packages, String[] precedence)
      Returns the members of packages that occur in precedence, iterated in precedence order. Matches are inserted into a LinkedHashSet while walking precedence, then wrapped. The wrapper stays: callers publish the set to concurrent readers and share it with the startup index, so a later update replaces the map entry instead of mutating this set. An empty result is Collections.emptySet(). A single match is Collections.singleton(Object).
      Parameters:
      packages - packages discovered for one simple name; null is empty
      precedence - package prefixes in the order they must be tried; null yields an empty set
      Returns:
      an immutable set in precedence order
    • including

      public static Set<String> including(Set<String> existing, String packagePrefix, String[] precedence)
      Returns existing when it already contains packagePrefix. Otherwise returns the precedence-ordered union. packagePrefix values absent from precedence are not added.
      Parameters:
      existing - the packages already recorded, or null
      packagePrefix - the package to add
      precedence - package prefixes in try-order
      Returns:
      an immutable set in precedence order, or existing when unchanged
    • merge

      public static void merge(Map<String,Set<String>> target, Map<String,Set<String>> additions, String[] precedence)
      Unions additions into target. Each stored set is rewritten with ordered(java.util.Collection<java.lang.String>, java.lang.String[]). An addition that contributes no precedence package is ignored. When the value already stored contains every incoming package, that same instance is kept.
      Parameters:
      target - class name to packages already collected; updated in place
      additions - class name to packages found by one scan; null is a no-op
      precedence - package prefixes in try-order