Refactoring of PS#getPlots:

Initialize to HashSet rather than ArrayList, because of add in HashSet
is O(1) vs. add in ArrayList which is O(n). Also make the wrapping
set immutable.
This commit is contained in:
sauilitired 2018-11-14 13:52:09 +01:00
parent 032484b0f5
commit 16dbbe5244

View File

@ -966,18 +966,16 @@ public class PS {
* *
* @param area the {@code PlotArea} * @param area the {@code PlotArea}
* @param uuid the plot owner * @param uuid the plot owner
* @return Set of plot * @return Set of plots
*/ */
public Set<Plot> getPlots(PlotArea area, UUID uuid) { public Set<Plot> getPlots(PlotArea area, UUID uuid) {
ArrayList<Plot> myplots = new ArrayList<>(); final HashSet<Plot> plots = new HashSet<>();
for (Plot plot : getPlots(area)) { for (Plot plot : getPlots(area)) {
if (plot.hasOwner()) { if (plot.hasOwner() && plot.isOwnerAbs(uuid)) {
if (plot.isOwnerAbs(uuid)) { plots.add(plot);
myplots.add(plot);
} }
} }
} return Collections.unmodifiableSet(plots);
return new HashSet<>(myplots);
} }
/** /**