1 4 package com.tc.util; 5 6 import com.tc.text.PrettyPrintable; 7 import com.tc.text.PrettyPrinter; 8 9 import java.util.Iterator ; 10 import java.util.LinkedList ; 11 import java.util.List ; 12 13 public class WindowUtil implements PrettyPrintable { 14 private final int size; 15 private final List list; 16 public WindowUtil(int size) { 17 this.size = size; 18 this.list = new LinkedList (); 19 } 20 21 public void add(Object o) { 22 synchronized (list) { 23 if (list.size() == size) { 24 list.remove(0); 25 } 26 list.add(o); 27 } 28 } 29 30 public PrettyPrinter prettyPrint(PrettyPrinter out) { 31 out.println("WindowUtil"); 32 PrettyPrinter rv = out; 33 out = out.duplicateAndIndent(); 34 synchronized (list) { 35 for (Iterator i=list.iterator(); i.hasNext(); ) { 36 out.indent().visit(i.next()).println(); 37 } 38 } 39 return rv; 40 } 41 } 42 | Popular Tags |