If you think the Android project coursera-android-pos listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package edu.vuum.mooca;
/*fromwww.java2s.com*/import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
/**
* @class BuggyBlockingQueue
*
* @brief Defines a buggy version of the BlockingQueue interface that
* doesn't implement any synchronization mechanisms, so of
* course it will fail horribly, which is the intent!
*/publicclass BuggyBlockingQueue<E> implements BlockingQueue<E> {
/**
* ArrayList doesn't provide any synchronization, so it will not
* work correctly when called from multiple Java Threads.
*/private ArrayList<E> mList = null;
/**
* Constructor just creates an ArrayList of the appropriate size.
*/public BuggyBlockingQueue(int initialSize) {
mList = new ArrayList<E>(initialSize);
}
/**
* Insert msg at the tail of the queue, but doesn't block if the
* queue is full.
*/publicvoid put(E msg) throws InterruptedException {
mList.add(msg);
}
/**
* Remove msg from the head of the queue, but doesn't block if the
* queue is empty.
*/public E take() throws InterruptedException {
return mList.remove(0);
}
/**
* All these methods are inherited from the BlockingQueue
* interface. They are defined as no-ops to ensure the "Buggyness"
* of this class ;-)
*/publicint drainTo(Collection<? super E> c) {
return 0;
}
publicint drainTo(Collection<? super E> c, int maxElements) {
return 0;
}
publicboolean contains(Object o) {
return false;
}
publicboolean remove(Object o) {
return false;
}
publicint remainingCapacity() {
return 0;
}
public E poll() {
return null;
}
public E poll(long timeout, TimeUnit unit) throws InterruptedException {
<<<<<<< HEAD
return take();
=======
return null;
>>>>>>> 9fd1c4e49778d97613b3d9cc324c279dfb2e7274
}
public E peek() {
return null;
}
publicboolean offer(E e) {
return false;
}
publicboolean offer(E e, long timeout, TimeUnit unit) {
<<<<<<< HEAD
try {
put(e);
}
catch (InterruptedException ex) {
// Just swallow this exception for this simple (buggy) test.
}
return true;
=======
return false;
>>>>>>> 9fd1c4e49778d97613b3d9cc324c279dfb2e7274
}
publicboolean add(E e) {
return false;
}
public E element() {
return null;
}
public E remove() {
return null;
}
publicvoid clear() {
}
publicboolean retainAll(Collection<?> collection) {
return false;
}
publicboolean removeAll(Collection<?> collection) {
return false;
}
publicboolean addAll(Collection<? extends E> collection) {
return false;
}
publicboolean containsAll(Collection<?> collection) {
return false;
}
public Object[] toArray() {
return null;
}
public <T> T[] toArray(T[] array) {
return null;
}
public Iterator<E> iterator() {
return null;
}
publicboolean isEmpty() {
return false;
}
publicint size() {
return 0;
}
}