mirror of
https://github.com/corda/corda.git
synced 2025-01-05 20:54:13 +00:00
Merge branch 'master' of https://github.com/ReadyTalk/avian into avian-droid-2
This commit is contained in:
commit
35b567c778
@ -126,7 +126,7 @@ public class Data {
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] array) {
|
||||
return toArray(this, array);
|
||||
return Data.toArray(this, array);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
@ -170,7 +170,7 @@ public class Data {
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] array) {
|
||||
return toArray(this, array);
|
||||
return Data.toArray(this, array);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
@ -256,7 +256,7 @@ public class Data {
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] array) {
|
||||
return toArray(this, array);
|
||||
return Data.toArray(this, array);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
@ -74,6 +74,21 @@ public class SystemClassLoader extends ClassLoader {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Package getPackage(String name) {
|
||||
Package p = super.getPackage(name);
|
||||
if (p == null) {
|
||||
String source = getPackageSource(name);
|
||||
if (source != null) {
|
||||
// todo: load attributes from JAR manifest
|
||||
definePackage(name, null, null, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
return super.getPackage(name);
|
||||
}
|
||||
|
||||
protected static native String getPackageSource(String name);
|
||||
|
||||
// OpenJDK's java.lang.ClassLoader.getResource makes use of
|
||||
// sun.misc.Launcher to load bootstrap resources, which is not
|
||||
// appropriate for the Avian build, so we override it to ensure we
|
||||
|
@ -559,8 +559,7 @@ public final class Class <T> implements Type, AnnotatedElement {
|
||||
String name = getCanonicalName();
|
||||
int index = name.lastIndexOf('.');
|
||||
if (index >= 0) {
|
||||
return new Package(name.substring(0, index),
|
||||
null, null, null, null, null, null, null, null);
|
||||
return getClassLoader().getPackage(name.substring(0, index));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -17,9 +17,12 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
public abstract class ClassLoader {
|
||||
private final ClassLoader parent;
|
||||
private Map<String, Package> packages;
|
||||
|
||||
protected ClassLoader(ClassLoader parent) {
|
||||
if (parent == null) {
|
||||
@ -33,6 +36,45 @@ public abstract class ClassLoader {
|
||||
this(getSystemClassLoader());
|
||||
}
|
||||
|
||||
private Map<String, Package> packages() {
|
||||
if (packages == null) {
|
||||
packages = new HashMap();
|
||||
}
|
||||
return packages;
|
||||
}
|
||||
|
||||
protected Package getPackage(String name) {
|
||||
synchronized (this) {
|
||||
return packages().get(name);
|
||||
}
|
||||
}
|
||||
|
||||
protected Package[] getPackages() {
|
||||
synchronized (this) {
|
||||
return packages().values().toArray(new Package[packages().size()]);
|
||||
}
|
||||
}
|
||||
|
||||
protected Package definePackage(String name,
|
||||
String specificationTitle,
|
||||
String specificationVersion,
|
||||
String specificationVendor,
|
||||
String implementationTitle,
|
||||
String implementationVersion,
|
||||
String implementationVendor,
|
||||
URL sealBase)
|
||||
{
|
||||
Package p = new Package
|
||||
(name, implementationTitle, implementationVersion,
|
||||
implementationVendor, specificationTitle, specificationVersion,
|
||||
specificationVendor, sealBase, this);
|
||||
|
||||
synchronized (this) {
|
||||
packages().put(name, p);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
public static ClassLoader getSystemClassLoader() {
|
||||
return ClassLoader.class.getClassLoader();
|
||||
}
|
||||
|
90
classpath/java/util/AbstractDeque.java
Normal file
90
classpath/java/util/AbstractDeque.java
Normal file
@ -0,0 +1,90 @@
|
||||
/* Copyright (c) 2008-2014, Avian Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software
|
||||
for any purpose with or without fee is hereby granted, provided
|
||||
that the above copyright notice and this permission notice appear
|
||||
in all copies.
|
||||
|
||||
There is NO WARRANTY for this software. See license.txt for
|
||||
details. */
|
||||
|
||||
package java.util;
|
||||
|
||||
public abstract class AbstractDeque<T> extends AbstractQueue<T>
|
||||
implements Deque<T> {
|
||||
|
||||
@Override
|
||||
public void push(T e) {
|
||||
addFirst(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLast(T element) {
|
||||
if (! offerLast(element)) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(T element) {
|
||||
if (! offerFirst(element)) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean offer(T element) {
|
||||
return offerLast(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T poll() {
|
||||
return pollFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T pop() {
|
||||
return removeFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T removeFirst() {
|
||||
return remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object element) {
|
||||
return removeFirstOccurrence(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T removeLast() {
|
||||
T result = pollLast();
|
||||
if (result == null) {
|
||||
throw new NoSuchElementException();
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getFirst() {
|
||||
return element();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getLast() {
|
||||
T result = peekLast();
|
||||
|
||||
if (result == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T peek() {
|
||||
return peekFirst();
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ public abstract class AbstractQueue<T> extends AbstractCollection<T> implements
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(T element) {
|
||||
if (offer(element)) {
|
||||
return true;
|
||||
@ -23,7 +24,8 @@ public abstract class AbstractQueue<T> extends AbstractCollection<T> implements
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection <? extends T> collection) {
|
||||
if (collection == null) {
|
||||
throw new NullPointerException();
|
||||
@ -35,26 +37,31 @@ public abstract class AbstractQueue<T> extends AbstractCollection<T> implements
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
while (size() > 0) {
|
||||
poll();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public T element() {
|
||||
emptyCheck();
|
||||
return peek();
|
||||
}
|
||||
|
||||
public T remove() {
|
||||
emptyCheck();
|
||||
return poll();
|
||||
}
|
||||
|
||||
private void emptyCheck() {
|
||||
if (size() == 0) {
|
||||
T result = peek();
|
||||
if (result == null) {
|
||||
throw new NoSuchElementException();
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove() {
|
||||
T result = poll();
|
||||
if (result == null) {
|
||||
throw new NoSuchElementException();
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
364
classpath/java/util/ArrayDeque.java
Normal file
364
classpath/java/util/ArrayDeque.java
Normal file
@ -0,0 +1,364 @@
|
||||
/* Copyright (c) 2008-2014, Avian Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software
|
||||
for any purpose with or without fee is hereby granted, provided
|
||||
that the above copyright notice and this permission notice appear
|
||||
in all copies.
|
||||
|
||||
There is NO WARRANTY for this software. See license.txt for
|
||||
details. */
|
||||
|
||||
package java.util;
|
||||
|
||||
public class ArrayDeque<T> extends AbstractDeque<T>
|
||||
implements Deque<T> {
|
||||
private Object[] dataArray;
|
||||
// both indexes are inclusive, except when size == 0
|
||||
private int startIndex;
|
||||
private int endIndex;
|
||||
private int size;
|
||||
private int modCount;
|
||||
|
||||
public ArrayDeque() {
|
||||
this(16);
|
||||
}
|
||||
|
||||
public ArrayDeque(int intialSize) {
|
||||
dataArray = new Object[intialSize];
|
||||
modCount = 0;
|
||||
clear();
|
||||
}
|
||||
|
||||
public ArrayDeque(Collection<? extends T> c) {
|
||||
this(c.size());
|
||||
|
||||
addAll(c);
|
||||
}
|
||||
|
||||
private void copyInto(Object[] array) {
|
||||
if (startIndex <= endIndex) {
|
||||
// only one copy needed
|
||||
System.arraycopy(dataArray, startIndex, array, 0, size);
|
||||
} else {
|
||||
int firstCopyCount = dataArray.length - startIndex;
|
||||
System.arraycopy(dataArray, startIndex, array, 0, firstCopyCount);
|
||||
System.arraycopy(dataArray, 0, array, firstCopyCount, endIndex + 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureCapacity(int newSize) {
|
||||
if (dataArray.length < newSize) {
|
||||
Object[] newArray = new Object[dataArray.length * 2];
|
||||
copyInto(newArray);
|
||||
|
||||
dataArray = newArray;
|
||||
startIndex = 0;
|
||||
endIndex = size - 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean offerFirst(T e) {
|
||||
ensureCapacity(size() + 1);
|
||||
modCount++;
|
||||
|
||||
if (size > 0) {
|
||||
// we don't need to move the head index for the first one
|
||||
startIndex--;
|
||||
if (startIndex < 0) { // wrapping to the end of the array
|
||||
startIndex = dataArray.length - 1;
|
||||
}
|
||||
}
|
||||
size++;
|
||||
dataArray[startIndex] = e;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean offerLast(T e) {
|
||||
ensureCapacity(size() + 1);
|
||||
modCount++;
|
||||
|
||||
if (size > 0) {
|
||||
// we don't need to move the tail index for the first one
|
||||
endIndex = (endIndex + 1) % dataArray.length;
|
||||
}
|
||||
size++;
|
||||
dataArray[endIndex] = e;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T pollFirst() {
|
||||
modCount++;
|
||||
|
||||
if (size == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
T result = (T)dataArray[startIndex];
|
||||
size--;
|
||||
if (size == 0) {
|
||||
startIndex = endIndex = 0;
|
||||
} else {
|
||||
startIndex = (startIndex + 1) % dataArray.length;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T pollLast() {
|
||||
modCount++;
|
||||
|
||||
if (size == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
T result = (T)dataArray[endIndex];
|
||||
size--;
|
||||
if (size == 0) {
|
||||
startIndex = endIndex = 0;
|
||||
} else {
|
||||
endIndex--;
|
||||
if (endIndex < 0) {
|
||||
endIndex = dataArray.length - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T peekFirst() {
|
||||
if (size == 0) {
|
||||
return null;
|
||||
} else {
|
||||
@SuppressWarnings("unchecked")
|
||||
T result = (T)dataArray[startIndex];
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T peekLast() {
|
||||
if (size == 0) {
|
||||
return null;
|
||||
} else {
|
||||
@SuppressWarnings("unchecked")
|
||||
T result = (T)dataArray[endIndex];
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends T> c) {
|
||||
if (c == null || c.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ensureCapacity(size() + c.size());
|
||||
|
||||
Iterator<? extends T> it = c.iterator();
|
||||
while (it.hasNext()) {
|
||||
add(it.next());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
boolean removed = false;
|
||||
Iterator<?> it = c.iterator();
|
||||
while (it.hasNext()) {
|
||||
removed = remove(it.next()) || removed;
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
private boolean remove(Object o, boolean first) {
|
||||
modCount++;
|
||||
|
||||
Iterator<T> it;
|
||||
if (first) {
|
||||
it = iterator();
|
||||
} else {
|
||||
it = descendingIterator();
|
||||
}
|
||||
while (it.hasNext()) {
|
||||
T next = it.next();
|
||||
if (next == null) {
|
||||
if (o == null) {
|
||||
it.remove();
|
||||
return true;
|
||||
}
|
||||
} else if (next.equals(o)) {
|
||||
it.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFirstOccurrence(Object o) {
|
||||
return remove(o, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeLastOccurrence(Object o) {
|
||||
return remove(o, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
size = 0;
|
||||
startIndex = endIndex = 0;
|
||||
modCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object element) {
|
||||
Iterator<T> it = iterator();
|
||||
while (it.hasNext()) {
|
||||
T next = it.next();
|
||||
if (next == null) {
|
||||
if (element == null) {
|
||||
return true;
|
||||
}
|
||||
} else if (next.equals(element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
Iterator<?> it = c.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (! contains(it.next())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
Object[] result = new Object[size];
|
||||
copyInto(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> S[] toArray(S[] array) {
|
||||
return avian.Data.toArray(this, array);
|
||||
}
|
||||
|
||||
public Iterator<T> iterator() {
|
||||
return new GenericIterator() {
|
||||
@Override
|
||||
protected int getArrayIndex() {
|
||||
int result = (currentIndex + startIndex) % dataArray.length;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Iterator<T> descendingIterator() {
|
||||
return new GenericIterator() {
|
||||
@Override
|
||||
protected int getArrayIndex() {
|
||||
int result = (endIndex - currentIndex) % dataArray.length;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private abstract class GenericIterator implements Iterator<T> {
|
||||
protected int expectedModCount = modCount;
|
||||
protected int currentIndex = 0;
|
||||
|
||||
protected abstract int getArrayIndex();
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
if (modCount != expectedModCount) {
|
||||
throw new ConcurrentModificationException();
|
||||
} else if (currentIndex == size) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
T result = (T)dataArray[getArrayIndex()];
|
||||
currentIndex++;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return currentIndex < size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
currentIndex--;
|
||||
|
||||
int removalIndex = getArrayIndex();
|
||||
if (removalIndex == startIndex) {
|
||||
// avoid array copy
|
||||
pollFirst();
|
||||
expectedModCount = modCount;
|
||||
} else if (removalIndex == endIndex) {
|
||||
// avoid array copy
|
||||
pollLast();
|
||||
expectedModCount = modCount;
|
||||
} else { // array must be copied
|
||||
Object[] newArray = new Object[dataArray.length];
|
||||
if (startIndex <= endIndex) {
|
||||
int firstCopyCount = removalIndex - startIndex;
|
||||
System.arraycopy(dataArray, startIndex,
|
||||
newArray, 0, firstCopyCount);
|
||||
System.arraycopy(dataArray, removalIndex + 1,
|
||||
newArray, firstCopyCount, size - firstCopyCount);
|
||||
} else if (removalIndex > startIndex) {
|
||||
int firstCopyCount = removalIndex - startIndex;
|
||||
System.arraycopy(dataArray, startIndex,
|
||||
newArray, 0, firstCopyCount);
|
||||
System.arraycopy(dataArray, startIndex + firstCopyCount + 1,
|
||||
newArray, firstCopyCount, dataArray.length - removalIndex - 1);
|
||||
System.arraycopy(dataArray, 0, newArray, size - removalIndex, endIndex + 1);
|
||||
} else {
|
||||
int firstCopyCount = dataArray.length - startIndex;
|
||||
System.arraycopy(dataArray, startIndex,
|
||||
newArray, 0, firstCopyCount);
|
||||
System.arraycopy(dataArray, 0,
|
||||
newArray, firstCopyCount, removalIndex);
|
||||
System.arraycopy(dataArray, removalIndex + 1,
|
||||
newArray, firstCopyCount + removalIndex, endIndex - removalIndex);
|
||||
}
|
||||
|
||||
dataArray = newArray;
|
||||
startIndex = 0;
|
||||
endIndex = --size - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
package java.util.concurrent;
|
||||
|
||||
import java.util.AbstractQueue;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Queue;
|
||||
|
||||
import avian.Atomic;
|
||||
|
||||
public class ConcurrentLinkedQueue<T> implements Queue<T> {
|
||||
public class ConcurrentLinkedQueue<T> extends AbstractQueue<T> {
|
||||
private static final long QueueHead;
|
||||
private static final long QueueTail;
|
||||
private static final long NodeNext;
|
||||
@ -67,31 +66,11 @@ public class ConcurrentLinkedQueue<T> implements Queue<T> {
|
||||
return poll(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T element() {
|
||||
T result = peek();
|
||||
if (result == null) {
|
||||
throw new NoSuchElementException();
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T poll() {
|
||||
return poll(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove() {
|
||||
T result = poll();
|
||||
if (result == null) {
|
||||
throw new NoSuchElementException();
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private T poll(boolean remove) {
|
||||
while (true) {
|
||||
Node<T> h = head;
|
||||
@ -150,12 +129,6 @@ public class ConcurrentLinkedQueue<T> implements Queue<T> {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends T> collection) {
|
||||
// TODO - implement
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object element) {
|
||||
// TODO - implement
|
||||
|
@ -1,11 +1,22 @@
|
||||
/* Copyright (c) 2008-2014, Avian Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software
|
||||
for any purpose with or without fee is hereby granted, provided
|
||||
that the above copyright notice and this permission notice appear
|
||||
in all copies.
|
||||
|
||||
There is NO WARRANTY for this software. See license.txt for
|
||||
details. */
|
||||
|
||||
package java.util.concurrent;
|
||||
|
||||
import java.util.AbstractQueue;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class LinkedBlockingQueue<T> implements BlockingQueue<T> {
|
||||
public class LinkedBlockingQueue<T> extends AbstractQueue<T>
|
||||
implements BlockingQueue<T> {
|
||||
private final Object collectionLock;
|
||||
private final LinkedList<T> storage;
|
||||
private final int capacity;
|
||||
@ -84,15 +95,6 @@ public class LinkedBlockingQueue<T> implements BlockingQueue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(T element) {
|
||||
if (! offer(element)) {
|
||||
throw new IllegalStateException("At capacity");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean offer(T element) {
|
||||
synchronized (collectionLock) {
|
||||
@ -158,17 +160,6 @@ public class LinkedBlockingQueue<T> implements BlockingQueue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T element() {
|
||||
T result = peek();
|
||||
|
||||
if (result == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// should be synchronized on collectionLock before calling
|
||||
private T removeFirst() {
|
||||
T result = storage.removeFirst();
|
||||
@ -209,17 +200,6 @@ public class LinkedBlockingQueue<T> implements BlockingQueue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove() {
|
||||
T result = poll();
|
||||
|
||||
if (result == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int drainTo(Collection<? super T> c) {
|
||||
return drainTo(c, Integer.MAX_VALUE);
|
||||
@ -256,11 +236,6 @@ public class LinkedBlockingQueue<T> implements BlockingQueue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object element) {
|
||||
synchronized (collectionLock) {
|
||||
|
@ -1577,9 +1577,6 @@ class Classpath {
|
||||
virtual const char*
|
||||
bootClasspath() = 0;
|
||||
|
||||
virtual void
|
||||
updatePackageMap(Thread* t, object class_) = 0;
|
||||
|
||||
virtual object
|
||||
makeDirectByteBuffer(Thread* t, void* p, jlong capacity) = 0;
|
||||
|
||||
|
@ -238,6 +238,36 @@ Avian_avian_SystemClassLoader_getClass
|
||||
(getJClass(t, reinterpret_cast<object>(arguments[0])));
|
||||
}
|
||||
|
||||
extern "C" AVIAN_EXPORT int64_t JNICALL
|
||||
Avian_avian_SystemClassLoader_getPackageSource
|
||||
(Thread* t, object, uintptr_t* arguments)
|
||||
{
|
||||
object name = reinterpret_cast<object>(arguments[0]);
|
||||
PROTECT(t, name);
|
||||
|
||||
ACQUIRE(t, t->m->classLock);
|
||||
|
||||
THREAD_RUNTIME_ARRAY(t, char, chars, stringLength(t, name) + 2);
|
||||
stringChars(t, name, RUNTIME_ARRAY_BODY(chars));
|
||||
replace('.', '/', RUNTIME_ARRAY_BODY(chars));
|
||||
RUNTIME_ARRAY_BODY(chars)[stringLength(t, name)] = '/';
|
||||
RUNTIME_ARRAY_BODY(chars)[stringLength(t, name) + 1] = 0;
|
||||
|
||||
object key = makeByteArray(t, RUNTIME_ARRAY_BODY(chars));
|
||||
|
||||
object array = hashMapFind
|
||||
(t, root(t, Machine::PackageMap), key, byteArrayHash, byteArrayEqual);
|
||||
|
||||
if (array) {
|
||||
return reinterpret_cast<uintptr_t>
|
||||
(makeLocalReference
|
||||
(t, t->m->classpath->makeString
|
||||
(t, array, 0, byteArrayLength(t, array))));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef AVIAN_HEAPDUMP
|
||||
|
||||
extern "C" AVIAN_EXPORT void JNICALL
|
||||
|
@ -22,6 +22,7 @@ extern "C" int JNI_OnLoad(JavaVM*, void*);
|
||||
#include "avian/machine.h"
|
||||
#include "avian/classpath-common.h"
|
||||
#include "avian/process.h"
|
||||
#include "avian/util.h"
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
const char* getErrnoDescription(int err); // This function is defined in mingw-extensions.cpp
|
||||
@ -488,9 +489,22 @@ class MyClasspath : public Classpath {
|
||||
}
|
||||
|
||||
virtual void
|
||||
boot(Thread*)
|
||||
boot(Thread* t)
|
||||
{
|
||||
// ignore
|
||||
object c = resolveClass
|
||||
(t, root(t, Machine::BootLoader), "java/lang/ClassLoader");
|
||||
PROTECT(t, c);
|
||||
|
||||
object constructor = resolveMethod
|
||||
(t, c, "<init>", "(Ljava/lang/ClassLoader;Z)V");
|
||||
PROTECT(t, constructor);
|
||||
|
||||
t->m->processor->invoke
|
||||
(t, constructor, root(t, Machine::BootLoader), 0, true);
|
||||
|
||||
t->m->processor->invoke
|
||||
(t, constructor, root(t, Machine::AppLoader),
|
||||
root(t, Machine::BootLoader), false);
|
||||
}
|
||||
|
||||
virtual const char*
|
||||
@ -499,12 +513,6 @@ class MyClasspath : public Classpath {
|
||||
return AVIAN_CLASSPATH;
|
||||
}
|
||||
|
||||
virtual void
|
||||
updatePackageMap(Thread*, object)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
virtual object
|
||||
makeDirectByteBuffer(Thread* t, void* p, jlong capacity)
|
||||
{
|
||||
|
@ -133,12 +133,6 @@ class MyClasspath : public Classpath {
|
||||
return AVIAN_CLASSPATH;
|
||||
}
|
||||
|
||||
virtual void
|
||||
updatePackageMap(Thread*, object)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
virtual object
|
||||
makeDirectByteBuffer(Thread* t, void* p, jlong capacity)
|
||||
{
|
||||
|
@ -774,62 +774,6 @@ class MyClasspath : public Classpath {
|
||||
return classpath;
|
||||
}
|
||||
|
||||
virtual void
|
||||
updatePackageMap(Thread* t, object class_)
|
||||
{
|
||||
PROTECT(t, class_);
|
||||
|
||||
if (root(t, Machine::PackageMap) == 0) {
|
||||
setRoot(t, Machine::PackageMap, makeHashMap(t, 0, 0));
|
||||
}
|
||||
|
||||
object className = vm::className(t, class_);
|
||||
if ('[' != byteArrayBody(t, className, 0)) {
|
||||
THREAD_RUNTIME_ARRAY
|
||||
(t, char, packageName, byteArrayLength(t, className));
|
||||
|
||||
char* s = reinterpret_cast<char*>(&byteArrayBody(t, className, 0));
|
||||
char* p = strrchr(s, '/');
|
||||
|
||||
if (p) {
|
||||
int length = (p - s) + 1;
|
||||
memcpy(RUNTIME_ARRAY_BODY(packageName),
|
||||
&byteArrayBody(t, className, 0),
|
||||
length);
|
||||
RUNTIME_ARRAY_BODY(packageName)[length] = 0;
|
||||
|
||||
object key = vm::makeByteArray
|
||||
(t, "%s", RUNTIME_ARRAY_BODY(packageName));
|
||||
PROTECT(t, key);
|
||||
|
||||
hashMapRemove
|
||||
(t, root(t, Machine::PackageMap), key, byteArrayHash,
|
||||
byteArrayEqual);
|
||||
|
||||
object source = classSource(t, class_);
|
||||
if (source) {
|
||||
// note that we strip the "file:" prefix, since
|
||||
// Package.defineSystemPackage expects an unadorned
|
||||
// filename:
|
||||
const unsigned PrefixLength = 5;
|
||||
unsigned sourceNameLength = byteArrayLength(t, source)
|
||||
- PrefixLength;
|
||||
THREAD_RUNTIME_ARRAY(t, char, sourceName, sourceNameLength);
|
||||
memcpy(RUNTIME_ARRAY_BODY(sourceName),
|
||||
&byteArrayBody(t, source, PrefixLength),
|
||||
sourceNameLength);
|
||||
|
||||
source = vm::makeByteArray(t, "%s", RUNTIME_ARRAY_BODY(sourceName));
|
||||
} else {
|
||||
source = vm::makeByteArray(t, "avian-dummy-package-source");
|
||||
}
|
||||
|
||||
hashMapInsert
|
||||
(t, root(t, Machine::PackageMap), key, source, byteArrayHash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual object
|
||||
makeDirectByteBuffer(Thread* t, void* p, jlong capacity)
|
||||
{
|
||||
|
@ -3042,6 +3042,61 @@ findInTable(Thread* t, object table, object name, object spec,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
updatePackageMap(Thread* t, object class_)
|
||||
{
|
||||
PROTECT(t, class_);
|
||||
|
||||
if (root(t, Machine::PackageMap) == 0) {
|
||||
setRoot(t, Machine::PackageMap, makeHashMap(t, 0, 0));
|
||||
}
|
||||
|
||||
object className = vm::className(t, class_);
|
||||
if ('[' != byteArrayBody(t, className, 0)) {
|
||||
THREAD_RUNTIME_ARRAY
|
||||
(t, char, packageName, byteArrayLength(t, className));
|
||||
|
||||
char* s = reinterpret_cast<char*>(&byteArrayBody(t, className, 0));
|
||||
char* p = strrchr(s, '/');
|
||||
|
||||
if (p) {
|
||||
int length = (p - s) + 1;
|
||||
memcpy(RUNTIME_ARRAY_BODY(packageName),
|
||||
&byteArrayBody(t, className, 0),
|
||||
length);
|
||||
RUNTIME_ARRAY_BODY(packageName)[length] = 0;
|
||||
|
||||
object key = vm::makeByteArray
|
||||
(t, "%s", RUNTIME_ARRAY_BODY(packageName));
|
||||
PROTECT(t, key);
|
||||
|
||||
hashMapRemove
|
||||
(t, root(t, Machine::PackageMap), key, byteArrayHash,
|
||||
byteArrayEqual);
|
||||
|
||||
object source = classSource(t, class_);
|
||||
if (source) {
|
||||
// note that we strip the "file:" prefix, since OpenJDK's
|
||||
// Package.defineSystemPackage expects an unadorned filename:
|
||||
const unsigned PrefixLength = 5;
|
||||
unsigned sourceNameLength = byteArrayLength(t, source)
|
||||
- PrefixLength;
|
||||
THREAD_RUNTIME_ARRAY(t, char, sourceName, sourceNameLength);
|
||||
memcpy(RUNTIME_ARRAY_BODY(sourceName),
|
||||
&byteArrayBody(t, source, PrefixLength),
|
||||
sourceNameLength);
|
||||
|
||||
source = vm::makeByteArray(t, "%s", RUNTIME_ARRAY_BODY(sourceName));
|
||||
} else {
|
||||
source = vm::makeByteArray(t, "avian-dummy-package-source");
|
||||
}
|
||||
|
||||
hashMapInsert
|
||||
(t, root(t, Machine::PackageMap), key, source, byteArrayHash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace vm {
|
||||
@ -4295,7 +4350,7 @@ resolveSystemClass(Thread* t, object loader, object spec, bool throw_,
|
||||
if (class_) {
|
||||
hashMapInsert(t, classLoaderMap(t, loader), spec, class_, byteArrayHash);
|
||||
|
||||
t->m->classpath->updatePackageMap(t, class_);
|
||||
updatePackageMap(t, class_);
|
||||
} else if (throw_) {
|
||||
throwNew(t, throwType, "%s", &byteArrayBody(t, spec, 0));
|
||||
}
|
||||
|
161
test/ArrayDequeTest.java
Normal file
161
test/ArrayDequeTest.java
Normal file
@ -0,0 +1,161 @@
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class ArrayDequeTest {
|
||||
private static void verify(boolean val) {
|
||||
if (! val) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
QueueHelper.sizeTest(new ArrayDeque<Object>());
|
||||
QueueHelper.isEmptyTest(new ArrayDeque<Object>());
|
||||
QueueHelper.addTest(new ArrayDeque<Object>());
|
||||
QueueHelper.addAllTest(new ArrayDeque<Object>());
|
||||
QueueHelper.elementTest(new ArrayDeque<Object>());
|
||||
QueueHelper.elementFail(new ArrayDeque<Object>());
|
||||
QueueHelper.removeEmptyFail(new ArrayDeque<Object>());
|
||||
QueueHelper.removeTest(new ArrayDeque<Object>());
|
||||
QueueHelper.containsTest(new ArrayDeque<Object>());
|
||||
QueueHelper.containsAllTest(new ArrayDeque<Object>());
|
||||
QueueHelper.removeObjectTest(new ArrayDeque<Object>());
|
||||
QueueHelper.removeAllTest(new ArrayDeque<Object>());
|
||||
QueueHelper.clearTest(new ArrayDeque<Object>());
|
||||
QueueHelper.toArrayTest(new ArrayDeque<Object>());
|
||||
|
||||
DequeHelper.addFirstTest(new ArrayDeque<Object>());
|
||||
DequeHelper.addLastTest(new ArrayDeque<Object>());
|
||||
DequeHelper.removeFirstTest(new ArrayDeque<Object>());
|
||||
DequeHelper.removeLastTest(new ArrayDeque<Object>());
|
||||
|
||||
iterateTest(false);
|
||||
iterateTest(true);
|
||||
iteratorRemoveTest(false);
|
||||
iteratorRemoveTest(true);
|
||||
iteratorNoElementFail(false);
|
||||
iteratorNoElementFail(true);
|
||||
}
|
||||
|
||||
private static void iterateTest(boolean desc) {
|
||||
int testQty = 10;
|
||||
LinkedList<Object> compareList = new LinkedList<Object>();
|
||||
ArrayDeque<Object> ad = new ArrayDeque<Object>();
|
||||
|
||||
for (int i = 0; i < testQty; i++) {
|
||||
Object o = new Object();
|
||||
compareList.add(o);
|
||||
ad.add(o);
|
||||
}
|
||||
|
||||
Iterator<Object> compIt;
|
||||
Iterator<Object> testIt;
|
||||
if (desc) {
|
||||
compIt = compareList.descendingIterator();
|
||||
testIt = ad.descendingIterator();
|
||||
} else {
|
||||
compIt = compareList.iterator();
|
||||
testIt = ad.iterator();
|
||||
}
|
||||
while (testIt.hasNext()) {
|
||||
verify(testIt.next() == compIt.next());
|
||||
}
|
||||
|
||||
// remove from the front
|
||||
compareList.removeFirst();
|
||||
ad.removeFirst();
|
||||
|
||||
if (desc) {
|
||||
compIt = compareList.descendingIterator();
|
||||
testIt = ad.descendingIterator();
|
||||
} else {
|
||||
compIt = compareList.iterator();
|
||||
testIt = ad.iterator();
|
||||
}
|
||||
while (testIt.hasNext()) {
|
||||
verify(testIt.next() == compIt.next());
|
||||
}
|
||||
|
||||
// remove from the end
|
||||
compareList.removeLast();
|
||||
ad.removeLast();
|
||||
|
||||
if (desc) {
|
||||
compIt = compareList.descendingIterator();
|
||||
testIt = ad.descendingIterator();
|
||||
} else {
|
||||
compIt = compareList.iterator();
|
||||
testIt = ad.iterator();
|
||||
}
|
||||
while (testIt.hasNext()) {
|
||||
verify(testIt.next() == compIt.next());
|
||||
}
|
||||
}
|
||||
|
||||
private static void iteratorRemoveTest(boolean desc) {
|
||||
int testQty = 20;
|
||||
LinkedList<Object> compareList = new LinkedList<Object>();
|
||||
ArrayDeque<Object> ad = new ArrayDeque<Object>();
|
||||
|
||||
for (int i = 0; i < testQty; i++) {
|
||||
Object o = new Object();
|
||||
compareList.add(o);
|
||||
ad.add(o);
|
||||
}
|
||||
|
||||
Iterator<Object> compIt;
|
||||
Iterator<Object> testIt;
|
||||
if (desc) {
|
||||
compIt = compareList.descendingIterator();
|
||||
testIt = ad.descendingIterator();
|
||||
} else {
|
||||
compIt = compareList.iterator();
|
||||
testIt = ad.iterator();
|
||||
}
|
||||
boolean flip = true; // start with true to ensure first is removed
|
||||
while (testIt.hasNext()) {
|
||||
// advance iterators
|
||||
testIt.next();
|
||||
compIt.next();
|
||||
|
||||
if (flip || ! testIt.hasNext()) {
|
||||
compIt.remove();
|
||||
testIt.remove();
|
||||
flip = false;
|
||||
} else {
|
||||
flip = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (desc) {
|
||||
compIt = compareList.descendingIterator();
|
||||
testIt = ad.descendingIterator();
|
||||
} else {
|
||||
compIt = compareList.iterator();
|
||||
testIt = ad.iterator();
|
||||
}
|
||||
while (testIt.hasNext()) {
|
||||
verify(testIt.next() == compIt.next());
|
||||
}
|
||||
}
|
||||
|
||||
private static void iteratorNoElementFail(boolean desc) {
|
||||
ArrayDeque<Object> ad = new ArrayDeque<Object>();
|
||||
|
||||
Iterator<Object> testIt;
|
||||
if (desc) {
|
||||
testIt = ad.descendingIterator();
|
||||
} else {
|
||||
testIt = ad.iterator();
|
||||
}
|
||||
|
||||
try {
|
||||
testIt.next();
|
||||
throw new RuntimeException("Exception should have thrown");
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
55
test/DequeHelper.java
Normal file
55
test/DequeHelper.java
Normal file
@ -0,0 +1,55 @@
|
||||
import java.util.Deque;
|
||||
|
||||
public class DequeHelper {
|
||||
private static void verify(boolean val) {
|
||||
if (! val) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
// prevents unit test failure
|
||||
}
|
||||
|
||||
public static void addFirstTest(Deque<Object> q) {
|
||||
Object firstObject = new Object();
|
||||
Object lastObject = new Object();
|
||||
q.addFirst(lastObject);
|
||||
q.addFirst(firstObject);
|
||||
|
||||
verify(q.size() == 2);
|
||||
verify(q.peekFirst() == firstObject);
|
||||
verify(q.peekLast() == lastObject);
|
||||
}
|
||||
|
||||
public static void addLastTest(Deque<Object> q) {
|
||||
Object firstObject = new Object();
|
||||
Object lastObject = new Object();
|
||||
q.addLast(firstObject);
|
||||
q.addLast(lastObject);
|
||||
|
||||
verify(q.size() == 2);
|
||||
verify(q.peekFirst() == firstObject);
|
||||
verify(q.peekLast() == lastObject);
|
||||
}
|
||||
|
||||
public static void removeFirstTest(Deque<Object> q) {
|
||||
Object firstObject = new Object();
|
||||
Object lastObject = new Object();
|
||||
q.addLast(firstObject);
|
||||
q.addLast(lastObject);
|
||||
|
||||
verify(q.removeFirst() == firstObject);
|
||||
verify(q.removeFirst() == lastObject);
|
||||
}
|
||||
|
||||
public static void removeLastTest(Deque<Object> q) {
|
||||
Object firstObject = new Object();
|
||||
Object lastObject = new Object();
|
||||
q.addLast(firstObject);
|
||||
q.addLast(lastObject);
|
||||
|
||||
verify(q.removeLast() == lastObject);
|
||||
verify(q.removeLast() == firstObject);
|
||||
}
|
||||
}
|
@ -1,40 +1,38 @@
|
||||
import java.util.LinkedList;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
public class LinkedBlockingQueueTest {
|
||||
private static final int DELAY_TILL_ACTION = 10;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
remainingCapacityTest();
|
||||
sizeTest();
|
||||
isEmptyTest();
|
||||
addTest();
|
||||
QueueHelper.sizeTest(new LinkedBlockingQueue<Object>());
|
||||
QueueHelper.isEmptyTest(new LinkedBlockingQueue<Object>());
|
||||
QueueHelper.addTest(new LinkedBlockingQueue<Object>());
|
||||
addCapacityFail();
|
||||
offerTest();
|
||||
offerWithTimeoutTest();
|
||||
offerTimeoutTest();
|
||||
putTest();
|
||||
addAllTest();
|
||||
QueueHelper.addAllTest(new LinkedBlockingQueue<Object>());
|
||||
addAllFail();
|
||||
elementTest();
|
||||
elementFail();
|
||||
QueueHelper.elementTest(new LinkedBlockingQueue<Object>());
|
||||
QueueHelper.elementFail(new LinkedBlockingQueue<Object>());
|
||||
pollEmptyTest();
|
||||
pollTest();
|
||||
pollTimeoutTest();
|
||||
takeTest();
|
||||
removeEmptyTest();
|
||||
removeTest();
|
||||
QueueHelper.removeEmptyFail(new LinkedBlockingQueue<Object>());
|
||||
QueueHelper.removeTest(new LinkedBlockingQueue<Object>());
|
||||
drainToTest();
|
||||
drainToLimitTest();
|
||||
containsTest();
|
||||
containsAllTest();
|
||||
removeObjectTest();
|
||||
removeAllTest();
|
||||
clearTest();
|
||||
toArrayTest();
|
||||
QueueHelper.containsTest(new LinkedBlockingQueue<Object>());
|
||||
QueueHelper.containsAllTest(new LinkedBlockingQueue<Object>());
|
||||
QueueHelper.removeObjectTest(new LinkedBlockingQueue<Object>());
|
||||
QueueHelper.removeAllTest(new LinkedBlockingQueue<Object>());
|
||||
QueueHelper.clearTest(new LinkedBlockingQueue<Object>());
|
||||
QueueHelper.toArrayTest(new LinkedBlockingQueue<Object>());
|
||||
}
|
||||
|
||||
private static void verify(boolean val) {
|
||||
@ -51,31 +49,6 @@ public class LinkedBlockingQueueTest {
|
||||
verify(lbq.remainingCapacity() == 1);
|
||||
}
|
||||
|
||||
private static void sizeTest() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
verify(lbq.size() == 0);
|
||||
|
||||
lbq.add(new Object());
|
||||
verify(lbq.size() == 1);
|
||||
}
|
||||
|
||||
private static void isEmptyTest() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
verify(lbq.isEmpty());
|
||||
|
||||
lbq.add(new Object());
|
||||
verify(! lbq.isEmpty());
|
||||
}
|
||||
|
||||
private static void addTest() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
Object testObject = new Object();
|
||||
lbq.add(testObject);
|
||||
|
||||
verify(lbq.size() == 1);
|
||||
verify(lbq.peek() == testObject);
|
||||
}
|
||||
|
||||
private static void addCapacityFail() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>(1);
|
||||
Object testObject = new Object();
|
||||
@ -139,20 +112,6 @@ public class LinkedBlockingQueueTest {
|
||||
verify(lbq.peek() == testObject);
|
||||
}
|
||||
|
||||
private static void addAllTest() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
LinkedList<Object> toAdd = new LinkedList<Object>();
|
||||
toAdd.add(new Object());
|
||||
toAdd.add(new Object());
|
||||
|
||||
lbq.addAll(toAdd);
|
||||
|
||||
verify(lbq.size() == toAdd.size());
|
||||
while (! lbq.isEmpty()) {
|
||||
verify(lbq.remove() == toAdd.remove());
|
||||
}
|
||||
}
|
||||
|
||||
private static void addAllFail() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>(1);
|
||||
LinkedList<Object> toAdd = new LinkedList<Object>();
|
||||
@ -167,25 +126,6 @@ public class LinkedBlockingQueueTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static void elementTest() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
Object testObject = new Object();
|
||||
lbq.add(testObject);
|
||||
|
||||
verify(lbq.element() == testObject);
|
||||
}
|
||||
|
||||
private static void elementFail() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
|
||||
try {
|
||||
lbq.element();
|
||||
throw new RuntimeException("Exception should have thrown");
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
private static void pollEmptyTest() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
|
||||
@ -240,25 +180,6 @@ public class LinkedBlockingQueueTest {
|
||||
verify(lbq.take() == testObject);
|
||||
}
|
||||
|
||||
private static void removeEmptyTest() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
|
||||
try {
|
||||
lbq.remove();
|
||||
throw new RuntimeException("Exception should have thrown");
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeTest() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
Object testObject = new Object();
|
||||
lbq.add(testObject);
|
||||
|
||||
verify(lbq.remove() == testObject);
|
||||
}
|
||||
|
||||
private static void drainToTest() {
|
||||
int objQty = 2;
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
@ -284,78 +205,4 @@ public class LinkedBlockingQueueTest {
|
||||
verify(drainToResult.size() == limit);
|
||||
verify(lbq.size() == objQty - limit);
|
||||
}
|
||||
|
||||
private static void containsTest() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
Object testObject = new Object();
|
||||
|
||||
verify(! lbq.contains(testObject));
|
||||
|
||||
lbq.add(testObject);
|
||||
verify(lbq.contains(testObject));
|
||||
}
|
||||
|
||||
private static void containsAllTest() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
Object testObject = new Object();
|
||||
lbq.add(testObject);
|
||||
|
||||
LinkedList<Object> testList = new LinkedList<Object>();
|
||||
testList.add(testObject);
|
||||
testList.add(new Object());
|
||||
|
||||
verify(! lbq.containsAll(testList));
|
||||
|
||||
lbq.addAll(testList);
|
||||
verify(lbq.containsAll(testList));
|
||||
}
|
||||
|
||||
private static void removeObjectTest() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
Object testObject = new Object();
|
||||
|
||||
verify(! lbq.remove(testObject));
|
||||
|
||||
lbq.add(testObject);
|
||||
verify(lbq.remove(testObject));
|
||||
}
|
||||
|
||||
private static void removeAllTest() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
Object testObject = new Object();
|
||||
lbq.add(testObject);
|
||||
|
||||
LinkedList<Object> testList = new LinkedList<Object>();
|
||||
testList.add(testObject);
|
||||
testList.add(new Object());
|
||||
|
||||
verify(lbq.removeAll(testList));
|
||||
|
||||
lbq.addAll(testList);
|
||||
verify(lbq.removeAll(testList));
|
||||
}
|
||||
|
||||
private static void clearTest() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
lbq.add(new Object());
|
||||
|
||||
lbq.clear();
|
||||
|
||||
verify(lbq.isEmpty());
|
||||
}
|
||||
|
||||
private static void toArrayTest() {
|
||||
LinkedBlockingQueue<Object> lbq = new LinkedBlockingQueue<Object>();
|
||||
|
||||
if (lbq.toArray().length != 0) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
Object testObject = new Object();
|
||||
lbq.add(testObject);
|
||||
|
||||
Object[] result = lbq.toArray();
|
||||
verify(result.length == 1);
|
||||
verify(result[0] == testObject);
|
||||
}
|
||||
}
|
||||
|
149
test/QueueHelper.java
Normal file
149
test/QueueHelper.java
Normal file
@ -0,0 +1,149 @@
|
||||
import java.util.LinkedList;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Queue;
|
||||
|
||||
public class QueueHelper {
|
||||
private static void verify(boolean val) {
|
||||
if (! val) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
// prevents unit test failure
|
||||
}
|
||||
|
||||
public static void sizeTest(Queue<Object> q) {
|
||||
verify(q.size() == 0);
|
||||
|
||||
q.add(new Object());
|
||||
verify(q.size() == 1);
|
||||
}
|
||||
|
||||
public static void isEmptyTest(Queue<Object> q) {
|
||||
verify(q.isEmpty());
|
||||
|
||||
q.add(new Object());
|
||||
verify(! q.isEmpty());
|
||||
}
|
||||
|
||||
public static void addTest(Queue<Object> q) {
|
||||
Object testObject = new Object();
|
||||
q.add(testObject);
|
||||
|
||||
verify(q.size() == 1);
|
||||
verify(q.peek() == testObject);
|
||||
}
|
||||
|
||||
public static void addAllTest(Queue<Object> q) {
|
||||
LinkedList<Object> toAdd = new LinkedList<Object>();
|
||||
toAdd.add(new Object());
|
||||
toAdd.add(new Object());
|
||||
|
||||
q.addAll(toAdd);
|
||||
|
||||
verify(q.size() == toAdd.size());
|
||||
while (! q.isEmpty()) {
|
||||
verify(q.remove() == toAdd.remove());
|
||||
}
|
||||
}
|
||||
|
||||
public static void elementTest(Queue<Object> q) {
|
||||
Object testObject = new Object();
|
||||
q.add(testObject);
|
||||
|
||||
verify(q.element() == testObject);
|
||||
}
|
||||
|
||||
public static void elementFail(Queue<Object> q) {
|
||||
try {
|
||||
q.element();
|
||||
throw new RuntimeException("Exception should have thrown");
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeTest(Queue<Object> q) {
|
||||
Object testObject = new Object();
|
||||
q.add(testObject);
|
||||
|
||||
verify(q.remove() == testObject);
|
||||
}
|
||||
|
||||
public static void removeEmptyFail(Queue<Object> q) {
|
||||
try {
|
||||
q.remove();
|
||||
throw new RuntimeException("Exception should have thrown");
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public static void containsTest(Queue<Object> q) {
|
||||
Object testObject = new Object();
|
||||
|
||||
verify(! q.contains(testObject));
|
||||
|
||||
q.add(testObject);
|
||||
verify(q.contains(testObject));
|
||||
}
|
||||
|
||||
public static void containsAllTest(Queue<Object> q) {
|
||||
Object testObject = new Object();
|
||||
q.add(testObject);
|
||||
|
||||
LinkedList<Object> testList = new LinkedList<Object>();
|
||||
testList.add(testObject);
|
||||
testList.add(new Object());
|
||||
|
||||
verify(! q.containsAll(testList));
|
||||
|
||||
q.addAll(testList);
|
||||
verify(q.containsAll(testList));
|
||||
}
|
||||
|
||||
public static void removeObjectTest(Queue<Object> q) {
|
||||
Object testObject = new Object();
|
||||
|
||||
verify(! q.remove(testObject));
|
||||
|
||||
q.add(testObject);
|
||||
verify(q.remove(testObject));
|
||||
}
|
||||
|
||||
public static void removeAllTest(Queue<Object> q) {
|
||||
Object testObject = new Object();
|
||||
q.add(testObject);
|
||||
|
||||
LinkedList<Object> testList = new LinkedList<Object>();
|
||||
testList.add(testObject);
|
||||
testList.add(new Object());
|
||||
|
||||
verify(q.removeAll(testList));
|
||||
|
||||
q.addAll(testList);
|
||||
verify(q.removeAll(testList));
|
||||
}
|
||||
|
||||
public static void clearTest(Queue<Object> q) {
|
||||
q.add(new Object());
|
||||
|
||||
q.clear();
|
||||
|
||||
verify(q.isEmpty());
|
||||
}
|
||||
|
||||
public static void toArrayTest(Queue<Object> q) {
|
||||
if (q.toArray().length != 0) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
Object testObject = new Object();
|
||||
q.add(testObject);
|
||||
|
||||
Object[] result = q.toArray();
|
||||
verify(result.length == 1);
|
||||
verify(result[0] == testObject);
|
||||
}
|
||||
}
|
@ -249,6 +249,9 @@ public class Reflection {
|
||||
expect(getClass().getDeclaringClass() == null);
|
||||
}
|
||||
}.run();
|
||||
|
||||
expect(avian.testing.annotations.Test.class.getPackage().getName().equals
|
||||
("avian.testing.annotations"));
|
||||
}
|
||||
|
||||
protected static class Baz {
|
||||
|
Loading…
Reference in New Issue
Block a user