Class DefaultImportPackages
java.lang.Object
org.apache.groovy.vmplugin.internal.DefaultImportPackages
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 Summary
Modifier and TypeMethodDescriptionReturnsexistingwhen it already containspackagePrefix.static voidUnionsadditionsintotarget.ordered(Collection<String> packages, String[] precedence) Returns the members ofpackagesthat occur inprecedence, iterated inprecedenceorder.
-
Method Details
-
ordered
Returns the members ofpackagesthat occur inprecedence, iterated inprecedenceorder. Matches are inserted into aLinkedHashSetwhile walkingprecedence, 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 isCollections.emptySet(). A single match isCollections.singleton(Object).- Parameters:
packages- packages discovered for one simple name;nullis emptyprecedence- package prefixes in the order they must be tried;nullyields an empty set- Returns:
- an immutable set in precedence order
-
including
public static Set<String> including(Set<String> existing, String packagePrefix, String[] precedence) Returnsexistingwhen it already containspackagePrefix. Otherwise returns the precedence-ordered union.packagePrefixvalues absent fromprecedenceare not added.- Parameters:
existing- the packages already recorded, ornullpackagePrefix- the package to addprecedence- package prefixes in try-order- Returns:
- an immutable set in precedence order, or
existingwhen unchanged
-
merge
public static void merge(Map<String, Set<String>> target, Map<String, Set<String>> additions, String[] precedence) Unionsadditionsintotarget. Each stored set is rewritten withordered(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 placeadditions- class name to packages found by one scan;nullis a no-opprecedence- package prefixes in try-order
-