001/* *********************************************************************** * 002 * project: org.matsim.* 003 * * 004 * *********************************************************************** * 005 * * 006 * copyright : (C) 2016 by the members listed in the COPYING, * 007 * LICENSE and WARRANTY file. * 008 * email : info at matsim dot org * 009 * * 010 * *********************************************************************** * 011 * * 012 * This program is free software; you can redistribute it and/or modify * 013 * it under the terms of the GNU General Public License as published by * 014 * the Free Software Foundation; either version 2 of the License, or * 015 * (at your option) any later version. * 016 * See also COPYING, LICENSE and WARRANTY file * 017 * * 018 * *********************************************************************** */ 019 020package org.matsim.contrib.util; 021 022public abstract class AbstractEnumAdder<K extends Enum<K>, N extends Number> implements EnumAdder<K, N> { 023 protected final K[] keys; 024 025 public AbstractEnumAdder(Class<K> clazz) { 026 this.keys = clazz.getEnumConstants(); 027 } 028 029 public K[] getKeys() { 030 return keys; 031 032 } 033 034 public void increment(K e) { 035 add(e, 1);// (Integer)1 is cached internally by JVM, so shouldn't be so costly 036 } 037 038 @Override 039 public void addAll(EnumAdder<K, ?> enumAdder) { 040 for (K e : keys) { 041 add(e, enumAdder.get(e)); 042 } 043 } 044}