MATSIM
Public Member Functions | List of all members
org.matsim.utils.objectattributes.ObjectAttributes Class Reference
Inheritance diagram for org.matsim.utils.objectattributes.ObjectAttributes:
Inheritance graph
[legend]

Public Member Functions

String toString ()
 
Object putAttribute (final String objectId, final String attribute, final Object value)
 
Object getAttribute (final String objectId, final String attribute)
 
Object removeAttribute (final String objectId, final String attribute)
 
void removeAllAttributes (final String objectId)
 
void clear ()
 

Detailed Description

A simple helper class to store arbitrary attributes (identified by Strings) for arbitrary objects (identified by String-Ids). Note that this implementation uses large amounts of memory for storing many attributes for many objects, it is not heavily optimized.

This class is not thread-safe.

More information can be found in the package's Javadoc.

Example(s):

Author
mrieser

Definition at line 44 of file ObjectAttributes.java.

Member Function Documentation

◆ toString()

String org.matsim.utils.objectattributes.ObjectAttributes.toString ( )

Definition at line 49 of file ObjectAttributes.java.

49  {
50  StringBuilder stb = new StringBuilder() ;
51  for ( Entry<String, Map<String,Object>> entry : attributes.entrySet() ) {
52  String key = entry.getKey() ;
53  stb.append("key=").append(key);
54  Map<String,Object> map = entry.getValue() ;
55  for ( Entry<String,Object> ee : map.entrySet() ) {
56  String subkey = ee.getKey();
57  stb.append("; subkey=").append(subkey);
58  stb.append("; object=").append(ee.getValue().toString());
59  }
60  stb.append("\n") ;
61  }
62  return stb.toString() ;
63  }

◆ putAttribute()

Object org.matsim.utils.objectattributes.ObjectAttributes.putAttribute ( final String  objectId,
final String  attribute,
final Object  value 
)

Definition at line 65 of file ObjectAttributes.java.

Referenced by org.matsim.utils.objectattributes.ObjectAttributesXmlReader.endTag(), and org.matsim.utils.objectattributes.RunObjectAttributesExample.main().

65  {
66  Map<String, Object> attMap = this.attributes.get(objectId);
67  if (attMap == null) {
68  attMap = new IdentityHashMap<String, Object>(5);
69  this.attributes.put(objectId, attMap);
70  }
71  return attMap.put(attribute.intern(), value);
72  }

◆ getAttribute()

Object org.matsim.utils.objectattributes.ObjectAttributes.getAttribute ( final String  objectId,
final String  attribute 
)

Definition at line 74 of file ObjectAttributes.java.

Referenced by org.matsim.utils.objectattributes.RunObjectAttributesExample.filterByAttributes().

74  {
75  Map<String, Object> attMap = this.attributes.get(objectId);
76  if (attMap == null) {
77  return null;
78  }
79  return attMap.get(attribute.intern());
80  }

◆ removeAttribute()

Object org.matsim.utils.objectattributes.ObjectAttributes.removeAttribute ( final String  objectId,
final String  attribute 
)

Definition at line 82 of file ObjectAttributes.java.

82  {
83  Map<String, Object> attMap = this.attributes.get(objectId);
84  if (attMap == null) {
85  return null;
86  }
87  return attMap.remove(attribute.intern());
88  }

◆ removeAllAttributes()

void org.matsim.utils.objectattributes.ObjectAttributes.removeAllAttributes ( final String  objectId)

Definition at line 90 of file ObjectAttributes.java.

90  {
91  this.attributes.remove(objectId);
92  }

◆ clear()

void org.matsim.utils.objectattributes.ObjectAttributes.clear ( )

Deletes all attributes of all objects, and all objects-ids.

Definition at line 97 of file ObjectAttributes.java.

97  {
98  this.attributes.clear();
99  }

The documentation for this class was generated from the following file: