From: SVN by r. <sv...@ca...> - 2008-07-28 20:54:22
|
Author: roy Date: 2008-07-28 22:54:09 +0200 (Mon, 28 Jul 2008) New Revision: 273 Added: src/main/java/nl/improved/sqlclient/Screen.java src/main/java/nl/improved/sqlclient/util/LimitedArrayList.java Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java Log: restructure of source code made it (hopefully) a little more readable and extendable still lots todo though ;( Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-07-28 20:20:24 UTC (rev 272) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-07-28 20:54:09 UTC (rev 273) @@ -47,6 +47,7 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import nl.improved.sqlclient.commands.*; +import nl.improved.sqlclient.util.LimitedArrayList; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -63,27 +64,6 @@ */ private CommandThread commandThread; /** - * True when the prompt should be visible. - * Normally it is not visible during the execution of a command - */ - protected boolean showPrompt = true; - - /** - * The (default) maximum matches to show in a selection dialog. - */ - protected static final int MAX_MATCH_SIZE = 15; - protected int MAX_LINE_LENGTH; // not static and final.. since it can change on window resize - - /** - * Page up count 0 means were at the bottom of our screen. - * Increasement of the pageup count moves the visible part of the screen up. - */ - protected int pageUpCount = 0; - /** - * All lines in a screen. - */ - protected List<CharSequence> screenBuffer = new LimitedArrayList<CharSequence>(1000); - /** * The current command lines. */ protected SQLCommand commandLines; @@ -94,22 +74,8 @@ /** * Index for browsing commands. */ - protected int commandIndex = 0; + private int commandIndex = 0; /** - * An empty line for easy line completion (fill with spaces). - */ - protected String emptyLine; - /** - * The cursor position in the command lines list. - * 0,0 means it is at the first line at the first character - * 10,5 means it is at the 11th character at the 6th line - */ - protected Point cursorPosition = new Point(0,0); - /** - * The prompt to show when entering sql commands. - */ - protected static final String PROMPT = "SQL"; - /** * Some debug info holding the last trace of an exception. */ private String lastExceptionDetails; @@ -125,6 +91,8 @@ private ArrayBlockingQueue<CommandInfo> commandQueue = new ArrayBlockingQueue<CommandInfo>(10, true); // true means fair + private Screen screen; + /** * A map of string key representation to a action that should be executed when a specific key is pressed. */ @@ -137,9 +105,10 @@ * Constructor. */ public AbstractSQLShellWindow() { + screen = new Screen(); char[] emptyLineChar = new char[getScreenWidth()]; Arrays.fill(emptyLineChar, ' '); - emptyLine = new String(emptyLineChar); + screen.setEmptyLine(new String(emptyLineChar)); // initialize the command shell commandLines = new SQLCommand(); @@ -167,6 +136,7 @@ specialActionKeys.put(InputKey.SpecialKey.LEFT, new KeyAction() { @Override public void execute() { + Point cursorPosition = screen.getCursorPosition(); if (cursorPosition.x > 0) { cursorPosition.x--; } else if (cursorPosition.y > 0) { @@ -182,6 +152,7 @@ specialActionKeys.put(InputKey.SpecialKey.RIGHT, new KeyAction() { @Override public void execute() { + Point cursorPosition = screen.getCursorPosition(); CharSequence tmp = commandLines.getLines().get(cursorPosition.y); if (cursorPosition.x < tmp.length()) { cursorPosition.x++; @@ -200,6 +171,7 @@ public void execute() { if (commandIndex > 0) { commandLines = commandHistory.get(--commandIndex); + Point cursorPosition = screen.getCursorPosition(); cursorPosition.y = commandLines.getLines().size()-1; CharSequence lineBuffer = commandLines.getLines().get(cursorPosition.y); cursorPosition.x = lineBuffer.length(); @@ -215,6 +187,7 @@ public void execute() { if (commandIndex < commandHistory.size()-1) { commandLines = commandHistory.get(++commandIndex); + Point cursorPosition = screen.getCursorPosition(); cursorPosition.y = commandLines.getLines().size()-1; CharSequence lineBuffer = commandLines.getLines().get(cursorPosition.y); cursorPosition.x = lineBuffer.length(); @@ -228,6 +201,7 @@ specialActionKeys.put(InputKey.SpecialKey.END,new KeyAction() { @Override public void execute() { + Point cursorPosition = screen.getCursorPosition(); int curLineEnd = commandLines.getLines().get(cursorPosition.y).length(); if (cursorPosition.x == curLineEnd) { cursorPosition.y = commandLines.getLines().size()-1; @@ -245,6 +219,7 @@ specialActionKeys.put(InputKey.SpecialKey.HOME, new KeyAction() { @Override public void execute() { + Point cursorPosition = screen.getCursorPosition(); if (cursorPosition.x == 0) { cursorPosition.y = 0; } @@ -258,6 +233,7 @@ specialActionKeys.put(InputKey.SpecialKey.BACKSPACE, new KeyAction() { @Override public void execute() { + Point cursorPosition = screen.getCursorPosition(); if (cursorPosition.x == 0) { if (cursorPosition.y > 0) { joinLine(); @@ -278,6 +254,7 @@ specialActionKeys.put(InputKey.SpecialKey.DELETE, new KeyAction() { @Override public void execute() { + Point cursorPosition = screen.getCursorPosition(); StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y); if (cursorPosition.x < lineBuffer.length()) { StringBuilder tmp = getEditableCommand().getEditableLines().get(cursorPosition.y); @@ -292,9 +269,10 @@ specialActionKeys.put(InputKey.SpecialKey.PAGE_UP, new KeyAction() { @Override public void execute() { + List<CharSequence> screenBuffer = screen.getScreenBuffer(); if ((screenBuffer.size() + commandLines.getLines().size() - - (getScreenHeight()/2) * pageUpCount) > 0) { - pageUpCount++; + - (getScreenHeight()/2) * screen.getPageUpCount()) > 0) { + screen.setPageUpCount(screen.getPageUpCount() + 1); } } @@ -306,8 +284,8 @@ specialActionKeys.put(InputKey.SpecialKey.PAGE_DOWN, new KeyAction() { @Override public void execute() { - if (pageUpCount > 0) { - pageUpCount--; + if (screen.getPageUpCount() > 0) { + screen.setPageUpCount(screen.getPageUpCount() - 1); } } @Override @@ -318,6 +296,7 @@ actionKeys.put("", new KeyAction() { @Override public void execute() { // ctrl+w + Point cursorPosition = screen.getCursorPosition(); if (cursorPosition.x == 0) { if (cursorPosition.y > 0) { joinLine(); @@ -340,6 +319,7 @@ actionKeys.put("", new KeyAction() { // ctrl+u @Override public void execute() { + Point cursorPosition = screen.getCursorPosition(); if (cursorPosition.x > 0) { StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y); lineBuffer.delete(0, cursorPosition.x); @@ -385,7 +365,7 @@ } }); - MAX_LINE_LENGTH = getScreenWidth()-(PROMPT.length()+2+1); // prompt + "> " + screen.MAX_LINE_LENGTH = getScreenWidth()-(Screen.PROMPT.length()+2+1); // prompt + "> " output("Welcome to the SQLShell client."); output("Type 'help' to get a list of available commands other then the default sql input."); @@ -437,21 +417,23 @@ } + // TODO move to Screen??? public abstract int getScreenWidth(); public abstract int getScreenHeight(); - private void repaint() { + + protected void repaint() { if (paint) { try { - paint(); + paint(screen); } catch(Throwable t) { error(t); } } } - public abstract void paint(); + public abstract void paint(Screen screen); public abstract void beep(); public abstract void debug(String debug); - public abstract String select(List<String> items); + public abstract String select(List<String> items, Point p); /** * Returns the connection to the database * @return the connection to the database @@ -484,6 +466,7 @@ * Add a new line to the command lines buffer. */ private StringBuilder newLine() { + Point cursorPosition = screen.getCursorPosition(); cursorPosition.x = 0; StringBuilder newLine = new StringBuilder(); getEditableCommand().getEditableLines().add(newLine); @@ -498,7 +481,7 @@ protected void handleInput(InputKey inp) { try { if (!inp.isSpecialKey() || (inp.getSpecialKeyValue() != InputKey.SpecialKey.PAGE_UP && inp.getSpecialKeyValue() != InputKey.SpecialKey.PAGE_DOWN)) { - pageUpCount = 0; // some character entered, so reset pageup count + screen.setPageUpCount(0); // some character entered, so reset pageup count } if (inp.isSpecialKey()) { KeyAction ke = specialActionKeys.get(inp.getSpecialKeyValue());// || inp.toString().equals("") || inp.toString().equals("")) { @@ -529,6 +512,7 @@ commandHistory.remove(commandIndex); commandIndex = commandHistory.indexOf(newSqlCommand); commandLines = newSqlCommand; + Point cursorPosition = screen.getCursorPosition(); cursorPosition.y = 0; cursorPosition.x = 0; repaint(); // force repaint @@ -555,6 +539,7 @@ newLine(); } commandIndex = commandHistory.size()-1; + Point cursorPosition = screen.getCursorPosition(); cursorPosition.y = commandLines.getLines().size()-1; cursorPosition.x = commandLines.getLines().get(cursorPosition.y).length(); repaint(); // force repaint @@ -564,6 +549,7 @@ CharSequence newText; if (inp.getCharacter() == '\t') { try { + Point cursorPosition = screen.getCursorPosition(); newText = getTabCompletion(commandLines, cursorPosition); } catch(IllegalStateException e) { output(getCommand().getCommandString()); // add command as well... @@ -576,12 +562,13 @@ if (newText.equals("\n")) { newLine(); // TODO Fix return in middle of an other line } else { + Point cursorPosition = screen.getCursorPosition(); List<StringBuilder> editableLines = getEditableCommand().getEditableLines(); StringBuilder currentLine = editableLines.get(cursorPosition.y); currentLine.insert(cursorPosition.x, newText); cursorPosition.x += newText.length(); // check if the new line is becoming too long - if (currentLine.length() > MAX_LINE_LENGTH) { + if (currentLine.length() > screen.MAX_LINE_LENGTH) { // TODO search for lastspace that is not between '' ?? int lastSpace = SQLUtil.getLastBreakIndex(currentLine.toString());//currentLine.lastIndexOf(" "); int lastChar = currentLine.charAt(lastSpace); @@ -597,7 +584,7 @@ // check if the nextline has enough room for the new word // if not.. add a new line if (editableLines.get(cursorPosition.y+1).length() - + (currentLine.length()-lastSpace+1) > MAX_LINE_LENGTH) { + + (currentLine.length()-lastSpace+1) > screen.MAX_LINE_LENGTH) { StringBuilder newLine = new StringBuilder(); editableLines.add(cursorPosition.y+1, newLine); } @@ -668,6 +655,7 @@ * @param data the data to print to the screen. */ protected synchronized void output(CharSequence data) { + List<CharSequence> screenBuffer = screen.getScreenBuffer(); screenBuffer.addAll(getLines(data)); if (spoolWriter != null) { try { @@ -758,8 +746,15 @@ String match = null; if (matches.size() == 1) { match = matches.get(0); - } else if (matches.size() > 1 && matches.size() < MAX_MATCH_SIZE) { - match = select(matches); + } else if (matches.size() > 1 && matches.size() < Screen.MAX_MATCH_SIZE) { + int y; + Point cursorPosition = screen.getCursorPosition(); + if (screen.getScreenBuffer().size() + cursorPosition.y > getScreenHeight()-3) { + y = getScreenHeight()-4; + } else { + y = screen.getScreenBuffer().size() + cursorPosition.y; + } + match = select(matches, new Point(cursorPosition.x, y)); } else if (matches.size() > 1) { output("\n"+toColumns(matches)); } @@ -919,7 +914,7 @@ StringBuilder returnValue = new StringBuilder(); for (int row = 0; row < values.size(); row+=nrOfColumns) { for (int col = 0; col < nrOfColumns && row + col < values.size(); col++) { - returnValue.append(values.get(row+col) + emptyLine.substring(0, maxWidth - values.get(row+col).length())); + returnValue.append(values.get(row+col) + screen.getEmptyLine().substring(0, maxWidth - values.get(row+col).length())); } returnValue.append('\n'); } @@ -927,36 +922,6 @@ } /** - * A list which contains a limited number of lines. - */ - private class LimitedArrayList<E> extends ArrayList<E> { - private int maxSize; - /** - * Constructor. - * @param maxSize the maximum number of lines the list may contain - */ - public LimitedArrayList(int maxSize) { - super(maxSize); // some sane default - this.maxSize = maxSize; - } - - @Override - public boolean add(E object) { - if (size() == maxSize) { - remove(0); - } - return super.add(object); - } - @Override - public void add(int index, E object) { - if (size() == maxSize) { - remove(0); - } - super.add(index, object); - } - } - - /** * Connect command for setting up a connection to a database. */ private static class ConnectCommand implements Command { @@ -1213,7 +1178,7 @@ if (cmd.getCommandString().equals(cmdString)) { return cmd.getCommandString()+": " + cmd.getHelp().toString().replaceAll("\n" - , "\n"+emptyLine.substring(0, cmd.getCommandString().length()+3)); + , "\n"+screen.getEmptyLine().substring(0, cmd.getCommandString().length()+3)); } } } @@ -1600,7 +1565,12 @@ output(commandString); output(currentCommand.execute(new InputCommand(commandString))); cmd=new StringBuilder(); - new Thread() { public void run() { repaint();}}.start(); + new Thread() { + @Override + public void run() { + repaint(); + } + }.start(); } } } catch(IOException e) { @@ -1709,12 +1679,14 @@ this.cmd = cmd; } + @Override public final void run() { - showPrompt = false; + screen.setShowPrompt(false); + repaint(); try { execute(); } finally { - showPrompt = true; + screen.setShowPrompt(true); repaint(); } } @@ -1783,6 +1755,7 @@ } private void joinLine() { + Point cursorPosition = screen.getCursorPosition(); StringBuilder line = getEditableCommand().getEditableLines().remove(cursorPosition.y); cursorPosition.y--; StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y); Added: src/main/java/nl/improved/sqlclient/Screen.java =================================================================== --- src/main/java/nl/improved/sqlclient/Screen.java 2008-07-28 20:20:24 UTC (rev 272) +++ src/main/java/nl/improved/sqlclient/Screen.java 2008-07-28 20:54:09 UTC (rev 273) @@ -0,0 +1,94 @@ +/* + * Copyright 2008 Roy van der Kuil (ro...@va...) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.improved.sqlclient; + +import java.util.List; +import nl.improved.sqlclient.util.LimitedArrayList; + +/** + * + * @author roy + */ +public class Screen { + + /** + * The (default) maximum matches to show in a selection dialog. + */ + public static final int MAX_MATCH_SIZE = 15; + public int MAX_LINE_LENGTH; // not static and final.. since it can change on window resize + /** + * The prompt to show when entering sql commands. + */ + public static final String PROMPT = "SQL"; + + /** + * True when the prompt should be visible. + * Normally it is not visible during the execution of a command + */ + private boolean showPrompt = true; + + /** + * Page up count 0 means were at the bottom of our screen. + * Increasement of the pageup count moves the visible part of the screen up. + */ + private int pageUpCount = 0; + /** + * All lines in a screen. + */ + private List<CharSequence> screenBuffer = new LimitedArrayList<CharSequence>(1000); + /** + * An empty line for easy line completion (fill with spaces). + */ + private String emptyLine; + /** + * The cursor position in the command lines list. + * 0,0 means it is at the first line at the first character + * 10,5 means it is at the 11th character at the 6th line + */ + private Point cursorPosition = new Point(0,0); + + public Point getCursorPosition() { + return cursorPosition; + } + + public List<CharSequence> getScreenBuffer() { + return screenBuffer; + } + + public int getPageUpCount() { + return pageUpCount; + } + + public void setPageUpCount(int pageUpCount) { + this.pageUpCount = pageUpCount; + } + + public boolean getShowPrompt() { + return showPrompt; + } + + public void setShowPrompt(boolean showPrompt) { + this.showPrompt = showPrompt; + } + + public String getEmptyLine() { + return emptyLine; + } + + public void setEmptyLine(String emptyLine) { + this.emptyLine = emptyLine; + } +} Modified: src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java 2008-07-28 20:20:24 UTC (rev 272) +++ src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java 2008-07-28 20:54:09 UTC (rev 273) @@ -1,8 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright 2008 Roy van der Kuil (ro...@va...) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - package nl.improved.sqlclient.jcurses; import java.util.ArrayList; @@ -17,6 +27,7 @@ import nl.improved.sqlclient.InputKey; import nl.improved.sqlclient.Point; import nl.improved.sqlclient.SQLCommand; +import nl.improved.sqlclient.Screen; import nl.improved.sqlclient.TabCompletionInfo; import nl.improved.sqlclient.commands.Command; @@ -61,6 +72,7 @@ */ @Override protected synchronized void paint() { + /* CharColor color = new CharColor(CharColor.BLACK, CharColor.WHITE, CharColor.BOLD, CharColor.BOLD); List<CharSequence> tmpList = new ArrayList<CharSequence>(); @@ -113,6 +125,8 @@ } } Toolkit.printString(cursorChar, PROMPT.length() +"> ".length() + cursorPosition.x, lineNr-(commandLines.getLines().size() -cursorPosition.y)-startLine, color); + * */ + SQLShellWindow.this.repaint(); } private InputKey toInputKey(InputChar inputChar) { @@ -208,14 +222,8 @@ } @Override - public String select(List<String> items) { - int y; - if (screenBuffer.size() + cursorPosition.y > getScreenHeight()-3) { - y = getScreenHeight()-4; - } else { - y = screenBuffer.size() + cursorPosition.y; - } - PopUpMenu menu = new PopUpMenu(cursorPosition.x,Math.max(2, y-items.size()), "Find match"); + public String select(List<String> items, Point p) { + PopUpMenu menu = new PopUpMenu(p.x,Math.max(2, p.y-items.size()), "Find match"); Iterator<String> iMatches = items.iterator(); while (iMatches.hasNext()) { menu.add(iMatches.next()); @@ -225,27 +233,28 @@ } @Override - public void paint() { + public void paint(Screen screen) { CharColor color = new CharColor(CharColor.BLACK, CharColor.WHITE, CharColor.BOLD, CharColor.BOLD); List<CharSequence> tmpList = new ArrayList<CharSequence>(); + List<CharSequence> screenBuffer = screen.getScreenBuffer(); tmpList.addAll(screenBuffer); //add prompt List<? extends CharSequence> currentLines = commandLines.getLines(); for (int i = 0; i < currentLines.size(); i++) { - if (i == 0 && showPrompt) { - tmpList.add(PROMPT+"> "+currentLines.get(i)); + if (i == 0 && screen.getShowPrompt()) { + tmpList.add(Screen.PROMPT+"> "+currentLines.get(i)); } else { String nrI = Integer.toString(i+1); - tmpList.add(emptyLine.substring(0,PROMPT.length() - nrI.length()) + nrI+"> "+currentLines.get(i)); + tmpList.add(screen.getEmptyLine().substring(0,Screen.PROMPT.length() - nrI.length()) + nrI+"> "+currentLines.get(i)); } } int startLine; if (tmpList.size() > Toolkit.getScreenHeight()-1) { startLine = tmpList.size() - (Toolkit.getScreenHeight()-1); - if (pageUpCount > 0) { - startLine -= (pageUpCount * Toolkit.getScreenHeight()/2); + if (screen.getPageUpCount() > 0) { + startLine -= (screen.getPageUpCount() * Toolkit.getScreenHeight()/2); if (startLine < 0) { startLine = 0; } @@ -256,17 +265,18 @@ int lineNr; for (lineNr = startLine;lineNr < tmpList.size() && lineNr - startLine < Toolkit.getScreenHeight()-1; lineNr++) { CharSequence linePart = tmpList.get(lineNr); - String line = linePart.length() >= emptyLine.length() ? linePart.toString() : linePart + emptyLine.substring(linePart.length()); + String line = linePart.length() >= screen.getEmptyLine().length() ? linePart.toString() : linePart + screen.getEmptyLine().substring(linePart.length()); Toolkit.printString(line , 0, lineNr-startLine, color); } for (int lNr = lineNr; lNr < Toolkit.getScreenHeight(); lNr++) { - Toolkit.printString(emptyLine, 0, lNr, color); + Toolkit.printString(screen.getEmptyLine(), 0, lNr, color); } // paint cursor color = new CharColor(CharColor.BLACK, CharColor.WHITE, CharColor.REVERSE, CharColor.REVERSE); String cursorChar = " "; + Point cursorPosition = screen.getCursorPosition(); if (commandLines.getLines().size() > 0) { String tmp = commandLines.getLines().get(cursorPosition.y).toString(); if (cursorPosition.x < 0) { @@ -277,7 +287,7 @@ cursorChar = tmp.substring(cursorPosition.x, cursorPosition.x+1); } } - Toolkit.printString(cursorChar, PROMPT.length() +"> ".length() + cursorPosition.x, lineNr-(commandLines.getLines().size() -cursorPosition.y)-startLine, color); + Toolkit.printString(cursorChar, Screen.PROMPT.length() +"> ".length() + cursorPosition.x, lineNr-(commandLines.getLines().size() -cursorPosition.y)-startLine, color); } public static void main(String[] args) { Added: src/main/java/nl/improved/sqlclient/util/LimitedArrayList.java =================================================================== --- src/main/java/nl/improved/sqlclient/util/LimitedArrayList.java 2008-07-28 20:20:24 UTC (rev 272) +++ src/main/java/nl/improved/sqlclient/util/LimitedArrayList.java 2008-07-28 20:54:09 UTC (rev 273) @@ -0,0 +1,48 @@ +/* + * Copyright 2008 Roy van der Kuil (ro...@va...) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.improved.sqlclient.util; + +import java.util.ArrayList; + +/** + * A list which contains a limited number of lines. + */ +public class LimitedArrayList<E> extends ArrayList<E> { + private int maxSize; + /** + * Constructor. + * @param maxSize the maximum number of lines the list may contain + */ + public LimitedArrayList(int maxSize) { + super(maxSize); // some sane default + this.maxSize = maxSize; + } + + @Override + public boolean add(E object) { + if (size() == maxSize) { + remove(0); + } + return super.add(object); + } + @Override + public void add(int index, E object) { + if (size() == maxSize) { + remove(0); + } + super.add(index, object); + } +} |