diff options
author | Nathalie Lepine | 2020-10-16 09:29:20 +0000 |
---|---|---|
committer | Maxime Porhel | 2020-10-23 13:59:13 +0000 |
commit | 3466ee9caf4136f41dc2988b1638dd2b9202a5d3 (patch) | |
tree | 26a8b318e63d64370c2262206ba25a0381cb9dce /plugins | |
parent | 1c66a4c62c85fcb14ce43d3f9055537bec89e0ac (diff) | |
download | org.eclipse.sirius-3466ee9caf4136f41dc2988b1638dd2b9202a5d3.tar.gz org.eclipse.sirius-3466ee9caf4136f41dc2988b1638dd2b9202a5d3.tar.xz org.eclipse.sirius-3466ee9caf4136f41dc2988b1638dd2b9202a5d3.zip |
[567517] Remove some Lists.newArrayList
There is no need to create the list if we only need to filter or count
the elements.
Bug: 567517
Change-Id: I9e349fe245780c56f4fb606b5b4073db5eead776
Signed-off-by: Nathalie Lepine <nathalie.lepine@obeo.fr>
Diffstat (limited to 'plugins')
2 files changed, 23 insertions, 24 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/layout/EventEndToPositionFunction.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/layout/EventEndToPositionFunction.java index de27cfbb80..3beb031db6 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/layout/EventEndToPositionFunction.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/layout/EventEndToPositionFunction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2020 THALES GLOBAL SERVICES. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -32,7 +32,6 @@ import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; /** * Function to compute position of and EventEnd. @@ -61,6 +60,7 @@ public class EventEndToPositionFunction implements Function<EventEnd, Integer> { /** * {@inheritDoc} */ + @Override public Integer apply(EventEnd from) { return getOldPosition(from, eventEndToSequenceEvents.apply(from)); } @@ -86,9 +86,9 @@ public class EventEndToPositionFunction implements Function<EventEnd, Integer> { private ISequenceEvent getSafeEvent(Collection<ISequenceEvent> ises) { ISequenceEvent ise = null; Predicate<Object> safe = Predicates.or(Predicates.instanceOf(AbstractNodeEvent.class), Predicates.instanceOf(AbstractFrame.class)); - Collection<? extends ISequenceEvent> safeEvents = Lists.newArrayList(Iterables.filter(ises, safe)); + Iterable<? extends ISequenceEvent> safeEvents = Iterables.filter(ises, safe); - if (!safeEvents.isEmpty()) { + if (!Iterables.isEmpty(safeEvents)) { ise = safeEvents.iterator().next(); } else if (Iterables.size(Iterables.filter(ises, Operand.class)) == 2) { ise = getSafeOperandEnd(ises); @@ -114,8 +114,7 @@ public class EventEndToPositionFunction implements Function<EventEnd, Integer> { } /** - * Get the old position of the corresponding event end, regarding the given - * event old range. event. + * Get the old position of the corresponding event end, regarding the given event old range. event. * * @param see * event end diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/util/SubEventsHelper.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/util/SubEventsHelper.java index 60bf62049f..242511e9ae 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/util/SubEventsHelper.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/util/SubEventsHelper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2020 THALES GLOBAL SERVICES. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -73,8 +73,7 @@ public final class SubEventsHelper { * Default constructor. * * @param event - * a supported {@link ISequenceEvent} : {@linkLifeline}, - * {@link AbstractNodeEvent}, {@link Operand}. + * a supported {@link ISequenceEvent} : {@linkLifeline}, {@link AbstractNodeEvent}, {@link Operand}. */ public SubEventsHelper(ISequenceEvent event) { Preconditions.checkArgument(types.contains(event.getClass())); @@ -86,8 +85,8 @@ public final class SubEventsHelper { /** * Common implementation of {@link ISequenceEvent#getSubEvents()}. * - * @return the sub-events of the (root) execution, ordered by their starting - * position (graphically) from top to bottom. + * @return the sub-events of the (root) execution, ordered by their starting position (graphically) from top to + * bottom. */ public List<ISequenceEvent> getSubEvents() { List<ISequenceEvent> result = getValidSubEvents(); @@ -232,6 +231,7 @@ public final class SubEventsHelper { final ISequenceEvent potentialChild = event; Predicate<ISequenceEvent> isParentOfCurrent = new Predicate<ISequenceEvent>() { + @Override public boolean apply(ISequenceEvent input) { Range inputRange = input.getVerticalRange(); boolean isParent = inputRange.includes(verticalRange); @@ -239,12 +239,13 @@ public final class SubEventsHelper { } }; - List<ISequenceEvent> parents = Lists.newArrayList(Iterables.filter(potentialParents, isParentOfCurrent)); - if (parents.isEmpty()) { + Iterable<ISequenceEvent> parents = Iterables.filter(potentialParents, isParentOfCurrent); + if (Iterables.isEmpty(parents)) { topLevel.add(potentialChild); } else if (potentialChild instanceof AbstractFrame && !parentFrames) { Collection<ISequenceEvent> carriers = new ArrayList<ISequenceEvent>(getCarryingParents((AbstractFrame) potentialChild, coveredLifelines)); - Iterables.removeAll(carriers, parents); + List<ISequenceEvent> parentsList = Lists.newArrayList(parents); + Iterables.removeAll(carriers, parentsList); if (!carriers.isEmpty()) { topLevel.add(potentialChild); } @@ -266,35 +267,32 @@ public final class SubEventsHelper { } /** - * Implementation of - * {@link ISequenceEvent#canChildOccupy(ISequenceEvent, Range)} . + * Implementation of {@link ISequenceEvent#canChildOccupy(ISequenceEvent, Range)} . * * @param child * the child. * @param range * the vertical range to test. - * @return <code>true</code> if the child can be placed anywhere inside the - * specified vertical range (including occupying the whole range). + * @return <code>true</code> if the child can be placed anywhere inside the specified vertical range (including + * occupying the whole range). */ public boolean canChildOccupy(ISequenceEvent child, Range range) { return canChildOccupy(child, range, null, child == null ? getCoverage(parentEvent) : getCoverage(child)); } /** - * Implementation of - * {@link ISequenceEvent#canChildOccupy(ISequenceEvent, Range)} . + * Implementation of {@link ISequenceEvent#canChildOccupy(ISequenceEvent, Range)} . * * @param child - * the child, if child is null it means that it is a insertion - * point request from a CreationTool. + * the child, if child is null it means that it is a insertion point request from a CreationTool. * @param range * the vertical range to test. * @param eventsToIgnore * the list of events to ignore while compute canChildOccupy. * @param lifelines * lifelines to inspect - * @return <code>true</code> if the child can be placed anywhere inside the - * specified vertical range (including occupying the whole range). + * @return <code>true</code> if the child can be placed anywhere inside the specified vertical range (including + * occupying the whole range). */ public boolean canChildOccupy(ISequenceEvent child, final Range range, List<ISequenceEvent> eventsToIgnore, Collection<Lifeline> lifelines) { boolean result = true; @@ -367,6 +365,7 @@ public final class SubEventsHelper { Set<ISequenceEvent> result = new HashSet<ISequenceEvent>(self.getSubEvents()); Predicate<ISequenceEvent> inRangePredicate = new Predicate<ISequenceEvent>() { + @Override public boolean apply(ISequenceEvent input) { Range inputRange = input.getVerticalRange(); return range.includesAtLeastOneBound(inputRange) || new ISequenceEventQuery(input).isReflectiveMessage() && inputRange.includesAtLeastOneBound(range); @@ -375,6 +374,7 @@ public final class SubEventsHelper { }; Predicate<ISequenceEvent> inCoverage = new Predicate<ISequenceEvent>() { + @Override public boolean apply(ISequenceEvent input) { Collection<Lifeline> inputCoverage = new ArrayList<Lifeline>(getCoverage(input)); return Iterables.removeAll(inputCoverage, lifelines); |