Skip to content

Commit

Permalink
replace Hashset by LinkedHashSet
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaillandier committed Jan 27, 2022
1 parent 47cf56e commit 31ddfab
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 45 deletions.
Expand Up @@ -2,7 +2,7 @@

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.stream.Collectors;

import core.metamodel.entity.AGeoEntity;
Expand Down Expand Up @@ -51,7 +51,7 @@ public class GenStarGamaConstraintBuilder {
private double distanceStep;
private int distancePriority;

public GenStarGamaConstraintBuilder() { this.constraints = new HashSet<>(); }
public GenStarGamaConstraintBuilder() { this.constraints = new LinkedHashSet<>(); }

/**
* Get the constraints that have been setup to be created by this builder
Expand All @@ -77,7 +77,7 @@ public boolean hasConstraints() {
*/
public Collection<ISpatialConstraint> buildConstraints(Collection<? extends AGeoEntity<? extends IValue>> nests) throws IllegalStateException {
if(!hasConstraints()) { throw new IllegalStateException("You must have at least one constraint setup to use the builder"); }
Collection<ISpatialConstraint> buildConstraints = new HashSet<>();
Collection<ISpatialConstraint> buildConstraints = new LinkedHashSet<>();
for(SpatialConstraint sc : this.constraints) {
switch(sc) {
case DENSITY:
Expand Down
4 changes: 2 additions & 2 deletions msi.gama.core/src/msi/gama/common/geometry/GeometryUtils.java
Expand Up @@ -19,7 +19,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
Expand Down Expand Up @@ -607,7 +607,7 @@ public static List<LineString> squeletisation(final IScope scope, final Geometry
for (final Object o : cc) {
final GamaShape node = (GamaShape) o;
final Coordinate[] coordsArr =
GeometryUtils.extractPoints(node, new HashSet(Graphs.neighborsOf(scope, graph, node)));
GeometryUtils.extractPoints(node, new LinkedHashSet<IShape>(Graphs.neighborsOf(scope, graph, node)));
if (coordsArr != null) { network.add(GEOMETRY_FACTORY.createLineString(coordsArr)); }
}
} else if (cc.size() == 2) {
Expand Down
Expand Up @@ -11,7 +11,7 @@

package msi.gama.kernel.batch.optimization.genetic;

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

import msi.gama.runtime.IScope;
Expand All @@ -22,7 +22,7 @@ public CrossOver1Pt() {}

@Override
public Set<Chromosome> crossOver(final IScope scope, final Chromosome parent1, final Chromosome parent2) {
final Set<Chromosome> children = new HashSet<>();
final Set<Chromosome> children = new LinkedHashSet<>();
final int nbGenes = parent2.getGenes().length;
if (nbGenes == 1) { return children; }
int cutPt = 0;
Expand Down
Expand Up @@ -10,7 +10,7 @@
********************************************************************************************************/
package msi.gama.metamodel.topology.graph;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -131,7 +131,7 @@ protected void aStar(final V sourceNode, final V targetNode) {
openMap.remove(current.node);
closedMap.put(current.node, current);
final _Vertex<V, E> node = graph.getVertex(current.node);
final Set<E> edges = new HashSet<E>(node.getOutEdges());
final Set<E> edges = new LinkedHashSet<E>(node.getOutEdges());
if (!graph.isDirected()) {
edges.addAll(node.getInEdges());

Expand Down
Expand Up @@ -14,7 +14,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -539,8 +539,8 @@ GamaSpatialPath pathFromEdgesUndirected(final IScope scope, final IList<IShape>
IList<IShape> edges = listOfEdges;
if (edges.isEmpty() || edges.get(0) == null) { return null; }
if (!sourceNode) {
Set edgesSetInit = new HashSet(Arrays.asList(edges.get(0).getInnerGeometry().getCoordinates()));
final Set edgesSetS = new HashSet(Arrays.asList(edgeS.getInnerGeometry().getCoordinates()));
Set edgesSetInit = new LinkedHashSet(Arrays.asList(edges.get(0).getInnerGeometry().getCoordinates()));
final Set edgesSetS = new LinkedHashSet(Arrays.asList(edgeS.getInnerGeometry().getCoordinates()));
if (!edgesSetS.equals(edgesSetInit)) {
double l1 = 0;
double l2 = 1;
Expand All @@ -554,7 +554,7 @@ GamaSpatialPath pathFromEdgesUndirected(final IScope scope, final IList<IShape>
edges.add(0, edgeS);
} else {
edges = edgesbis;
edgesSetInit = new HashSet(Arrays.asList(edges.get(0).getInnerGeometry().getCoordinates()));
edgesSetInit = new LinkedHashSet(Arrays.asList(edges.get(0).getInnerGeometry().getCoordinates()));
if (!edgesSetS.equals(edgesSetInit)) {
edges.add(0, edgeS);
}
Expand All @@ -564,8 +564,8 @@ GamaSpatialPath pathFromEdgesUndirected(final IScope scope, final IList<IShape>
}
if (!targetNode) {
final Set edgesSetEnd =
new HashSet(Arrays.asList(edges.get(edges.size() - 1).getInnerGeometry().getCoordinates()));
final Set edgesSetT = new HashSet(Arrays.asList(edgeT.getInnerGeometry().getCoordinates()));
new LinkedHashSet(Arrays.asList(edges.get(edges.size() - 1).getInnerGeometry().getCoordinates()));
final Set edgesSetT = new LinkedHashSet(Arrays.asList(edgeT.getInnerGeometry().getCoordinates()));

if (!edgesSetT.equals(edgesSetEnd)) {
edges.add(edgeT);
Expand Down Expand Up @@ -1005,13 +1005,13 @@ public Collection<IAgent> getNeighborsOf(final IScope scope, final IShape source
searchVertices = filter.getSpecies() == graph.getVertexSpecies();
}
if (searchEdges) {
final Set<IShape> edgs = getNeighborsOfRec(scope, realS, true, distance, graph, new HashSet<IShape>());
final Set<IShape> edgs = getNeighborsOfRec(scope, realS, true, distance, graph, new LinkedHashSet<IShape>());
for (final IShape ed : edgs) {
agents.add(ed.getAgent());
}
return agents.items();
} else if (searchVertices) {
final Set<IShape> nds = getNeighborsOfRec(scope, realS, false, distance, graph, new HashSet<IShape>());
final Set<IShape> nds = getNeighborsOfRec(scope, realS, false, distance, graph, new LinkedHashSet<IShape>());
for (final IShape nd : nds) {
agents.add(nd.getAgent());
}
Expand All @@ -1023,7 +1023,7 @@ public Collection<IAgent> getNeighborsOf(final IScope scope, final IShape source
} else {
agentsTotest = scope.getSimulation().getAgents(scope);
}
final Set<IShape> edges = getNeighborsOfRec(scope, realS, true, distance, graph, new HashSet<IShape>());
final Set<IShape> edges = getNeighborsOfRec(scope, realS, true, distance, graph, new LinkedHashSet<IShape>());
for (final Object ob : agentsTotest.iterable(scope)) {
final IShape ag = (IShape) ob;
if (filter.accept(scope, source, ag)) {
Expand Down
6 changes: 3 additions & 3 deletions msi.gama.core/src/msi/gama/util/file/GamaOsmFile.java
Expand Up @@ -20,8 +20,8 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -348,8 +348,8 @@ public void getFeatureIterator(final IScope scope, final boolean returnIt) {
final List<Node> nodes = new ArrayList<>();
final List<Way> ways = new ArrayList<>();
final List<Relation> relations = new ArrayList<>();
final Set<Long> intersectionNodes = new HashSet<>();
final Set<Long> usedNodes = new HashSet<>();
final Set<Long> intersectionNodes = new LinkedHashSet<>();
final Set<Long> usedNodes = new LinkedHashSet<>();

final Sink sinkImplementation = new Sink() {

Expand Down
5 changes: 2 additions & 3 deletions msi.gama.core/src/msi/gama/util/graph/GamaGraph.java
Expand Up @@ -15,7 +15,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -324,7 +323,7 @@ public GamaGraph(final IScope scope, final IType nodeType, final IType edgeType)
public GamaGraph(final IScope scope, final AbstractBaseGraph<String, DefaultEdge> graph, final ISpecies nodeS,
final ISpecies edgeS) {
this(scope, nodeS == null ? Types.STRING : Types.AGENT, edgeS == null ? Types.STRING : Types.AGENT);
Map<String, IAgent> verticesAg = new HashMap();
Map<String, IAgent> verticesAg = GamaMapFactory.create();
for (Object v : graph.vertexSet()) {
if (nodeS == null) {
addVertex(v.toString());
Expand Down Expand Up @@ -382,7 +381,7 @@ public GamaGraph(final IScope scope, final AbstractBaseGraph<String, DefaultEdge
public GamaGraph(final IScope scope, final AbstractBaseGraph<String, DefaultEdge> graph, final IList nodes,
final ISpecies edgeS) {
this(scope, Types.get(nodes.get(0).getClass()), edgeS == null ? Types.STRING : Types.AGENT);
Map<String, Object> verticesAg = new HashMap();
Map<String, Object> verticesAg = GamaMapFactory.create();
for (Object v : graph.vertexSet()) {
Object d = nodes.get(Integer.parseInt(v.toString()));
addVertex(d);
Expand Down
4 changes: 2 additions & 2 deletions msi.gama.core/src/msi/gama/util/graph/_Vertex.java
Expand Up @@ -10,7 +10,7 @@
********************************************************************************************************/
package msi.gama.util.graph;

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

import org.jgrapht.util.ArrayUnenforcedSet;
Expand Down Expand Up @@ -84,7 +84,7 @@ public Set edgesTo(final Object v2) {
}

public Set getEdges() {
final Set result = new HashSet(inEdges);
final Set result = new LinkedHashSet<>(inEdges);
result.addAll(outEdges);
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions msi.gama.core/src/msi/gama/util/graph/layout/LayoutGrid.java
Expand Up @@ -10,8 +10,8 @@
package msi.gama.util.graph.layout;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -142,7 +142,7 @@ public void applyLayout(final IScope scope) {
}
remaining.remove(nV);
open.add(nV);
final Set<IShape> neigh2 = new HashSet<IShape>(Graphs.predecessorsOf(scope, graph, nV));
final Set<IShape> neigh2 = new LinkedHashSet<IShape>(Graphs.predecessorsOf(scope, graph, nV));
neigh2.addAll(Graphs.successorsOf(scope, graph, nV));

neigh2.removeAll(close);
Expand Down
Expand Up @@ -14,8 +14,8 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -90,12 +90,12 @@ public static Integer WeightedMeansDecisionMaking(final IScope scope, final ILis
public static void buildCombination(final List<String> criteria, final Set<String> currentSol,
final Set<Set<String>> combinations, final int start, final int end, final int index) {
if (index == criteria.size()) {
combinations.add(new HashSet<>(criteria));
combinations.add(new LinkedHashSet<>(criteria));
return;
}

for (int i = start; i <= end; i++) {
final Set<String> comb = new HashSet<>(currentSol);
final Set<String> comb = new LinkedHashSet<>(currentSol);
comb.add(criteria.get(i));
combinations.add(comb);
buildCombination(criteria, comb, combinations, i + 1, end, index + 1);
Expand All @@ -119,7 +119,7 @@ public static Integer FuzzyChoquetDecisionMaking(final IScope scope, final IList
final Map<String, Double> critWeight = new HashMap<>();
final Map<Set<String>, Double> weight = new HashMap<>();
for (final Object o : criteriaWeights.keySet()) {
final Set<String> key = new HashSet<>((List) o);
final Set<String> key = new LinkedHashSet<>((List) o);
final Double val = Cast.asFloat(scope, criteriaWeights.get(o));
if (key.size() == 1) {
critWeight.put(new ArrayList<>(key).get(0), val);
Expand All @@ -131,8 +131,8 @@ public static Integer FuzzyChoquetDecisionMaking(final IScope scope, final IList
critWeight.put(crit, 1.0);
}
}
final Set<Set<String>> combinations = new HashSet<>();
buildCombination(criteria, new HashSet<>(), combinations, 0, criteria.size() - 1, 0);
final Set<Set<String>> combinations = new LinkedHashSet<>();
buildCombination(criteria, new LinkedHashSet<>(), combinations, 0, criteria.size() - 1, 0);
for (final Set<String> comb : combinations) {
if (!weight.containsKey(comb)) {
Double tot = 0.0;
Expand Down Expand Up @@ -163,7 +163,7 @@ public static Integer FuzzyChoquetDecisionMaking(final IScope scope, final IList
double utility = prev;
for (int i = 1; i < orderedList.size(); i++) {
final double val = Cast.asFloat(scope, orderedList.get(i));
final Set<String> comb = new HashSet<>();
final Set<String> comb = new LinkedHashSet<>();
for (int j = i; j < listOfOrder.size(); j++) {
comb.add(criteria.get(listOfOrder.indexOf(j)));
}
Expand Down
6 changes: 3 additions & 3 deletions msi.gama.core/src/msi/gaml/operators/Spatial.java
Expand Up @@ -17,7 +17,7 @@
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -7030,7 +7030,7 @@ public static IList hierarchicalClusteringe(final IScope scope, final IContainer
final IList g1 = groups.get(i);
for (int j = i + 1; j < nb; j++) {
final IList g2 = groups.get(j);
final Set<IList> distGp = new HashSet<>();
final Set<IList> distGp = new LinkedHashSet<>();
distGp.add(g1);
distGp.add(g2);
final IAgent a = (IAgent) g1.get(0);
Expand Down Expand Up @@ -7060,7 +7060,7 @@ public static IList hierarchicalClusteringe(final IScope scope, final IContainer
groupeF.add(g1);

for (final IList groupe : groups) {
final Set<IList> newDistGp = new HashSet<>();
final Set<IList> newDistGp = new LinkedHashSet<>();
newDistGp.add(groupe);
newDistGp.add(g1);
double dist1 = Double.MAX_VALUE;
Expand Down
Expand Up @@ -11,7 +11,7 @@
package simtools.gaml.extensions.traffic.driving;

import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -1113,7 +1113,7 @@ public static Boolean readyToCross(final IScope scope,
// road node blocking information, which is a map: vehicle -> list of blocked roads
Map<IAgent, List<IAgent>> blockInfo = (Map<IAgent, List<IAgent>>)
node.getAttribute(RoadNodeSkill.BLOCK);
Collection<IAgent> blockingVehicles = new HashSet<>(blockInfo.keySet());
Collection<IAgent> blockingVehicles = new LinkedHashSet<>(blockInfo.keySet());
// check if any blocking vehicle has moved
for (IAgent otherVehicle : blockingVehicles) {
if (!otherVehicle.getLocation().equals(node.getLocation())) {
Expand Down Expand Up @@ -1593,9 +1593,9 @@ private void updateVehicleOrdering(final IScope scope, final int newLowestLane,

// Get all occupying lanes using `lowest_lane` and `num_lanes_occupied`
Set<Integer> oldLanes = IntStream.range(currentLowestLane, currentLowestLane + numLanesOccupied)
.boxed().collect(Collectors.toCollection(HashSet::new));
.boxed().collect(Collectors.toCollection(LinkedHashSet::new));
Set<Integer> newLanes = IntStream.range(newLowestLane, newLowestLane + numLanesOccupied)
.boxed().collect(Collectors.toCollection(HashSet::new));
.boxed().collect(Collectors.toCollection(LinkedHashSet::new));

IAgent correctRoad = getCurrentRoad(vehicle);
int numLanesCorrect = RoadSkill.getNumLanes(correctRoad);
Expand Down
Expand Up @@ -15,6 +15,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -373,7 +374,7 @@ private Set<IAgent> getExternalAgents(final IScope scope) {
if (scope.getAgent() == null) return Collections.EMPTY_SET;
Set<IAgent> result = (Set<IAgent>) scope.getAgent().getAttribute("__externalAgents");
if (result == null) {
result = new HashSet();
result = new LinkedHashSet<IAgent>();
scope.getAgent().setAttribute("__externalAgents", result);
}
return result;
Expand Down
Expand Up @@ -14,7 +14,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -476,7 +476,7 @@ public static double fuzzyKappaSimulation(final IScope scope,

final Map<List<Integer>, Map<Double, Double>> XaPerTransition = GamaMapFactory.create();
final Map<List<Integer>, Map<Double, Double>> XsPerTransition = GamaMapFactory.create();
final Set<Double> Xvals = new HashSet<>();
final Set<Double> Xvals = new LinkedHashSet<>();
for (int i = 0; i < nbCat; i++) { categoriesId.put(categories.get(i), i); }

for (int i = 0; i < nbCat; i++) {
Expand Down

0 comments on commit 31ddfab

Please sign in to comment.