1 16 package org.apache.commons.collections.bag; 17 18 import java.util.Set ; 19 20 import org.apache.commons.collections.Bag; 21 import org.apache.commons.collections.Transformer; 22 import org.apache.commons.collections.collection.TransformedCollection; 23 import org.apache.commons.collections.set.TransformedSet; 24 25 40 public class TransformedBag 41 extends TransformedCollection implements Bag { 42 43 44 private static final long serialVersionUID = 5421170911299074185L; 45 46 57 public static Bag decorate(Bag bag, Transformer transformer) { 58 return new TransformedBag(bag, transformer); 59 } 60 61 72 protected TransformedBag(Bag bag, Transformer transformer) { 73 super(bag, transformer); 74 } 75 76 81 protected Bag getBag() { 82 return (Bag) collection; 83 } 84 85 public int getCount(Object object) { 87 return getBag().getCount(object); 88 } 89 90 public boolean remove(Object object, int nCopies) { 91 return getBag().remove(object, nCopies); 92 } 93 94 public boolean add(Object object, int nCopies) { 96 object = transform(object); 97 return getBag().add(object, nCopies); 98 } 99 100 public Set uniqueSet() { 101 Set set = getBag().uniqueSet(); 102 return TransformedSet.decorate(set, transformer); 103 } 104 105 } 106 | Popular Tags |