01: /**
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */package com.tc.util;
04:
05: import com.tc.text.PrettyPrintable;
06: import com.tc.text.PrettyPrinter;
07:
08: import java.util.Iterator;
09: import java.util.LinkedList;
10: import java.util.List;
11:
12: public class WindowUtil implements PrettyPrintable {
13: private final int size;
14: private final List list;
15:
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: }
|