1 16 package org.apache.commons.collections.bag; 17 18 import java.io.IOException ; 19 import java.io.ObjectInputStream ; 20 import java.io.ObjectOutputStream ; 21 import java.io.Serializable ; 22 import java.util.Collection ; 23 import java.util.Comparator ; 24 import java.util.SortedMap ; 25 import java.util.TreeMap ; 26 27 import org.apache.commons.collections.SortedBag; 28 29 48 public class TreeBag 49 extends AbstractMapBag implements SortedBag, Serializable { 50 51 52 static final long serialVersionUID = -7740146511091606676L; 53 54 57 public TreeBag() { 58 super(new TreeMap ()); 59 } 60 61 67 public TreeBag(Comparator comparator) { 68 super(new TreeMap (comparator)); 69 } 70 71 77 public TreeBag(Collection coll) { 78 this(); 79 addAll(coll); 80 } 81 82 public Object first() { 84 return ((SortedMap ) getMap()).firstKey(); 85 } 86 87 public Object last() { 88 return ((SortedMap ) getMap()).lastKey(); 89 } 90 91 public Comparator comparator() { 92 return ((SortedMap ) getMap()).comparator(); 93 } 94 95 99 private void writeObject(ObjectOutputStream out) throws IOException { 100 out.defaultWriteObject(); 101 out.writeObject(comparator()); 102 super.doWriteObject(out); 103 } 104 105 108 private void readObject(ObjectInputStream in) throws IOException , ClassNotFoundException { 109 in.defaultReadObject(); 110 Comparator comp = (Comparator ) in.readObject(); 111 super.doReadObject(new TreeMap (comp), in); 112 } 113 114 } 115 | Popular Tags |