Skip to content

Commit

Permalink
[cleanup] Remove Guava dependencies from GMFHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
lredor committed Sep 12, 2024
1 parent 3ce87ad commit 441bc92
Showing 1 changed file with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
Expand Down Expand Up @@ -104,9 +105,6 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IEditorPart;

import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;

/**
* GMF Helper.
*
Expand Down Expand Up @@ -244,16 +242,18 @@ public static Point getAbsoluteLocation(Node node, boolean insetsAware, boolean
return location;
}

private static Node getPreviousChild(Node node) {
private static Node getPreviousChild(Node searchedNode) {
Node previousChild = null;
boolean found = false;
if (node.eContainer() instanceof Node container) {
for (Iterator<Node> children = Iterators.filter(container.getChildren().iterator(), Node.class); children.hasNext() && !found; /* */) {
Node child = children.next();
if (node == child) {
found = true;
} else {
previousChild = child;
if (searchedNode.eContainer() instanceof Node container) {
for (Iterator<View> children = container.getChildren().iterator(); children.hasNext() && !found; /* */) {
View child = children.next();
if (child instanceof Node nodeChild) {
if (searchedNode == nodeChild) {
found = true;
} else {
previousChild = nodeChild;
}
}
}
}
Expand Down Expand Up @@ -489,8 +489,8 @@ private static boolean hasFullLabelBorder(DDiagramElementContainer ddec) {
private static boolean isFirstRegion(DDiagramElementContainer ddec) {
EObject potentialRegionContainer = ddec.eContainer();
if (potentialRegionContainer instanceof DNodeContainer dNodeContainer) {
Iterable<DDiagramElementContainer> regions = Iterables.filter((dNodeContainer).getOwnedDiagramElements(), DDiagramElementContainer.class);
return !Iterables.isEmpty(regions) && ddec == Iterables.getFirst(regions, null);
Optional<DDiagramElement> optionalDDiagramElement = dNodeContainer.getOwnedDiagramElements().stream().filter(DDiagramElementContainer.class::isInstance).findFirst();
return optionalDDiagramElement.isPresent() && ddec == optionalDDiagramElement.get();
}
return false;
}
Expand Down Expand Up @@ -907,10 +907,10 @@ private static void replaceAutoSize(Node node, PrecisionRectangle bounds, boolea

private static int getBorderNodesSides(Node container, Rectangle containerChildrenBounds) {
int result = PositionConstants.NONE;
for (Iterator<Node> children = Iterators.filter(container.getChildren().iterator(), Node.class); children.hasNext(); /* */) {
Node child = children.next();
if (new NodeQuery(child).isBorderedNode()) {
Rectangle borderNodeBounds = getAbsoluteBounds(child, true, false, false, false);
for (ListIterator<View> children = container.getChildren().listIterator(); children.hasNext(); /* */) {
View child = children.next();
if (child instanceof Node nodeChild && new NodeQuery(nodeChild).isBorderedNode()) {
Rectangle borderNodeBounds = getAbsoluteBounds(nodeChild, true, false, false, false);
if (borderNodeBounds.preciseX() == containerChildrenBounds.preciseX()) {
result = result | PositionConstants.LEFT;
}
Expand Down Expand Up @@ -986,11 +986,11 @@ private static Rectangle getChildrenBounds(Node container, boolean considerBorde
result = getAbsoluteBounds(lastChild, true, false, true, false);
}
} else {
for (Iterator<Node> children = Iterators.filter(container.getChildren().iterator(), Node.class); children.hasNext(); /* */) {
Node nodeChild = children.next();
for (ListIterator<View> children = container.getChildren().listIterator(); children.hasNext(); /* */) {
View child = children.next();
// The border nodes are ignored, except if it is expected to consider it (auto-size of a container with
// children having border nodes)
if (considerBorderNodes || !(new NodeQuery(nodeChild).isBorderedNode())) {
if (child instanceof Node nodeChild && (considerBorderNodes || !(new NodeQuery(nodeChild).isBorderedNode()))) {
Rectangle childAbsoluteBounds = getAbsoluteBounds(nodeChild, true, false, true, false);
if (result == null) {
result = childAbsoluteBounds.getCopy();
Expand Down

0 comments on commit 441bc92

Please sign in to comment.