MATSIM
AttributesUtils.java
Go to the documentation of this file.
1 
2 /* *********************************************************************** *
3  * project: org.matsim.*
4  * AttributesUtils.java
5  * *
6  * *********************************************************************** *
7  * *
8  * copyright : (C) 2019 by the members listed in the COPYING, *
9  * LICENSE and WARRANTY file. *
10  * email : info at matsim dot org *
11  * *
12  * *********************************************************************** *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * See also COPYING, LICENSE and WARRANTY file *
19  * *
20  * *********************************************************************** */
21 
22  package org.matsim.utils.objectattributes.attributable;
23 
27 public class AttributesUtils {
28  public static final String ATTRIBUTES = "attributes";
29  public static final String ATTRIBUTE = "attribute";
30 
35  public static void copyTo( Attributes from , Attributes to ) {
36  for (var entry : from.getAsMap().entrySet()) {
37  to.putAttribute(entry.getKey(), entry.getValue());
38  }
39  }
40 
50  public static void copyToExcept(Attributes from, Attributes to, String exceptAttribute) {
51  for (var entry : from.getAsMap().entrySet()) {
52  String key = entry.getKey();
53  if (!key.equals(exceptAttribute)) {
54  to.putAttribute(key, entry.getValue());
55  }
56  }
57  }
58 
63  public static <T extends Attributable> void copyAttributesFromTo( T from , T to ) {
64  copyTo( from.getAttributes() , to.getAttributes() );
65  }
66 
76  public static <T extends Attributable> void copyAttributesFromToExcept(T from, T to, String exceptAttribute) {
77  copyToExcept(from.getAttributes(), to.getAttributes(), exceptAttribute);
78  }
79 
85  @Deprecated
86  public static boolean isEmpty(Attributes attributes) {
87  return attributes.size() == 0;
88  }
89 }
static< T extends Attributable > void copyAttributesFromTo(T from, T to)
static void copyTo(Attributes from, Attributes to)
static void copyToExcept(Attributes from, Attributes to, String exceptAttribute)
static< T extends Attributable > void copyAttributesFromToExcept(T from, T to, String exceptAttribute)
Object putAttribute(final String attribute, final Object value)