Commit 0b74cc7f authored by Thibaut Démare's avatar Thibaut Démare

Add the 'add node attribute' command

parent 94d0cab6
......@@ -42,6 +42,21 @@ global {
// Step
gs_step gs_sender_id:"test1" gs_step_number:1;
// Add attributes on node
// A string attribute
gs_add_node_attribute gs_sender_id:"test1" gs_node_id:"node1" gs_attribute_name:"string" gs_attribute_value:"a string value";
// A double attribute
gs_add_node_attribute gs_sender_id:"test1" gs_node_id:"node1" gs_attribute_name:"double" gs_attribute_value:10.0;
// An integer attribute
gs_add_node_attribute gs_sender_id:"test1" gs_node_id:"node1" gs_attribute_name:"integer" gs_attribute_value:1;
// A boolean attribute
gs_add_node_attribute gs_sender_id:"test1" gs_node_id:"node1" gs_attribute_name:"boolean" gs_attribute_value:true;
// A list attribute
gs_add_node_attribute gs_sender_id:"test1" gs_node_id:"node1" gs_attribute_name:"list" gs_attribute_value:[1,2,3];
// Step
gs_step gs_sender_id:"test1" gs_step_number:2;
// Clear
gs_clear gs_sender_id:"test1";
......
package org.graphstream.gama.extension.sender;
import msi.gama.precompiler.ISymbolKind;
import msi.gama.precompiler.GamlAnnotations.facet;
import msi.gama.precompiler.GamlAnnotations.facets;
import msi.gama.precompiler.GamlAnnotations.inside;
import msi.gama.precompiler.GamlAnnotations.symbol;
import msi.gama.runtime.IScope;
import msi.gama.runtime.exceptions.GamaRuntimeException;
import msi.gaml.descriptions.IDescription;
import msi.gaml.expressions.IExpression;
import msi.gaml.statements.AbstractStatement;
import msi.gaml.statements.IStatement;
import msi.gaml.types.IType;
import org.graphstream.gama.extension.GSManager;
import org.graphstream.gama.extension.IKeywordGSAdditional;
@symbol(name = IKeywordGSAdditional.ADD_NODE_ATTRIBUTE, kind = ISymbolKind.SINGLE_STATEMENT, with_sequence = false)
@inside(kinds = { ISymbolKind.BEHAVIOR, ISymbolKind.SINGLE_STATEMENT })
@facets(value = { @facet(name = IKeywordGSAdditional.SENDERID, type = IType.STRING, optional = false),
@facet(name = IKeywordGSAdditional.NODE_ID, type = IType.STRING, optional = false),
@facet(name = IKeywordGSAdditional.ATTRIBUTE_NAME, type = IType.STRING, optional = false),
@facet(name = IKeywordGSAdditional.ATTRIBUTE_VALUE, type = IType.NONE, optional = false)})
public class AddNodeAttributeStatement extends AbstractStatement implements IStatement{
final IExpression senderid;
final IExpression nodeid;
final IExpression attname;
final IExpression attval;
public AddNodeAttributeStatement(IDescription desc) {
super(desc);
senderid = getFacet(IKeywordGSAdditional.SENDERID);
nodeid = getFacet(IKeywordGSAdditional.NODE_ID);
attname = getFacet(IKeywordGSAdditional.ATTRIBUTE_NAME);
attval = getFacet(IKeywordGSAdditional.ATTRIBUTE_VALUE);
}
@Override
protected Object privateExecuteIn(IScope scope) throws GamaRuntimeException {
String s = (String)(senderid.value(scope));
String eid = (String)(nodeid.value(scope));
String an = (String)(attname.value(scope));
Object av = attval.value(scope);
GSSender sender = GSManager.getSender(s);
// If it is a GamaList, it must be cast to an array
if(av instanceof msi.gama.util.GamaList){
Object[] av_ar = ((msi.gama.util.GamaList) av).toArray();
sender.sendNodeAttributeAdded(eid, an, av_ar);
}
else {
sender.sendNodeAttributeAdded(eid, an, av);
}
return null;
}
}
\ No newline at end of file
......@@ -55,9 +55,9 @@ public class GSSender {
nsSender.graphAttributeAdded(sourceId, newEvent(), attribute, value);
}
public void sendNodeAttributeAdded(long nodeId, String attribute,
public void sendNodeAttributeAdded(String nodeId, String attribute,
Object value) {
nsSender.nodeAttributeAdded(sourceId, newEvent(), nodeId + "",
nsSender.nodeAttributeAdded(sourceId, newEvent(), nodeId,
attribute, value);
}
......@@ -71,8 +71,8 @@ public class GSSender {
nsSender.graphAttributeRemoved(sourceId, newEvent(), attribute);
}
public void sendNodeAttributeRemoved(long nodeId, String attribute) {
nsSender.nodeAttributeRemoved(sourceId, newEvent(), nodeId + "",
public void sendNodeAttributeRemoved(String nodeId, String attribute) {
nsSender.nodeAttributeRemoved(sourceId, newEvent(), nodeId,
attribute);
}
......
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