X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.fmil.core%2Fsrc%2Forg%2Fsimantics%2Ffmil%2Fcore%2FFMIL.java;h=0e413afcef29ff63c1cd7c98ee01044d917d7b6d;hb=a46781ce0c477e99fe27b9a2fca07bf76d1d480a;hp=ec63279c89feb1e982b3e79e254f77713afccac6;hpb=7ce2309e8267b8ad29d073dbaac74a83921e9af4;p=simantics%2Ffmil.git diff --git a/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java b/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java index ec63279..0e413af 100644 --- a/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java +++ b/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java @@ -123,7 +123,9 @@ public class FMIL { private String[] declaredTypeQuantities; private String[] declaredTypeUnits; - private TObjectIntHashMap variableMap = new TObjectIntHashMap(); + private static int NO_VARIABLE_KEY = -1; + + private TObjectIntHashMap variableMap = new TObjectIntHashMap(10, 0.5f, NO_VARIABLE_KEY); private Set subscriptionSet = new HashSet(); private TIntArrayList subscription = new TIntArrayList(); @@ -137,7 +139,7 @@ public class FMIL { synchronized(syncObject) { // Safety check int vr = variableMap.get(name); - if(vr == 0) return false; + if(vr == NO_VARIABLE_KEY) return false; if(!subscriptionSet.add(name)) return false; subscribedNames.add(name); subscription.add(vr); @@ -358,7 +360,10 @@ public class FMIL { * @throws FMILException */ public void setRealValue(String name, double value) throws FMILException { - setRealValue(variableMap.get(name), value); + int key = variableMap.get(name); + if(key == NO_VARIABLE_KEY) + throw new FMILException("No variable with name " + name); + setRealValue(key, value); } /** @@ -397,7 +402,10 @@ public class FMIL { * @throws FMILException */ public void setIntegerValue(String name, int value) throws FMILException { - setIntegerValue(variableMap.get(name), value); + int key = variableMap.get(name); + if(key == NO_VARIABLE_KEY) + throw new FMILException("No variable with name " + name); + setIntegerValue(key, value); } /** @@ -436,7 +444,10 @@ public class FMIL { * @throws FMILException */ public void setBooleanValue(String name, boolean value) throws FMILException { - setBooleanValue(variableMap.get(name), value); + int key = variableMap.get(name); + if(key == NO_VARIABLE_KEY) + throw new FMILException("No variable with name " + name); + setBooleanValue(key, value); } /** @@ -475,7 +486,10 @@ public class FMIL { * @throws FMILException */ public void setStringValue(String name, String value) throws FMILException { - setStringValue(variableMap.get(name), value); + int key = variableMap.get(name); + if(key == NO_VARIABLE_KEY) + throw new FMILException("No variable with name " + name); + setStringValue(key, value); } /** @@ -918,7 +932,10 @@ public class FMIL { * @throws FMILException */ public double getRealValue(String name) throws FMILException { - double result = getRealValue(variableMap.get(name)); + int key = variableMap.get(name); + if(key == NO_VARIABLE_KEY) + throw new FMILException("No variable with name " + name); + double result = getRealValue(key); if (DEBUG) System.err.println("getRealValue " + name + " = " + result); return result; } @@ -951,7 +968,10 @@ public class FMIL { * @throws FMILException */ public int getIntegerValue(String name) throws FMILException { - int result = getIntegerValue(variableMap.get(name)); + int key = variableMap.get(name); + if(key == NO_VARIABLE_KEY) + throw new FMILException("No variable with name " + name); + int result = getIntegerValue(key); if (DEBUG) System.err.println("getIntegerValue " + name + " = " + result); return result; } @@ -984,7 +1004,10 @@ public class FMIL { * @throws FMILException */ public boolean getBooleanValue(String name) throws FMILException { - boolean result = getBooleanValue(variableMap.get(name)); + int key = variableMap.get(name); + if(key == NO_VARIABLE_KEY) + throw new FMILException("No variable with name " + name); + boolean result = getBooleanValue(key); if (DEBUG) System.err.println("getBooleanValue " + name + " = " + result); return result; } @@ -1017,7 +1040,10 @@ public class FMIL { * @throws FMILException */ public String getStringValue(String name) throws FMILException { - String result = getStringValue(variableMap.get(name)); + int key = variableMap.get(name); + if(key == NO_VARIABLE_KEY) + throw new FMILException("No variable with name " + name); + String result = getStringValue(key); if (DEBUG) System.err.println("getIntegerValue " + name + " = " + result); return result; }