User Tools

Site Tools


usingahashmapinavalueobject

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
usingahashmapinavalueobject [2026/01/25 20:47] – wikiadminusingahashmapinavalueobject [2026/01/25 21:07] (current) – [Setting up the ValueObject "MAP" Property] wikiadmin
Line 28: Line 28:
 map.put("age",50); map.put("age",50);
 map.put("name","Joe Doe"); map.put("name","Joe Doe");
-map.put("color",new java.awt.Color(java.awt.Color.green)); //you can put Objects into the HashMap+map.put("color",java.awt.Color.green); //you can put Objects into the HashMap
  
 //add the "map" to a ValueObject so we can pass this to the script //add the "map" to a ValueObject so we can pass this to the script
Line 34: Line 34:
 vo = new LongValueObject(100); //the value can be used by the script, or ignored vo = new LongValueObject(100); //the value can be used by the script, or ignored
  
-vo.addProperty("MAP",map); //this is all you need to do before you send the value to the script+vo.setProperty("MAP",map); //this is all you need to do before you send the value to the script
  
 //send it to the script //send it to the script
  
-/Devices/UtilityServers_Servers/CalculateSomething->setValueObject(vo); //must use setValueObject so the MAP property is not striped+/Devices/UtilityServers_Servers/CalculateSomething->setValueObject(vo); //must use setValueObject so the MAP property is not striped (not, for example, setLongValue())
  
 </code> </code>
Line 44: Line 44:
 ==== Using the MAP property in your Script ==== ==== Using the MAP property in your Script ====
  
 +An example of a script which extracts the MAP property and gets the various values based on the key
  
 +<code javascript>
 +
 +if (incomingValue.getQuality()==0) {
 +
 + //following from the above example, incomingValue is a LongValueObject with a property called "MAP" which contains a HashMap of key/value pairs
 +
 +vo = incomingValue;
 +map = incomingValue.getProperty("MAP");
 +
 +//you can test what class map is as a sanity check
 +print("The MAP property is a "+map.getClass().getName()); //works as long as map is not null
 +
 +value1 = map.get("name");
 +value2 = map.get("age");
 +color = map.get("color"); //this is an awt Color object
 +//test color, get the r,g,b values
 +print("color is:" + "r:"+color.getRed()+" g:"+color.getGreen()+" b:"+color.getBlue());
 +
 +//you can use the values passed in the MAP property in your script....
 +
 +}
 +incomingValue;
 +
 +
 +</code>
  
usingahashmapinavalueobject.1769392046.txt.gz · Last modified: by wikiadmin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki