KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > util > WindowUtil


1 /**
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.util;
5
6 import com.tc.text.PrettyPrintable;
7 import com.tc.text.PrettyPrinter;
8
9 import java.util.Iterator JavaDoc;
10 import java.util.LinkedList JavaDoc;
11 import java.util.List JavaDoc;
12
13 public class WindowUtil implements PrettyPrintable {
14   private final int size;
15   private final List JavaDoc list;
16   public WindowUtil(int size) {
17     this.size = size;
18     this.list = new LinkedList JavaDoc();
19   }
20   
21   public void add(Object JavaDoc 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 JavaDoc i=list.iterator(); i.hasNext(); ) {
36           out.indent().visit(i.next()).println();
37         }
38       }
39       return rv;
40   }
41 }
42
Popular Tags