Commit 64178c3c authored by Thibaut Démare's avatar Thibaut Démare

Make the plugin be compatible with last version of GAMA (SVN)

parent 21ec003d
......@@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import msi.gama.runtime.IScope;
import msi.gama.runtime.exceptions.GamaRuntimeException;
import org.graphstream.gama.extension.receiver.GSReceiver;
......@@ -104,13 +105,13 @@ public class GSManager {
return receiver;
}
public static void addReceiver(String receiverId, String host, int port,
public static void addReceiver(IScope scope, String receiverId, String host, int port,
Set<String> attributeFilter) throws GamaRuntimeException {
GSReceiver receiver = receivers.get(receiverId);
if (receiver != null)
throw new RuntimeException("Receiver \"" + receiverId
+ "\" already exists");
receiver = new GSReceiver(sinkTime, host, port, attributeFilter);
receiver = new GSReceiver(scope, sinkTime, host, port, attributeFilter);
receivers.put(receiverId, receiver);
}
......
......@@ -77,7 +77,7 @@ public class AddReceiverStatement extends AbstractStatement implements IStatemen
Set filterSet = null;
if(filter != null)
filterSet = new HashSet((msi.gama.util.GamaList) filter.value(scope));
GSManager.addReceiver(r, h, p, filterSet);
GSManager.addReceiver(scope, r, h, p, filterSet);
return null;
}
}
\ No newline at end of file
......@@ -22,7 +22,9 @@ package org.graphstream.gama.extension.receiver;
import java.util.HashMap;
import java.util.Map;
import msi.gama.runtime.IScope;
import msi.gama.util.GamaList;
import msi.gama.util.GamaListFactory;
/**
......@@ -48,30 +50,30 @@ public class Attributes {
return map.remove(attribute);
}
public void add(String attribute, Object value) {
Object gamaValue = netStreamToGama(value);
public void add(IScope scope, String attribute, Object value) {
Object gamaValue = netStreamToGama(scope, value);
if (gamaValue == null)
return;
GamaList list = map.get(attribute);
if (list == null) {
list = new GamaList();
list = GamaListFactory.EMPTY_LIST;
map.put(attribute, list);
}
list.add(gamaValue);
list.addValue(scope, gamaValue);
}
protected static Object netStreamToGama(Object o) {
protected static Object netStreamToGama(IScope scope, Object o) {
Object result = simpleNetStreamToGama(o);
if (result != null)
return result;
if (!o.getClass().isArray())
return null;
GamaList list = new GamaList();
GamaList list = GamaListFactory.EMPTY_LIST;
for (Object element : (Object[]) o) {
Object gamaElement = simpleNetStreamToGama(element);
if (gamaElement == null)
return null;
list.add(gamaElement);
list.addValue(scope, gamaElement);
}
return list;
}
......
......@@ -27,6 +27,7 @@ import java.util.Map;
import java.util.Queue;
import java.util.Set;
import msi.gama.runtime.IScope;
import msi.gama.runtime.exceptions.GamaRuntimeException;
import msi.gama.util.GamaList;
......@@ -55,9 +56,11 @@ public class GSReceiver extends SinkAdapter {
protected Map<String, Attributes> edgeAttributes;
protected Queue<Double> steps;
protected Set<String> attributeFilter;
public GSReceiver(SinkTime sinkTime, String host, int port,
protected IScope scope;
public GSReceiver(IScope scope, SinkTime sinkTime, String host, int port,
Set<String> attributeFilter) throws GamaRuntimeException {
this.scope = scope;
this.sinkTime = sinkTime;
this.attributeFilter = attributeFilter;
try {
......@@ -133,7 +136,7 @@ public class GSReceiver extends SinkAdapter {
a = new Attributes();
edgeAttributes.put(edgeId, a);
}
a.add(attribute, value);
a.add(scope, attribute, value);
}
}
......@@ -149,7 +152,7 @@ public class GSReceiver extends SinkAdapter {
if (sinkTime.isNewEvent(sourceId, timeId)
&& (attributeFilter == null || attributeFilter
.contains(attribute)))
graphAttributes.add(attribute, value);
graphAttributes.add(scope, attribute, value);
}
@Override
......@@ -169,7 +172,7 @@ public class GSReceiver extends SinkAdapter {
a = new Attributes();
nodeAttributes.put(nodeId, a);
}
a.add(attribute, value);
a.add(scope, attribute, value);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment