1 4 package com.tc.config.schema.dynamic; 5 6 import com.tc.util.Assert; 7 8 11 public class SummingIntConfigItem implements IntConfigItem { 12 13 private final IntConfigItem[] children; 14 15 public SummingIntConfigItem(IntConfigItem[] children) { 16 Assert.assertNoNullElements(children); 17 this.children = children; 18 } 19 20 public int getInt() { 21 long out = 0; 22 for (int i = 0; i < children.length; ++i) { 23 out += children[i].getInt(); 24 } 25 26 if (out > Integer.MAX_VALUE) return Integer.MAX_VALUE; 28 else return (int) out; 29 } 30 31 public Object getObject() { 32 return new Integer (getInt()); 33 } 34 35 public void addListener(ConfigItemListener changeListener) { 36 for (int i = 0; i < this.children.length; ++i) 37 children[i].addListener(changeListener); 38 } 39 40 public void removeListener(ConfigItemListener changeListener) { 41 for (int i = 0; i < this.children.length; ++i) 42 children[i].removeListener(changeListener); 43 } 44 45 } 46 | Popular Tags |