001 002/* *********************************************************************** * 003 * project: org.matsim.* 004 * AttributesUtils.java 005 * * 006 * *********************************************************************** * 007 * * 008 * copyright : (C) 2019 by the members listed in the COPYING, * 009 * LICENSE and WARRANTY file. * 010 * email : info at matsim dot org * 011 * * 012 * *********************************************************************** * 013 * * 014 * This program is free software; you can redistribute it and/or modify * 015 * it under the terms of the GNU General Public License as published by * 016 * the Free Software Foundation; either version 2 of the License, or * 017 * (at your option) any later version. * 018 * See also COPYING, LICENSE and WARRANTY file * 019 * * 020 * *********************************************************************** */ 021 022 package org.matsim.utils.objectattributes.attributable; 023 024/** 025 * @author thibautd 026 */ 027public class AttributesUtils { 028 public static final String ATTRIBUTES = "attributes"; 029 public static final String ATTRIBUTE = "attribute"; 030 031 /** 032 * Adds the mappings from "from" to "to". Nothing is done to copy the Object themselves, 033 * which should be fine for 99.9% of the usecases of Attributes (value objects) 034 */ 035 public static void copyTo( Attributes from , Attributes to ) { 036 for (var entry : from.getAsMap().entrySet()) { 037 to.putAttribute(entry.getKey(), entry.getValue()); 038 } 039 } 040 041 /** 042 * Adds the mappings from "from" to "to". Nothing is done to copy the Object themselves, 043 * which should be fine for 99.9% of the usecases of Attributes (value objects) 044 */ 045 public static <T extends Attributable> void copyAttributesFromTo( T from , T to ) { 046 copyTo( from.getAttributes() , to.getAttributes() ); 047 } 048 049 /** 050 * @param attributes collection of attributes 051 * @return <code>true</code> if the attributes collection does not contain any attribute 052 * @deprecated use {@link Attributes#isEmpty()} instead 053 */ 054 @Deprecated 055 public static boolean isEmpty(Attributes attributes) { 056 return attributes.size() == 0; 057 } 058}