svnno****@sourc*****
svnno****@sourc*****
2009年 2月 26日 (木) 08:17:03 JST
Revision: 2740 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2740 Author: daisuke_m Date: 2009-02-26 08:17:03 +0900 (Thu, 26 Feb 2009) Log Message: ----------- ユーティリティ追加。 Added Paths: ----------- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/TokorotenStack.java -------------- next part -------------- Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/TokorotenStack.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/TokorotenStack.java (rev 0) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/TokorotenStack.java 2009-02-25 23:17:03 UTC (rev 2740) @@ -0,0 +1,87 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/02/26 + * + * This file is part of Jiemamy. + * + * 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 org.jiemamy.utils; + +import java.util.Iterator; +import java.util.LinkedList; + +/** + * 一定サイズを超えないよう、下の要素を捨てていくスタック。 + * + * <p>スレッドアンセーフである。</p> + * + * @author daisuke + */ +public class TokorotenStack<E> implements EssentialStack<E> { + + private LinkedList<E> stack = new LinkedList<E>(); + + private final int size; + + + /** + * インスタンスを生成する。 + * + * @param size + */ + public TokorotenStack(int size) { + this.size = size; + } + + public void clear() { + stack.clear(); + } + + public boolean isEmpty() { + return stack.isEmpty(); + } + + public Iterator<E> iterator() { + return stack.iterator(); + } + + public E peek() { + return stack.peek(); + } + + public E peek(int n) { + return stack.get(n); + } + + public E pop() { + return stack.getLast(); + } + + public void push(E element) { + while (size() >= size) { + stack.removeFirst(); + } + stack.add(element); + } + + public int size() { + return stack.size(); + } + + @Override + public String toString() { + return stack.toString(); + } + +} Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/TokorotenStack.java ___________________________________________________________________ Added: svn:mime-type + text/plain