MATSIM
ObjectAttributesUtils.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * *
4  * *********************************************************************** *
5  * *
6  * copyright : (C) 2013 by the members listed in the COPYING, *
7  * LICENSE and WARRANTY file. *
8  * email : info at matsim dot org *
9  * *
10  * *********************************************************************** *
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * See also COPYING, LICENSE and WARRANTY file *
17  * *
18  * *********************************************************************** */
19 
20 package org.matsim.utils.objectattributes;
21 
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.IdentityHashMap;
25 import java.util.Map;
26 
30 public final class ObjectAttributesUtils {
31 
33  // abstract helper class
34  }
35 
36  public static void copyAllAttributes(ObjectAttributes source, ObjectAttributes destination, String objectId) {
37  Map<String, Object> sAttrs = source.attributes.get(objectId);
38  if (sAttrs != null) {
39  Map<String, Object> dAttrs = destination.attributes.get(objectId);
40  if (dAttrs == null) {
41  dAttrs = new IdentityHashMap<String, Object>();
42  destination.attributes.put(objectId, dAttrs);
43  }
44  dAttrs.putAll(sAttrs);
45  }
46  }
47 
48  public static Collection<String> getAllAttributeNames(ObjectAttributes attributes, final String objectId) {
49  Map<String, Object> map = attributes.attributes.get(objectId);
50  if (map == null) {
51  return Collections.emptyList();
52  }
53  return Collections.unmodifiableCollection(map.keySet());
54  }
55 
56 }
static Collection< String > getAllAttributeNames(ObjectAttributes attributes, final String objectId)
static void copyAllAttributes(ObjectAttributes source, ObjectAttributes destination, String objectId)