Select to view content in your preferred language

Can I add Attribute with Mutable object to Immutable Graphic ?

4016
4
Jump to solution
11-25-2013 01:21 AM
JeremieJoalland1
Deactivated User
We would like to associate some POJOs as Attributes of our Graphics with :

  • Graphic(Geometry geometry, Symbol symbol, Map<String,Object> attributes, int drawOrder)

However, our POJOs are Mutable objects with seem not to be compliant with Immutable Graphic concept (from API Ref.) :

  • "Graphic objects are immutable..."

  • "getAttributes() returns all attributes of the graphic as a read-only collection."

So could somebody confirm to us, that using mutable objects as attributes values will not conflict with Graphic concept or behavior, as these mutable objects will be modified in parallel of their corresponding Graphic life cycle ?

(we currently develop with ArcGIS Runtime for Java 10.1.1, but will soon move to 10.2)
0 Kudos
1 Solution

Accepted Solutions
ColinAnderson1
Esri Contributor
Graphic is immutable - the attributes that you add are copied so you cannot change them throough a reference that you hold to the original attributes.

Once you have added a graphic to a GraphicsLayer you can use the returned ID to call update the on graphic - doing this will not change any instance of Graphic that you already hold. To get a Graphic instance with the updates you will have to call getGraphic using the ID which will give you a new graphic.

Finally, although you can add any object to the attributes the underlying core code will only support the types allowed by ESRI servers e.g. numbers, strings, dates etc. This means that your object will be turned into a string by calling toString on it since it is not one of the recognised types.

View solution in original post

0 Kudos
4 Replies
EricBader
Honored Contributor
There seems to be a bit of confusion here with the API Reference. This might be referring to graphic elements that come from non-editable FeatureServices.

Are you adding your own custom graphic elements with attributes and symbols to a normal GraphicsLayer? If so, these graphic elements are mutable, and your attributes are mutable. There should not be any problems here.
The way your described what you want to do sounds like it will work fine.
0 Kudos
JeremieJoalland1
Deactivated User
There seems to be a bit of confusion here with the API Reference. This might be referring to graphic elements that come from non-editable FeatureServices.

We are only refering to Graphic and GraphicsLayer, as we are drawing our own Point, Polyline and Polygon features.

Are you adding your own custom graphic elements with attributes and symbols to a normal GraphicsLayer? If so, these graphic elements are mutable, and your attributes are mutable. There should not be any problems here.
The way your described what you want to do sounds like it will work fine.

Yes to your question.

But I disagree for mutable graphic elements, as the ArcGIS Javadoc says "Graphic objects are immutable, ..." (-> please see the hyperlink on Graphic ion my first post).

From our tests, when we call Graphic Constructor and passes Attributes, it seems that Object from mutable Type are automatically converted to "String" type by calling .toString().
So Attributes seems to manage only String, boolean and Numeric (Integer, Double...) types.
Could ESRI confirm this point ? if Yes, the Javadoc could be improve to state the true behavior of Graphic and Attributes.
0 Kudos
ColinAnderson1
Esri Contributor
Graphic is immutable - the attributes that you add are copied so you cannot change them throough a reference that you hold to the original attributes.

Once you have added a graphic to a GraphicsLayer you can use the returned ID to call update the on graphic - doing this will not change any instance of Graphic that you already hold. To get a Graphic instance with the updates you will have to call getGraphic using the ID which will give you a new graphic.

Finally, although you can add any object to the attributes the underlying core code will only support the types allowed by ESRI servers e.g. numbers, strings, dates etc. This means that your object will be turned into a string by calling toString on it since it is not one of the recognised types.
0 Kudos
JeremieJoalland1
Deactivated User
Thanks for these precisions, confirmed by our test code.
It would be nice to have this documented in your API Reference/Javadoc.
0 Kudos