Skip to content
This repository has been archived by the owner on Oct 31, 2020. It is now read-only.

Commit

Permalink
Fix get/setMetadata to create the Map if null
Browse files Browse the repository at this point in the history
This is needed to handle recreating a node from a quickfile
  • Loading branch information
tcstewar committed Apr 16, 2013
1 parent 1207c52 commit d0a8cfa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public abstract class AbstractEnsemble implements Ensemble, Probeable, VisiblyMu
private Map<String, Origin> myOrigins;
private Map<String, EnsembleTermination> myTerminations;

private transient Map<String, Object> myData;
private transient Map<String, Object> myMetadata;

/**
* Note that setMode(SimulationMode.DEFAULT) is called at construction time.
Expand Down Expand Up @@ -117,11 +117,16 @@ private void init() {
myStateNames = findStateNames(myNodes);
myListeners = new ArrayList<Listener>(3);

myData = new LinkedHashMap<String, Object>(2);
}

public Object getMetadata(String key) {return myData.get(key);}
public void setMetadata(String key, Object value) {myData.put(key, value);}
public Object getMetadata(String key) {
if (myMetadata==null) myMetadata = new LinkedHashMap<String, Object>(2);
return myMetadata.get(key);
}
public void setMetadata(String key, Object value) {
if (myMetadata==null) myMetadata = new LinkedHashMap<String, Object>(2);
myMetadata.put(key, value);
}


/**
Expand Down
16 changes: 10 additions & 6 deletions simulator/src/java/main/ca/nengo/model/impl/NetworkImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public class NetworkImpl implements Network, VisiblyMutable, VisiblyMutable.List

private transient Collection<StepListener> myStepListeners;

private transient Map<String, Object> myData;
private transient Map<String, Object> myMetadata;



Expand All @@ -141,9 +141,7 @@ public NetworkImpl() {
OrderedExposedOrigins = new LinkedList <Origin> ();
OrderedExposedTerminations = new LinkedList <Termination> ();

myStepListeners = new ArrayList<StepListener>(1);

myData = new LinkedHashMap<String, Object>(2);
myStepListeners = new ArrayList<StepListener>(1);
}

/**
Expand Down Expand Up @@ -1638,6 +1636,12 @@ public String toPostScript(HashMap<String, Object> scriptData) throws ScriptGenE
return py.toString();
}

public Object getMetadata(String key) {return myData.get(key);}
public void setMetadata(String key, Object value) {myData.put(key, value);}
public Object getMetadata(String key) {
if (myMetadata==null) myMetadata = new LinkedHashMap<String, Object>(2);
return myMetadata.get(key);
}
public void setMetadata(String key, Object value) {
if (myMetadata==null) myMetadata = new LinkedHashMap<String, Object>(2);
myMetadata.put(key, value);
}
}

0 comments on commit d0a8cfa

Please sign in to comment.