1 /**
2 * Copyright 2010 The Kuali Foundation Licensed under the
3 * Educational Community License, Version 2.0 (the "License"); you may
4 * not use this file except in compliance with the License. You may
5 * obtain a copy of the License at
6 *
7 * http://www.osedu.org/licenses/ECL-2.0
8 *
9 * Unless required by applicable law or agreed to in writing,
10 * software distributed under the License is distributed on an "AS IS"
11 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 * or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 package org.kuali.student.common.ui.client.logging;
17
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 /**
23 * Stores log messages, can be sent to log service.
24 */
25 @Deprecated
26 public class LogBuffer implements Serializable {
27 private static final long serialVersionUID = 1L;
28
29 int maxSize = Integer.MAX_VALUE;
30 List<LogMessage> buffer = new ArrayList<LogMessage>();
31
32 /**
33 * Creates an empty LogBuffer with a size limit of Integer.MAX_VALUE
34 */
35 public LogBuffer() {
36
37 }
38
39 /**
40 * Creates an empty LogBuffer with the specified size limit.
41 * When size limit is reached, older messages are removed as newer ones are added.
42 * @param maxSize
43 */
44 public LogBuffer(int maxSize) {
45 this.maxSize = maxSize;
46 }
47
48 /**
49 * Adds a message to the buffer
50 * @param message
51 */
52 public void add(LogMessage message) {
53 buffer.add(message);
54 checkLimit();
55 }
56
57 /**
58 * Returns the underlying log buffer.
59 * @return the underlying log buffer as List<LogMessage>
60 */
61 public List<LogMessage> getLogMessages() {
62 return buffer;
63 }
64 /**
65 * Removes excess messages, oldest first.
66 */
67 private void checkLimit() {
68 while (buffer.size() > maxSize) {
69 buffer.remove(0);
70 }
71 }
72 }