001: /***
002: * Retrotranslator: a Java bytecode transformer that translates Java classes
003: * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
004: *
005: * Copyright (c) 2005 - 2008 Taras Puchko
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * 3. Neither the name of the copyright holders nor the names of its
017: * contributors may be used to endorse or promote products derived from
018: * this software without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
021: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
022: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
023: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
024: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
025: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
026: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
027: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
028: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
029: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
030: * THE POSSIBILITY OF SUCH DAMAGE.
031: */package net.sf.retrotranslator.runtime.java.util;
032:
033: import edu.emory.mathcs.backport.java.util.Deque;
034: import java.util.*;
035:
036: /**
037: * @author Taras Puchko
038: */
039: public class _Deque {
040:
041: public static boolean executeInstanceOfInstruction(Object object) {
042: return object instanceof LinkedList || object instanceof Deque;
043: }
044:
045: public static Collection executeCheckCastInstruction(Object object) {
046: if (object instanceof LinkedList) {
047: return (LinkedList) object;
048: }
049: return (Deque) object;
050: }
051:
052: public static void addFirst(Collection collection, Object o) {
053: if (collection instanceof LinkedList) {
054: ((LinkedList) collection).addFirst(o);
055: } else {
056: ((Deque) collection).addFirst(o);
057: }
058: }
059:
060: public static void addLast(Collection collection, Object o) {
061: if (collection instanceof LinkedList) {
062: ((LinkedList) collection).addLast(o);
063: } else {
064: ((Deque) collection).addLast(o);
065: }
066: }
067:
068: public static Iterator descendingIterator(Collection collection) {
069: if (collection instanceof LinkedList) {
070: return _LinkedList
071: .descendingIterator((LinkedList) collection);
072: }
073: return ((Deque) collection).descendingIterator();
074: }
075:
076: public static Object element(Collection collection) {
077: if (collection instanceof LinkedList) {
078: return _LinkedList.element((LinkedList) collection);
079: }
080: return ((Deque) collection).element();
081: }
082:
083: public static Object getFirst(Collection collection) {
084: if (collection instanceof LinkedList) {
085: return ((LinkedList) collection).getFirst();
086: }
087: return ((Deque) collection).getFirst();
088: }
089:
090: public static Object getLast(Collection collection) {
091: if (collection instanceof LinkedList) {
092: return ((LinkedList) collection).getLast();
093: }
094: return ((Deque) collection).getLast();
095: }
096:
097: public static boolean offer(Collection collection, Object element) {
098: if (collection instanceof LinkedList) {
099: return _LinkedList.offer((LinkedList) collection, element);
100: }
101: return ((Deque) collection).offer(element);
102: }
103:
104: public static boolean offerFirst(Collection collection,
105: Object element) {
106: if (collection instanceof LinkedList) {
107: return _LinkedList.offerFirst((LinkedList) collection,
108: element);
109: }
110: return ((Deque) collection).offerFirst(element);
111: }
112:
113: public static boolean offerLast(Collection collection,
114: Object element) {
115: if (collection instanceof LinkedList) {
116: return _LinkedList.offerLast((LinkedList) collection,
117: element);
118: }
119: return ((Deque) collection).offerLast(element);
120: }
121:
122: public static Object peek(Collection collection) {
123: if (collection instanceof LinkedList) {
124: return _LinkedList.peek((LinkedList) collection);
125: }
126: return ((Deque) collection).peek();
127: }
128:
129: public static Object peekFirst(Collection collection) {
130: if (collection instanceof LinkedList) {
131: return _LinkedList.peekFirst((LinkedList) collection);
132: }
133: return ((Deque) collection).peekFirst();
134: }
135:
136: public static Object peekLast(Collection collection) {
137: if (collection instanceof LinkedList) {
138: return _LinkedList.peekLast((LinkedList) collection);
139: }
140: return ((Deque) collection).peekLast();
141: }
142:
143: public static Object poll(Collection collection) {
144: if (collection instanceof LinkedList) {
145: return _LinkedList.poll((LinkedList) collection);
146: }
147: return ((Deque) collection).poll();
148: }
149:
150: public static Object pollFirst(Collection collection) {
151: if (collection instanceof LinkedList) {
152: return _LinkedList.pollFirst((LinkedList) collection);
153: }
154: return ((Deque) collection).pollFirst();
155: }
156:
157: public static Object pollLast(Collection collection) {
158: if (collection instanceof LinkedList) {
159: return _LinkedList.pollLast((LinkedList) collection);
160: }
161: return ((Deque) collection).pollLast();
162: }
163:
164: public static Object pop(Collection collection) {
165: if (collection instanceof LinkedList) {
166: return _LinkedList.pop((LinkedList) collection);
167: }
168: return ((Deque) collection).pop();
169: }
170:
171: public static void push(Collection collection, Object o) {
172: if (collection instanceof LinkedList) {
173: _LinkedList.push((LinkedList) collection, o);
174: } else {
175: ((Deque) collection).push(o);
176: }
177: }
178:
179: public static Object remove(Collection collection) {
180: if (collection instanceof LinkedList) {
181: return _LinkedList.remove((LinkedList) collection);
182: }
183: return ((Deque) collection).remove();
184: }
185:
186: public static Object removeFirst(Collection collection) {
187: if (collection instanceof LinkedList) {
188: return ((LinkedList) collection).removeFirst();
189: }
190: return ((Deque) collection).removeFirst();
191: }
192:
193: public static Object removeLast(Collection collection) {
194: if (collection instanceof LinkedList) {
195: return ((LinkedList) collection).removeLast();
196: }
197: return ((Deque) collection).removeLast();
198: }
199:
200: public static boolean removeFirstOccurrence(Collection collection,
201: Object o) {
202: if (collection instanceof LinkedList) {
203: return _LinkedList.removeFirstOccurrence(
204: (LinkedList) collection, o);
205: }
206: return ((Deque) collection).removeFirstOccurrence(o);
207: }
208:
209: public static boolean removeLastOccurrence(Collection collection,
210: Object o) {
211: if (collection instanceof LinkedList) {
212: return _LinkedList.removeLastOccurrence(
213: (LinkedList) collection, o);
214: }
215: return ((Deque) collection).removeLastOccurrence(o);
216: }
217:
218: }
|