Skip to content

Commit 028463b

Browse files
vogellaakurtakov
authored andcommitted
TargetDefinition.java - Code Quality Improvements
Optimizations: - Line 629-631: Eliminated unnecessary ArrayList creation and addAll call - changed from 3 lines to 1 line returning new ArrayList<>(Arrays.asList(collection)) - Line 598: Modernized array creation using method reference NameVersionDescriptor[]::new - Line 610: Modernized array creation using method reference TargetBundle[]::new - Line 527: Modernized array creation using method reference TargetBundle[]::new - Line 996: Modernized array creation using method reference TargetFeature[]::new Impact: - Cleaner, more concise code - Slightly better performance by avoiding unnecessary intermediate objects - Modern Java idioms make code easier to maintain - No API changes
1 parent e442ecb commit 028463b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetDefinition.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ private TargetBundle[] getBundles(boolean allBundles) {
524524
}
525525
}
526526

527-
TargetBundle[] allResolvedBundles = all.toArray(new TargetBundle[all.size()]);
527+
TargetBundle[] allResolvedBundles = all.toArray(TargetBundle[]::new);
528528
if (allBundles) {
529529
return allResolvedBundles;
530530
}
@@ -595,7 +595,7 @@ private TargetBundle[] filterBundles(TargetBundle[] bundles, NameVersionDescript
595595
}
596596

597597
// Return matching bundles, if we are organizing by feature, do not create invalid target bundles for missing bundle includes
598-
List<TargetBundle> result = getMatchingBundles(bundles, included.toArray(new NameVersionDescriptor[included.size()]), !containsFeatures);
598+
List<TargetBundle> result = getMatchingBundles(bundles, included.toArray(NameVersionDescriptor[]::new), !containsFeatures);
599599

600600
// Add in missing features as resolved bundles with error statuses
601601
if (containsFeatures && !missingFeatures.isEmpty()) {
@@ -607,7 +607,7 @@ private TargetBundle[] filterBundles(TargetBundle[] bundles, NameVersionDescript
607607
}
608608
}
609609

610-
return result.toArray(new TargetBundle[result.size()]);
610+
return result.toArray(TargetBundle[]::new);
611611
}
612612

613613
/**
@@ -627,9 +627,7 @@ private TargetBundle[] filterBundles(TargetBundle[] bundles, NameVersionDescript
627627
*/
628628
static List<TargetBundle> getMatchingBundles(TargetBundle[] collection, NameVersionDescriptor[] included, boolean handleMissingBundles) {
629629
if (included == null) {
630-
ArrayList<TargetBundle> result = new ArrayList<>();
631-
result.addAll(Arrays.asList(collection));
632-
return result;
630+
return new ArrayList<>(Arrays.asList(collection));
633631
}
634632
// map bundles names to available versions
635633
Map<String, List<TargetBundle>> bundleMap = new HashMap<>(collection.length);
@@ -995,7 +993,7 @@ public TargetFeature[] getAllFeatures() {
995993
}
996994
}
997995

998-
fFeatures = result.values().toArray(new TargetFeature[result.size()]);
996+
fFeatures = result.values().toArray(TargetFeature[]::new);
999997
return fFeatures;
1000998
}
1001999

0 commit comments

Comments
 (0)