Skip to content

Commit

Permalink
Replace Guava's collection factories by standard Java
Browse files Browse the repository at this point in the history
- Replace LinkedList with ArrayList or ArrayDeque

Part of #199
  • Loading branch information
iils-hwellmann committed Aug 14, 2024
1 parent 85cedde commit ebc6619
Show file tree
Hide file tree
Showing 58 changed files with 213 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
package de.cau.cs.kieler.kgraph.text.ui.internal;

import com.google.common.collect.Maps;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
Expand All @@ -12,6 +11,7 @@
import de.cau.cs.kieler.kgraph.text.ui.GRandomUiModule;
import de.cau.cs.kieler.kgraph.text.ui.KGraphUiModule;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import org.eclipse.ui.plugin.AbstractUIPlugin;
Expand All @@ -32,7 +32,7 @@ public class TextActivator extends AbstractUIPlugin {

private static TextActivator INSTANCE;

private Map<String, Injector> injectors = Collections.synchronizedMap(Maps.<String, Injector> newHashMapWithExpectedSize(1));
private Map<String, Injector> injectors = Collections.synchronizedMap(new HashMap<>(2));

@Override
public void start(BundleContext context) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
Expand All @@ -36,9 +37,6 @@
import org.eclipse.elk.core.util.Pair;
import org.eclipse.elk.graph.properties.IProperty;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import de.cau.cs.kieler.kgraph.text.grandom.GeneratorOptions.RandVal;
import de.cau.cs.kieler.klighd.kgraph.KEdge;
import de.cau.cs.kieler.klighd.kgraph.KGraphFactory;
Expand Down Expand Up @@ -132,7 +130,7 @@ private List<List<KNode>> addHierarchicalNodes(final KNode parent) {
private void connectAtomicNodesOnDifferentLevels(final List<List<KNode>> atomicNodes) {
int numCrossHier;
if (get(EXACT_RELATIVE_HIER) != null) {
Set<KEdge> newHashSet = Sets.newHashSet();
Set<KEdge> newHashSet = new HashSet<>();
for (List<KNode> level : atomicNodes) {
for (KNode node : level) {
newHashSet.addAll(node.getIncomingEdges());
Expand Down Expand Up @@ -1208,7 +1206,7 @@ private KPort retrievePort(final KNode node, final boolean source) {
float reusePortsChance = get(USE_EXISTING_PORTS_CHANCE).floatVal(random);
if (reusePortsChance > 0.0f && random.nextFloat() < reusePortsChance) {
// Collect candidate ports for reuse
List<KPort> reuseCandidates = Lists.newLinkedList();
List<KPort> reuseCandidates = new ArrayList<>();

for (KPort port : node.getPorts()) {
// Two flags indicating whether the port already has edges pointing in the right
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -32,7 +31,6 @@
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.ecore.util.EcoreUtil;

import com.google.common.collect.Lists;
import com.google.common.collect.MapDifference.ValueDifference;
import com.google.common.collect.Sets;

Expand Down Expand Up @@ -362,9 +360,9 @@ private void handleLabels(final KLabeledGraphElement baseElement,
final KLabeledGraphElement newElement) {
Set<KLabel> oldLabels = null;
if (baseElement != null) {
oldLabels = new HashSet<KLabel>(baseElement.getLabels());
oldLabels = new HashSet<>(baseElement.getLabels());
}
for (KLabel newLabel : Lists.newLinkedList(newElement.getLabels())) {
for (KLabel newLabel : new ArrayList<>(newElement.getLabels())) {
KLabel baseLabel = comparison.lookupBaseLabel(newLabel);
if (baseLabel == null) {
baseLabel = EcoreUtil.copy(newLabel);
Expand Down Expand Up @@ -425,9 +423,9 @@ private void updateLabel(final KLabel baseLabel, final KLabel newLabel) {
private void handlePorts(final KNode baseNode, final KNode newNode) {
Set<KPort> oldPorts = null;
if (baseNode != null) {
oldPorts = new HashSet<KPort>(baseNode.getPorts());
oldPorts = new HashSet<>(baseNode.getPorts());
}
for (KPort newPort : Lists.newLinkedList(newNode.getPorts())) {
for (KPort newPort : new ArrayList<>(newNode.getPorts())) {
KPort basePort = comparison.lookupBasePort(newPort);
if (basePort == null) {
basePort = EcoreUtil.copy(newPort);
Expand Down Expand Up @@ -487,7 +485,7 @@ private void updateGraphElement(final KGraphElement baseElement,
baseData.addAll(newData);
baseElement.copyProperties(newElement);
EMap<IProperty<?>, Object> baseProperties = baseElement.getProperties();
LinkedList<IProperty<?>> removedProperties = Lists.newLinkedList(
List<IProperty<?>> removedProperties = new ArrayList<>(
Sets.difference(baseProperties.keySet(), newElement.getProperties().keySet()));

for (IProperty<?> property : removedProperties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
package de.cau.cs.kieler.klighd.kgraph.util;

import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
import com.google.common.collect.Sets;

import de.cau.cs.kieler.klighd.kgraph.KEdge;
import de.cau.cs.kieler.klighd.kgraph.KGraphElement;
import de.cau.cs.kieler.klighd.kgraph.KPort;
Expand Down Expand Up @@ -67,7 +66,7 @@ public DefaultSelectionIterator(final KEdge edge, final boolean addPorts,
protected Iterator<? extends KGraphElement> getChildren(final Object object) {
// Ensure that the visited set is properly initialized
if (visited == null) {
visited = Sets.newHashSet();
visited = new HashSet<>();
}

if (object instanceof KEdge) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package de.cau.cs.kieler.klighd.kgraph.util;

import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

Expand All @@ -33,8 +34,6 @@
import org.eclipse.emf.ecore.util.EContentsEList.FeatureIteratorImpl;

import com.google.common.base.Predicate;
import com.google.common.collect.Maps;

import de.cau.cs.kieler.klighd.kgraph.EMapPropertyHolder;
import de.cau.cs.kieler.klighd.kgraph.KGraphPackage;
import de.cau.cs.kieler.klighd.kgraph.KLayoutData;
Expand Down Expand Up @@ -207,7 +206,7 @@ public static KNode loadDataElements(final KNode graph,
final Predicate<EMapPropertyHolder> handledTypes, final boolean clearProperties,
final IProperty<?>... knownProps) {

Map<String, IProperty<?>> knowPropsMap = Maps.newHashMap();
Map<String, IProperty<?>> knowPropsMap = new HashMap<>();
for (IProperty<?> p : knownProps) {
knowPropsMap.put(p.getId(), p);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package de.cau.cs.kieler.klighd.kgraph.util;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
Expand All @@ -43,8 +44,6 @@
import com.google.common.base.Strings;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import de.cau.cs.kieler.klighd.kgraph.EMapPropertyHolder;
import de.cau.cs.kieler.klighd.kgraph.KEdge;
import de.cau.cs.kieler.klighd.kgraph.KGraphElement;
Expand Down Expand Up @@ -710,7 +709,7 @@ public static Iterator<KGraphElement> getConnectedElements(final KEdge kedge,
// get a singleton iterator offering 'kedge'
final Iterator<KGraphElement> kedgeIt = Iterators.singletonIterator((KGraphElement) kedge);
// Keep a set of visited elements for the tree iterators
final Set<KPort> visited = Sets.newHashSet();
final Set<KPort> visited = new HashSet<>();

// Grab source iterator if edge has a source
final SelectionIterator sourceSideIt =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import java.util.HashMap;

import com.google.common.collect.Maps;

/**
* An color library containing a huge collection named colors.<br>
* The list of literals have been extracted from
Expand Down Expand Up @@ -1755,7 +1753,7 @@ public String toStringWithComponents() {
return super.toString() + "(" + redComponent + "," + greenComponent + "," + blueComponent + ")";
}

private static HashMap<String, Colors> fastColorLookup = Maps.newHashMap();
private static HashMap<String, Colors> fastColorLookup = new HashMap<>();

/**
* Provides the color with the name <code>name</code>. Besides it builds up a {@link HashMap} of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Arrays;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -66,8 +67,6 @@
import org.freehep.util.io.WriterOutputStream;

import com.google.common.base.Strings;
import com.google.common.collect.Maps;

import de.cau.cs.kieler.klighd.Klighd;
import de.cau.cs.kieler.klighd.KlighdConstants;
import de.cau.cs.kieler.klighd.microlayout.PlacementUtil;
Expand Down Expand Up @@ -227,7 +226,7 @@ public static void setDefaultProperties(Properties newProperties) {

private final float pointToPxFactor = KlighdConstants.DEFAULT_DISPLAY_DPI / 72f;
/** A mapping of awt fonts to swt fonts. The latter are used for font size calculations. */
private Map<Font, org.eclipse.swt.graphics.Font> awtSwtFontCache = Maps.newHashMap();
private Map<Font, org.eclipse.swt.graphics.Font> awtSwtFontCache = new HashMap<>();

/*
* ================================================================================ |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.text.AttributedCharacterIterator;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.elk.core.util.Pair;
Expand All @@ -62,8 +63,6 @@
import org.eclipse.swt.graphics.RGB;

import com.google.common.base.Objects;
import com.google.common.collect.Maps;

import de.cau.cs.kieler.klighd.KlighdConstants;
import de.cau.cs.kieler.klighd.krendering.KTextUtil;
import de.cau.cs.kieler.klighd.piccolo.internal.KlighdSWTGraphicsEx;
Expand Down Expand Up @@ -100,7 +99,7 @@ public abstract class KlighdAbstractSVGGraphics extends Graphics2D implements Kl

private FontData fontData = KlighdConstants.DEFAULT_FONT;

private final Map<ImageData, BufferedImage> imageBuffer = Maps.newHashMap();
private final Map<ImageData, BufferedImage> imageBuffer = new HashMap<>();
private final Rectangle2D imageBoundsRect = new Rectangle2D.Double();

// the dash constants in the following definitions are copied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.awt.image.renderable.RenderableImage;
import java.lang.ref.WeakReference;
import java.text.AttributedCharacterIterator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -65,8 +66,6 @@
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.widgets.Display;

import com.google.common.collect.Lists;

import de.cau.cs.kieler.klighd.Klighd;
import de.cau.cs.kieler.klighd.KlighdConstants;
import de.cau.cs.kieler.klighd.piccolo.internal.nodes.KlighdPaths;
Expand Down Expand Up @@ -488,7 +487,7 @@ public void setFont(final FontData fontData, final int maxLineWidth) {

} else {
if (temporaryFonts == null) {
temporaryFonts = Lists.newArrayList();
temporaryFonts = new ArrayList<>();
}
curFont = new org.eclipse.swt.graphics.Font(
fontCreationDevice != null ? fontCreationDevice : device, fontData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
Expand Down Expand Up @@ -796,7 +797,7 @@ private boolean isSelected(final KText kText) {
*/
protected List<KStyle> determinePropagationStyles(final List<KStyle> renderingStyles,
final List<KStyle> propagatedStyles, final boolean isRenderingRef) {
final List<KStyle> result = Lists.newLinkedList();
final List<KStyle> result = new ArrayList<>();

for (final KStyle style : isRenderingRef ? propagatedStyles : concat(
propagatedStyles, renderingStyles)) {
Expand Down Expand Up @@ -1255,7 +1256,7 @@ protected void addListener(final String property, final IKlighdNode parent,
@SuppressWarnings("unchecked")
List<Object> listeners = (List<Object>) nodeAsPNode.getAttribute(PROPERTY_LISTENER_KEY);
if (listeners == null) {
listeners = Lists.newLinkedList();
listeners = new ArrayList<>();
nodeAsPNode.addAttribute(PROPERTY_LISTENER_KEY, listeners);
}
listeners.add(new Pair<String, PropertyChangeListener>(property, listener));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import java.awt.geom.Point2D;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -45,9 +48,6 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

import de.cau.cs.kieler.klighd.Klighd;
import de.cau.cs.kieler.klighd.KlighdOptions;
import de.cau.cs.kieler.klighd.ViewContext;
Expand Down Expand Up @@ -156,7 +156,7 @@ public class DiagramController {
private boolean record = false;

/** the layout changes to graph elements while recording. */
private final Map<IKGraphElementNode, Object> recordedChanges = Maps.newLinkedHashMap();
private final Map<IKGraphElementNode, Object> recordedChanges = new LinkedHashMap<>();

/** indicates whether scheduled diagram element updates must be executed via this display. */
private final Display display;
Expand Down Expand Up @@ -835,9 +835,9 @@ void recordChange(final IKGraphElementNode node, final Object change) {
recordedChanges.put(node, change);
}

private final Set<AbstractKGERenderingController<?, ?>> dirtyDiagramElements = Sets.newHashSet();
private final Set<AbstractKGERenderingController<?, ?>> dirtyDiagramElements = new HashSet<>();
private final Map<AbstractKGERenderingController<?, ?>, ElementMovement> dirtyDiagramElementStyles =
Maps.newHashMap();
new HashMap<>();

void scheduleRenderingUpdate(final AbstractKGERenderingController<?, ?> controller) {
renderingUpdater.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.awt.geom.Point2D;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
Expand Down Expand Up @@ -133,7 +134,7 @@ public void propertyChange(final PropertyChangeEvent event) {
edgeNode.addAttribute(EDGE_OFFSET_LISTENER_KEY, listener);

// calculate the offset and register the update offset listener
List<PNode> listenedNodes = Lists.newLinkedList();
List<PNode> listenedNodes = new ArrayList<>();
Point2D offset = new Point2D.Double(0, 0);
PNode currentNode = relativeChildArea;
while (currentNode != null && currentNode != edgeNodeParent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
*/
package de.cau.cs.kieler.klighd.piccolo.internal.controller;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.elk.core.math.Spacing;
import org.eclipse.elk.core.options.CoreOptions;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;

import de.cau.cs.kieler.klighd.kgraph.KEdge;
import de.cau.cs.kieler.klighd.kgraph.KGraphElement;
import de.cau.cs.kieler.klighd.kgraph.KInsets;
Expand Down Expand Up @@ -293,7 +292,7 @@ public PBounds toPBoundsIncludingPortsAndLabels(final KNode node,
public PBounds getContainedSubDiagramsBoundingBox(final KNode node,
final Predicate<KGraphElement> isDisplayedFilter) {
final PBounds nodeBounds = new PBounds();
final Set<KEdge> visitedEdges = Sets.newHashSet();
final Set<KEdge> visitedEdges = new HashSet<>();

for (final KNode childNode : Iterables.filter(node.getChildren(), isDisplayedFilter)) {
nodeBounds.add(toPBoundsIncludingPortsAndLabels(childNode, false, null, false));
Expand Down
Loading

0 comments on commit ebc6619

Please sign in to comment.