svnno****@sourc*****
svnno****@sourc*****
2009年 9月 18日 (金) 03:43:29 JST
Revision: 3604 http://sourceforge.jp/projects/jiemamy/svn/view?view=rev&revision=3604 Author: daisuke_m Date: 2009-09-18 03:43:29 +0900 (Fri, 18 Sep 2009) Log Message: ----------- jiemamy-commons v0.0.3リリース。 Added Paths: ----------- leto/jiemamy-commons/tags/release/0.0.3/ leto/jiemamy-commons/tags/release/0.0.3/pom.xml leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/ArrayEssentialStack.java leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/EssentialQueue.java leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/EssentialStack.java leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/EssentialStacks.java leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/LinkedEssentialQueue.java Removed Paths: ------------- leto/jiemamy-commons/tags/release/0.0.3/pom.xml Property changes on: leto/jiemamy-commons/tags/release/0.0.3 ___________________________________________________________________ Added: svn:ignore + target lib repo .externalToolBuilders Added: svn:externals + .settings -r3599 http://svn.sourceforge.jp/svnroot/jiemamy/athena/master/trunk/.settings Deleted: leto/jiemamy-commons/tags/release/0.0.3/pom.xml =================================================================== --- leto/jiemamy-commons/trunk/pom.xml 2009-09-17 14:55:11 UTC (rev 3599) +++ leto/jiemamy-commons/tags/release/0.0.3/pom.xml 2009-09-17 18:43:29 UTC (rev 3604) @@ -1,117 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.jiemamy</groupId> - <artifactId>master</artifactId> - <version>1.1</version> - </parent> - <groupId>org.jiemamy</groupId> - <artifactId>jiemamy-commons</artifactId> - <name>Jiemamy Commons</name> - <version>0.0.2</version> - <url>http://report.jiemamy.org/jiemamy-commons</url> - <issueManagement> - <system>JIRA</system> - <url>http://jira.jiemamy.org/jira/browse/COM</url> - </issueManagement> - <ciManagement> - <system>hudson</system> - <url>http://hudson.jiemamy.org/hudson/job/jiemamy-commons/</url> - <notifiers> - <notifier> - <sendOnSuccess>false</sendOnSuccess> - <configuration> - <recipients>jiema****@googl*****</recipients> - </configuration> - </notifier> - </notifiers> - </ciManagement> - <inceptionYear>2009</inceptionYear> - <developers> - <developer> - <id>daisuke</id> - <name>MIYAMOTO Daisuke</name> - <email>daisuke_m****@users*****</email> - <url>http://d.hatena.ne.jp/daisuke-m/</url> - <timezone>+9</timezone> - </developer> - <developer> - <id>j5ik2o</id> - <name>Junichi Kato</name> - <email>j5ik2****@users*****</email> - <url>http://d.hatena.ne.jp/j5ik2o/</url> - <timezone>+9</timezone> - </developer> - </developers> - <scm> - <connection>scm:svn:http://svn.sourceforge.jp/svnroot/jiemamy/leto/jiemamy-commons/trunk</connection> - <developerConnection>scm:svn:svn+ssh://svn.sourceforge.jp/svnroot/jiemamy/leto/jiemamy-commons/trunk</developerConnection> - <url>http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi/leto/jiemamy-commons/trunk/?root=jiemamy</url> - </scm> - <repositories> - <repository> - <id>jiemamy.org</id> - <name>Jiemamy Repository</name> - <url>http://maven.jiemamy.org/release</url> - </repository> - </repositories> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.5</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-library</artifactId> - <version>1.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <version>1.1.113</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>1.5.6</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl-over-slf4j</artifactId> - <version>1.5.6</version> - </dependency> - <dependency> - <groupId>ch.qos.logback</groupId> - <artifactId>logback-core</artifactId> - <version>0.9.15</version> - </dependency> - <dependency> - <groupId>ch.qos.logback</groupId> - <artifactId>logback-classic</artifactId> - <version>0.9.15</version> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.4</version> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>1.3.2</version> - </dependency> - <dependency> - <groupId>javassist</groupId> - <artifactId>javassist</artifactId> - <version>3.8.0.GA</version> - <optional>false</optional> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: leto/jiemamy-commons/tags/release/0.0.3/pom.xml (from rev 3603, leto/jiemamy-commons/trunk/pom.xml) =================================================================== --- leto/jiemamy-commons/tags/release/0.0.3/pom.xml (rev 0) +++ leto/jiemamy-commons/tags/release/0.0.3/pom.xml 2009-09-17 18:43:29 UTC (rev 3604) @@ -0,0 +1,122 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.jiemamy</groupId> + <artifactId>master</artifactId> + <version>1.1</version> + </parent> + <groupId>org.jiemamy</groupId> + <artifactId>jiemamy-commons</artifactId> + <name>Jiemamy Commons</name> + <version>0.0.3</version> + <url>http://report.jiemamy.org/jiemamy-commons</url> + <issueManagement> + <system>JIRA</system> + <url>http://jira.jiemamy.org/jira/browse/COM</url> + </issueManagement> + <ciManagement> + <system>hudson</system> + <url>http://hudson.jiemamy.org/hudson/job/jiemamy-commons/</url> + <notifiers> + <notifier> + <sendOnSuccess>false</sendOnSuccess> + <configuration> + <recipients>jiema****@googl*****</recipients> + </configuration> + </notifier> + </notifiers> + </ciManagement> + <inceptionYear>2009</inceptionYear> + <developers> + <developer> + <id>daisuke</id> + <name>MIYAMOTO Daisuke</name> + <email>daisuke_m****@users*****</email> + <url>http://d.hatena.ne.jp/daisuke-m/</url> + <timezone>+9</timezone> + </developer> + <developer> + <id>j5ik2o</id> + <name>Junichi Kato</name> + <email>j5ik2****@users*****</email> + <url>http://d.hatena.ne.jp/j5ik2o/</url> + <timezone>+9</timezone> + </developer> + </developers> + <scm> + <connection>scm:svn:http://svn.sourceforge.jp/svnroot/jiemamy/leto/jiemamy-commons/trunk</connection> + <developerConnection>scm:svn:svn+ssh://svn.sourceforge.jp/svnroot/jiemamy/leto/jiemamy-commons/trunk</developerConnection> + <url>http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi/leto/jiemamy-commons/trunk/?root=jiemamy</url> + </scm> + <repositories> + <repository> + <id>jiemamy.org</id> + <name>Jiemamy Repository</name> + <url>http://maven.jiemamy.org/release</url> + </repository> + </repositories> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.5</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-library</artifactId> + <version>1.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>1.1.113</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.5.6</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + <version>1.5.6</version> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-core</artifactId> + <version>0.9.15</version> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <version>0.9.15</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.4</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.3.2</version> + </dependency> + <dependency> + <groupId>net.sourceforge.collections</groupId> + <artifactId>collections-generic</artifactId> + <version>4.01</version> + </dependency> + <dependency> + <groupId>javassist</groupId> + <artifactId>javassist</artifactId> + <version>3.8.0.GA</version> + <optional>false</optional> + </dependency> + </dependencies> +</project> \ No newline at end of file Copied: leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/ArrayEssentialStack.java (from rev 3601, leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/ArrayEssentialStack.java) =================================================================== --- leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/ArrayEssentialStack.java (rev 0) +++ leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/ArrayEssentialStack.java 2009-09-17 18:43:29 UTC (rev 3604) @@ -0,0 +1,148 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2008/12/16 + * + * 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.Collection; +import java.util.Iterator; + +import org.apache.commons.collections15.ArrayStack; +import org.apache.commons.lang.Validate; + +/** + * {@link EssentialStack}の{@link ArrayStack}を用いた実装。 + * + * @param <E> 要素の型 + * @author daisuke + */ +public class ArrayEssentialStack<E> implements EssentialStack<E> { + + /** 10% room for growth */ + private static final double GROWTH_FACTOR = 1.1; + + private final ArrayStack<E> stack; + + + /** + * インスタンスを生成する。 + */ + public ArrayEssentialStack() { + stack = new ArrayStack<E>(); + } + + /** + * インスタンスを生成する。 + * + * @param collection 初期要素を保持したコレクション + * @throws IllegalArgumentException 引数に{@code null}を与えた場合 + */ + public ArrayEssentialStack(Collection<? extends E> collection) { + Validate.notNull(collection); + int size = collection.size(); + int capacity = (int) Math.min(size * GROWTH_FACTOR, Integer.MAX_VALUE); + + stack = new ArrayStack<E>(capacity); + for (E element : collection) { + stack.push(element); + } + } + + /** + * インスタンスを生成する。 + * + * @param source 初期要素を保持したスタック + * @throws IllegalArgumentException 引数に{@code null}を与えた場合 + */ + public ArrayEssentialStack(EssentialStack<? extends E> source) { + Validate.notNull(source); + stack = new ArrayStack<E>(source.size()); + for (E element : source) { + stack.push(element); + } + } + + /** + * インスタンスを生成する。 + * + * @param initialSize 初期サイズ + */ + public ArrayEssentialStack(int initialSize) { + stack = new ArrayStack<E>(initialSize); + } + + public void clear() { + stack.clear(); + } + + public E get(int n) { + return stack.get(n); + } + + public void insert(int index, E element) { + stack.add(index, element); + } + + 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.peek(n); + } + + public E pop() { + return stack.pop(); + } + + public void push(E element) { + stack.push(element); + } + + public boolean remove(E element) { + return stack.remove(element); + } + + public E remove(int n) { + return stack.remove(n); + } + + public EssentialStack<E> reverse() { + EssentialStack<E> result = new ArrayEssentialStack<E>(stack.size()); + for (E element : stack) { + result.insert(0, element); + } + return result; + } + + public int size() { + return stack.size(); + } + + @Override + public String toString() { + return stack.toString(); + } +} Copied: leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/EssentialQueue.java (from rev 3601, leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/EssentialQueue.java) =================================================================== --- leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/EssentialQueue.java (rev 0) +++ leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/EssentialQueue.java 2009-09-17 18:43:29 UTC (rev 3604) @@ -0,0 +1,82 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2008/12/16 + * + * 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.NoSuchElementException; + +/** + * 本質的なキューのインターフェイス。 + * + * <p>{@link java.util.Queue}は不適切な継承を行っている為、 + * Jiemamy Projectでは、こちらのインターフェイスを優先的に使用する。</p> + * + * @param <E> 要素の型 + * @author daisuke + */ +public interface EssentialQueue<E> extends Iterable<E> { + + /** + * キューを初期化する。 + */ + void clear(); + + /** + * キューから要素を1つ取り出す。 + * + * @return 取り出した要素 + * @throws NoSuchElementException 取り出す要素が無い場合 + */ + E dequeue(); + + /** + * キューに要素を追加する。 + * + * @param element 追加する要素 + */ + void enqueue(E element); + + /** + * 与えられたキューの内容を、このキューに全て追加する。 + * + * @param queue 読み込み元のキュー + */ + void enqueue(EssentialQueue<E> queue); + + /** + * 取り出す要素があるかどうか調べる。 + * + * @return キューが空の場合は{@code true}、そうでない場合は{@code false} + */ + boolean isEmpty(); + + /** + * 次にキューから取り出される要素を取得する。キューから削除は行わない。 + * + * @return 次にキューから取り出される要素 + * @throws NoSuchElementException 取り出す要素が無い場合 + */ + E peek(); + + /** + * キューから取り出せる要素の数を取得する。 + * + * @return 要素の数 + */ + int size(); +} Copied: leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/EssentialStack.java (from rev 3601, leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/EssentialStack.java) =================================================================== --- leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/EssentialStack.java (rev 0) +++ leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/EssentialStack.java 2009-09-17 18:43:29 UTC (rev 3604) @@ -0,0 +1,128 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2008/12/16 + * + * 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.EmptyStackException; +import java.util.NoSuchElementException; + +/** + * 本質的なスタックのインターフェイス。 + * + * <p>{@link java.util.Stack}は実装型である上に、不適切な継承を行っている為、 + * Jiemamy Projectでは、こちらのインターフェイスを優先的に使用する。</p> + * + * @param <E> 要素の型 + * @author daisuke + */ +public interface EssentialStack<E> extends Iterable<E> { + + /** + * スタックを初期化する。 + */ + void clear(); + + /** + * n番目にpushされた要素を取得する。スタックから削除は行わない。 + * + * @param n インデックス + * @return 要素 + * @throws IndexOutOfBoundsException if index is out of range {@code (index < 0 || index >= size())}. + */ + E get(int n); + + /** + * スタックの下からn番目に要素を挿入する。 + * + * @param n インデックス + * @param element 挿入する要素 + */ + void insert(int n, E element); + + /** + * 取り出す要素があるかどうか調べる。 + * + * @return スタックが空の場合は{@code true}、そうでない場合は{@code false} + */ + boolean isEmpty(); + + /** + * 次の{@link #pop()}でスタックから取り出される要素を取得する。スタックから削除は行わない。 + * + * <p>{@code peek(0)}と等価である。</p> + * + * @return 要素 + * @throws NoSuchElementException 取り出す要素が無い場合 + */ + E peek(); + + /** + * n番目に{@link #pop()}でスタックから取り出される要素を取得する。スタックから削除は行わない。 + * + * @param n インデックス + * @return 要素 + * @throws EmptyStackException if there are not enough items on the + * stack to satisfy this request + */ + E peek(int n); + + /** + * スタックから要素を1つ取り出す。 + * + * @return 取り出した要素 + * @throws NoSuchElementException 取り出す要素が無い場合 + */ + E pop(); + + /** + * スタックに要素を追加する。 + * + * @param element 追加する要素 + */ + void push(E element); + + /** + * 下から検索し、初めて見つかった要素を削除する。 + * + * @param element 削除する要素 + * @return 削除が行われた場合は{@code true}、そうでない場合は{@code false} + */ + boolean remove(E element); + + /** + * n番目の要素を削除する。 + * + * @param n インデックス + * @return 削除された要素 + */ + E remove(int n); + + /** + * 逆順のスタックを返す。 + * + * @return 逆順のスタック + */ + EssentialStack<E> reverse(); + + /** + * スタックから取り出せる要素の数を取得する。 + * + * @return 要素の数 + */ + int size(); +} Copied: leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/EssentialStacks.java (from rev 3601, leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/EssentialStacks.java) =================================================================== --- leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/EssentialStacks.java (rev 0) +++ leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/EssentialStacks.java 2009-09-17 18:43:29 UTC (rev 3604) @@ -0,0 +1,91 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/03/04 + * + * 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 org.apache.commons.lang.ObjectUtils; +import org.apache.commons.lang.Validate; + +/** + * {@link EssentialStack}のユーティリティクラス。 + * + * @author daisuke + */ +public final class EssentialStacks { + + /** + * 左右の要素を下から調べ、初めて異なる要素が現れる所までの部分スタックを返す。 + * + * <p>ABCDEFG と ABCXYZ の場合は ABC を返し、ABCDEFG と ABXDXXG の場合は AB を返す。</p> + * + * @param <E> 要素の型 + * @param left 左辺スタック + * @param right 右辺スタック + * @return 部分スタック + * @throws IllegalArgumentException 引数に{@code null}を与えた場合 + */ + public static <E>EssentialStack<E> intersection(EssentialStack<? extends E> left, EssentialStack<? extends E> right) { + Validate.notNull(left); + Validate.notNull(right); + EssentialStack<E> result = new ArrayEssentialStack<E>(Math.min(left.size(), right.size())); + + int i = 0; + for (E leftElement : left) { + if (i >= right.size()) { + break; + } + E rightElement = right.get(i); + if (ObjectUtils.equals(rightElement, leftElement)) { + result.push(leftElement); + } else { + // 違いが生じた時点で終了 + break; + } + i++; + } + + return result; + } + + /** + * 左の要素から、右の要素を取り除いた部分スタックを返す。 + * + * @param <E> 要素の型 + * @param left 左辺スタック + * @param right 右辺スタック + * @return 部分スタック + * @throws IllegalArgumentException 引数に{@code null}を与えた場合 + */ + public static <E>EssentialStack<E> minus(EssentialStack<? extends E> left, EssentialStack<? extends E> right) { + Validate.notNull(left); + Validate.notNull(right); + EssentialStack<E> result = new ArrayEssentialStack<E>(left); + for (E er : right) { + for (E el : left) { + if (el == er) { + result.remove(el); + } + } + } + + return result; + } + + private EssentialStacks() { + } +} Copied: leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/LinkedEssentialQueue.java (from rev 3601, leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/LinkedEssentialQueue.java) =================================================================== --- leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/LinkedEssentialQueue.java (rev 0) +++ leto/jiemamy-commons/tags/release/0.0.3/src/main/java/org/jiemamy/utils/LinkedEssentialQueue.java 2009-09-17 18:43:29 UTC (rev 3604) @@ -0,0 +1,80 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2008/12/16 + * + * 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; +import java.util.NoSuchElementException; + +/** + * {@link EssentialQueue}の{@link LinkedList}を用いた実装。 + * + * @param <E> 要素の型 + * @author daisuke + */ +public class LinkedEssentialQueue<E> implements EssentialQueue<E> { + + private LinkedList<E> linkedList = new LinkedList<E>(); + + + public void clear() { + linkedList.clear(); + } + + public E dequeue() { + return linkedList.poll(); + } + + public void enqueue(E element) { + linkedList.offer(element); + } + + public void enqueue(EssentialQueue<E> queue) { + try { + while (true) { + E element = queue.dequeue(); + enqueue(element); + } + } catch (NoSuchElementException e) { + // ループを抜ける。 + } + } + + public boolean isEmpty() { + return linkedList.isEmpty(); + } + + public Iterator<E> iterator() { + return linkedList.iterator(); + } + + public E peek() { + return linkedList.peek(); + } + + public int size() { + return linkedList.size(); + } + + @Override + public String toString() { + return linkedList.toString(); + } + +}