Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;

import org.apache.commons.collections4.CollectionUtils;

/**
* Logit Scaling alignment (as introduced by P. Stephensen in International
* Journal of Microsimulation (2016) 9(3) 89-102),
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/microsim/data/ExperimentManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public Experiment setupExperiment(Experiment experiment, Object... models) throw
// expandODB(experiment.inputFolder + File.separator + inputDatabaseName,
// outFolder);

File inputDir = new File(experiment.inputFolder);
File inputDir = new File(Experiment.inputFolder);
if (inputDir.exists()) {
String[] files = inputDir.list();
for (String file : files) {
Expand All @@ -181,7 +181,7 @@ public Experiment setupExperiment(Experiment experiment, Object... models) throw
} else if (isMultiRun) {
log.info("Persisting database connection at: " + DatabaseUtils.databaseInputUrl);
} else {
DatabaseUtils.databaseInputUrl = experiment.inputFolder + File.separator + "input";
DatabaseUtils.databaseInputUrl = Experiment.inputFolder + File.separator + "input";
}

if (saveExperimentOnDatabase) {
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/microsim/data/MultiKeyCoefficientMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
*
* @author Ross Richardson
*/
public class MultiKeyCoefficientMap extends MultiKeyMap {// implements Cloneable {
// FIXME: this should be generic over <K, V> and leverage composition
public class MultiKeyCoefficientMap extends MultiKeyMap<Object, Object> {

private static final long serialVersionUID = 5049597007431364596L;

protected String[] keys;
protected Map<String, Integer> valuesMap;

Check warning on line 22 in src/main/java/microsim/data/MultiKeyCoefficientMap.java

View workflow job for this annotation

GitHub Actions / build

non-transient instance field of a serializable class declared with a non-serializable type

Check warning on line 22 in src/main/java/microsim/data/MultiKeyCoefficientMap.java

View workflow job for this annotation

GitHub Actions / build

non-transient instance field of a serializable class declared with a non-serializable type

/**
* Creates an empty new MultiKeyCoefficientMap with the names of the keys and
Expand Down Expand Up @@ -50,7 +51,7 @@
* @param keys - a String array listing the names of the categories of keys
* @param values - a String array listing the names of the categories of values
*/
public MultiKeyCoefficientMap(AbstractHashedMap map, String[] keys, String[] values) {
public MultiKeyCoefficientMap(AbstractHashedMap<MultiKey<?>, Object> map, String[] keys, String[] values) {
super(map);
this.keys = keys;
if (values != null) {
Expand Down Expand Up @@ -107,7 +108,7 @@
if (key[0] instanceof MultiKey)
return super.get(key[0]);
else
return super.get(new MultiKey(new Object[] { key[0] }));
return super.get(new MultiKey<>(new Object[] { key[0] }));
case 2:
return super.get(key[0], key[1]);
case 3:
Expand All @@ -131,7 +132,7 @@
// of the type MultiKey(MultiKey()).
value = (Object[]) super.get(key[0]);
else
value = (Object[]) super.get(new MultiKey(new Object[] { key[0] }));
value = (Object[]) super.get(new MultiKey<>(new Object[] { key[0] }));
return extractValueFromVector(toStringKey(key[1]), value);
case 3:
value = (Object[]) super.get(key[0], key[1]);
Expand Down Expand Up @@ -184,9 +185,9 @@
// MultiKey is created unnecessarily, which then leads to a
// null pointer exception as the MultKeyCoefficientMap does
// not have a key entry of the type MultiKey(MultiKey()).
super.put((MultiKey) keyValues[0], keyValues[1]);
super.put((MultiKey<?>) keyValues[0], keyValues[1]);
else {
super.put(new MultiKey(new Object[] { keyValues[0] }), keyValues[1]);
super.put(new MultiKey<>(new Object[] { keyValues[0] }), keyValues[1]);
}
break;
case 3:
Expand Down Expand Up @@ -215,7 +216,7 @@
if (value == null)
value = new Object[valuesMap.size()];
putValueToVector((String) keyValues[1], value, keyValues[2]);
super.put(new MultiKey(new Object[] { keyValues[0] }), value);
super.put(new MultiKey<>(new Object[] { keyValues[0] }), value);
break;
case 4:
value = (Object[]) super.get(keyValues[0], keyValues[1]);
Expand Down Expand Up @@ -259,14 +260,14 @@
case 1:
throw new IllegalArgumentException("Wrong number of key parameters");
case 2:
MultiKey key0;
MultiKey<?> key0;
if (keyValues[0] instanceof MultiKey) { // Ross: If we don't do this check, a new MultiKey of a MultiKey
// is created unnecessarily, which then leads to a null pointer
// exception as the MultKeyCoefficientMap does not have a key
// entry of the type MultiKey(MultiKey()).
key0 = (MultiKey) keyValues[0];
key0 = (MultiKey<?>) keyValues[0];
} else {
key0 = new MultiKey(new Object[] { keyValues[0] });
key0 = new MultiKey<>(new Object[] { keyValues[0] });
}
if (super.containsKey(key0))
super.remove(key0);
Expand Down Expand Up @@ -325,7 +326,7 @@
*/
@Override
public MultiKeyCoefficientMap clone() {
HashedMap mapClone = new HashedMap(this.decorated());
var mapClone = new HashedMap<>(this.decorated());
return new MultiKeyCoefficientMap(mapClone, this.getKeysNames(), this.getValuesNames());
}
}
7 changes: 3 additions & 4 deletions src/main/java/microsim/data/db/DatabaseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -253,7 +252,7 @@ public static EntityManager getEntityManger(boolean autoUpdate) {
try {
// Create the EntityManagerFactory

Map propertyMap = new HashMap();
var propertyMap = new HashMap<String, String>();
propertyMap.put("hibernate.connection.url", "jdbc:h2:file:" + databaseInputUrl);
entityManagerFactory = Persistence.createEntityManagerFactory("sim-model", propertyMap);

Expand All @@ -273,7 +272,7 @@ public static void inputSchemaUpdateEntityManger() {
try {

// Create the EntityManagerFactory
Map propertyMap = new HashMap();
var propertyMap = new HashMap<String, String>();
propertyMap.put("hibernate.connection.url", "jdbc:h2:file:" + DatabaseUtils.databaseInputUrl);
EntityManager em = Persistence.createEntityManagerFactory("sim-model", propertyMap)
.createEntityManager();
Expand Down Expand Up @@ -309,7 +308,7 @@ public static EntityManager getOutEntityManger(String persistenceUnitName) {
try {

// Create the EntityManagerFactory
Map propertyMap = new HashMap();
var propertyMap = new HashMap<String, String>();
propertyMap.put("hibernate.connection.url", "jdbc:h2:file:" + DatabaseUtils.databaseOutputUrl);
outEntityManagerFactory = Persistence.createEntityManagerFactory(persistenceUnitName, propertyMap);

Expand Down
12 changes: 3 additions & 9 deletions src/main/java/microsim/engine/SimulationEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ public class SimulationEngine extends Thread {

private ExperimentBuilder experimentBuilder = null;

/**
* @link dependency
* @stereotype use
* @supplierRole 1..
**/
/* #SimModel lnkSimModel; */

/**
* Build a new SimEngine with the given time unit.
*/
Expand Down Expand Up @@ -434,7 +427,7 @@ public void buildModels() {

try {
currentExperiment = ExperimentManager.getInstance().setupExperiment(currentExperiment,
models.toArray(new SimulationManager[models.size()]));
models.toArray());
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -467,13 +460,14 @@ public boolean getModelBuildStatus() {
*
* @return The list of disposed models.
*/
// FIXME: this should return a List<Class<SimulationManager>>
public synchronized Class<?>[] disposeModels() {
eventQueue.clear();

modelBuild = false;

// Get models' class type and dispose
Class<?>[] cls = new Class[models.size()];
var cls = new Class<?>[models.size()];
for (int i = 0; i < models.size(); i++) {
SimulationManager model = models.get(i);
cls[i] = model.getClass();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/microsim/event/CollectionTargetEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
*/
public CollectionTargetEvent(Collection<?> elements, Class<?> objectType,
String method, boolean readOnly) throws SimulationException {
setForObject(elements, objectType, method, readOnly);

Check warning on line 55 in src/main/java/microsim/event/CollectionTargetEvent.java

View workflow job for this annotation

GitHub Actions / build

possible 'this' escape before subclass is fully initialized

Check warning on line 55 in src/main/java/microsim/event/CollectionTargetEvent.java

View workflow job for this annotation

GitHub Actions / build

possible 'this' escape before subclass is fully initialized
}

/** Create a collection event using early binding method call. */
Expand All @@ -75,7 +75,7 @@
Class<?> cl = objectType;
while (cl != null)
try {
methodInvoker = cl.getDeclaredMethod(method, null);
methodInvoker = cl.getDeclaredMethod(method);
return;
} catch (NoSuchMethodException e) {
cl = cl.getSuperclass();
Expand Down Expand Up @@ -112,7 +112,7 @@
if (methodInvoker != null) {
while (itr.hasNext()) {
try {
methodInvoker.invoke(itr.next(), null);
methodInvoker.invoke(itr.next());
} catch (InvocationTargetException e) {
System.out.println("Object " + methodInvoker + " Method: "
+ methodInvoker.getName());
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/microsim/event/EventQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ public class EventQueue {
double time = 0;
// protected List<ISimEventListener> stepListeners;

/**
* @link dependency
* @supplierRole 1..
**/
/* #SimEvent lnkSimEvent; */

/** Build new event queue with TIME_TICKS time unit. */
public EventQueue() {
eventQueue = new PriorityQueue<Event>(10);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/microsim/event/SingleTargetEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void setForObject(Object o, String method) throws SimulationException {
Class<?> cl = o.getClass();
while (cl != null)
try {
methodInvoker = cl.getDeclaredMethod(method, null);
methodInvoker = cl.getDeclaredMethod(method);
return;
} catch (NoSuchMethodException e) {
cl = cl.getSuperclass();
Expand Down Expand Up @@ -105,7 +105,7 @@ public String toString() {
public void fireEvent() {
if (methodInvoker != null) {
try {
methodInvoker.invoke(object, null);
methodInvoker.invoke(object);
} catch (InvocationTargetException e) {
System.out.println("Object " + methodInvoker + " Method: "
+ methodInvoker.getName());
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/microsim/gui/colormap/DoubleRangeColorMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public DoubleRangeColorMap(int gradients, Color bottomColor, Color topColor,
for (int i = 0; i < gradients; i++) {
// int[] c = getComponents(getBoundedCol(i * gap));
int[] c = new int[] { 0, 0, 0 };
c[0] = redStart + (int) ((redEnd - redStart) * i / gradients);
c[1] = greenStart + (int) ((greenEnd - redStart) * i / gradients);
c[2] = blueStart + (int) ((blueEnd - redStart) * i / gradients);
c[0] = redStart + ((redEnd - redStart) * i / gradients);
c[1] = greenStart + ((greenEnd - redStart) * i / gradients);
c[2] = blueStart + ((blueEnd - redStart) * i / gradients);

addColor(i, new Color(c[0], c[1], c[2]));
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/microsim/gui/colormap/TripleRangeColorMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ public TripleRangeColorMap(int gradients, Color bottomColor, Color middleColor,
for (int i = 0; i < lowGradients; i++) {
// int[] c = getComponents(getBoundedCol(i * gap));
int[] c = new int[] { 0, 0, 0 };
c[0] = redStart + (int) ((redMiddle - redStart) * i / gradients);
c[1] = greenStart + (int) ((greenMiddle - greenStart) * i / gradients);
c[2] = blueStart + (int) ((blueMiddle - blueStart) * i / gradients);
c[0] = redStart + ((redMiddle - redStart) * i / gradients);
c[1] = greenStart + ((greenMiddle - greenStart) * i / gradients);
c[2] = blueStart + ((blueMiddle - blueStart) * i / gradients);

addColor(i, new Color(c[0], c[1], c[2]));
}

for (int i = lowGradients; i < gradients; i++) {
// int[] c = getComponents(getBoundedCol(i * gap));
int[] c = new int[] { 0, 0, 0 };
c[0] = redMiddle + (int) ((redEnd - redMiddle) * i / gradients);
c[1] = greenMiddle + (int) ((greenEnd - greenMiddle) * i / gradients);
c[2] = blueMiddle + (int) ((blueEnd - blueMiddle) * i / gradients);
c[0] = redMiddle + ((redEnd - redMiddle) * i / gradients);
c[1] = greenMiddle + ((greenEnd - greenMiddle) * i / gradients);
c[2] = blueMiddle + ((blueEnd - blueMiddle) * i / gradients);

addColor(i, new Color(c[0], c[1], c[2]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void onEvent(Enum<?> type) {

public void update() {
for (int i = 0; i < sources.size(); i++) {
ArraySource cs = (ArraySource) sources.get(i);
var cs = sources.get(i);
final String category = categories.get(i);

double[] vals = cs.getDoubleArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public void update() {
// chart.getXYPlot().getRenderer().setSeriesPaint(s, new Color(r, g, b, 130));

for (int i = 0; i < sources.size(); i++) {
ArraySource cs = (ArraySource) sources.get(i);
var cs = sources.get(i);
double[] vals = cs.getDoubleArray();

if (minimum != null && maximum != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import microsim.event.CommonEventType;
import microsim.event.EventListener;
import microsim.gui.colormap.ColorMap;
import microsim.gui.colormap.FixedColorMap;
import microsim.reflection.ReflectionUtils;
import microsim.statistics.IDoubleSource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package microsim.gui.plot;

//package microsim.gui.plot;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JInternalFrame;

Expand Down Expand Up @@ -773,10 +770,8 @@ public void setMaxSamples(int maxSamples) {

public void refresh() {

List data = dataset.getSeries();
for (int i = 0; i < data.size(); i++) {
XYSeries series = (XYSeries) data.get(i);
series.clear();
for (int i = 0; i < dataset.getSeriesCount(); i++) {
dataset.getSeries(i).clear();
}

}
Expand Down
Loading
Loading