Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please give me all necessary screenshot and comments . (I use Eclipse) Thanks import java.lang.reflect.*; import com.abc.pp.fifo.*; /** * Implementation of {@link PPBoundedFifo} which uses

Please give me all necessary screenshot and comments. (I use Eclipse) Thanks

import java.lang.reflect.*;

import com.abc.pp.fifo.*;

/** * Implementation of {@link PPBoundedFifo} which uses a circular array * internally. *

* Look at the documentation in PPBoundedFifo to see how the methods are * supposed to work. *

* The data is stored in the slots array. count is the number of items currently * in the FIFO. When the FIFO is not empty, head is the index of the next item * to remove. When the FIFO is not full, tail is the index of the next available * slot to use for an added item. Both head and tail need to jump to index 0 * when they "increment" past the last valid index of slots (this is what makes * it circular). *

* See Circular Buffer * on Wikipedia for more information. */ public class CircularArrayPPBoundedFifo implements PPBoundedFifo { private final Class itemType; private final T[] slots; private int head; private int tail; private int count; private final Object lockObject;

public CircularArrayPPBoundedFifo(int fixedCapacity, Class itemType, Object proposedLockObject) {

lockObject = proposedLockObject != null ? proposedLockObject : new Object();

if ( fixedCapacity < 1 ) { throw new IllegalArgumentException( "fixedCapacity must be at least 1"); }

if (itemType == null) { throw new IllegalArgumentException("itemType must not be null"); } this.itemType = itemType;

slots = createTypeArray(fixedCapacity); head = 0; tail = 0; count = 0;

// TODO - add more to constructor if you need to....but don't change code above this line }

// this constructor is correct as written - do not change public CircularArrayPPBoundedFifo(int fixedCapacity, Class itemType) { this(fixedCapacity, itemType, null); }

@SuppressWarnings("unchecked") private T[] createTypeArray(int size) { T[] array = (T[]) Array.newInstance(itemType, size); return array; }

// this method is correct as written - do not change @Override public int getCount() { synchronized ( lockObject ) { return count; } }

@Override public boolean isEmpty() { // FIXME return false; }

@Override public boolean isFull() { // FIXME return false; }

@Override public void clear() { // FIXME }

// this method is correct as written - do not change @Override public int getCapacity() { return slots.length; }

@Override public void add(T item) throws InterruptedException { // FIXME }

@Override public T remove() throws InterruptedException { // FIXME return null; }

// this method is correct as written - do not change @Override public Object getLockObject() { return lockObject; }

// this method is correct as written - do not change @Override public Class getItemType() { return itemType; }

@Override public void addAll(T[] items) throws InterruptedException { // FIXME }

@Override public T[] removeAtLeastOne() throws InterruptedException { // FIXME return null; }

@Override public T[] removeAll() { // FIXME return null; }

@Override public boolean waitUntilEmpty(long msTimeout) throws InterruptedException { // FIXME return false; }

// this method is correct as written - do not change @Override public void waitUntilEmpty() throws InterruptedException { waitUntilEmpty(0); }

@Override public boolean waitWhileEmpty(long msTimeout) throws InterruptedException { // FIXME return false; }

@Override public void waitWhileEmpty() throws InterruptedException { // FIXME }

@Override public boolean waitUntilFull(long msTimeout) throws InterruptedException { // FIXME return false; }

@Override public void waitUntilFull() throws InterruptedException { // FIXME }

@Override public boolean waitWhileFull(long msTimeout) throws InterruptedException { // FIXME return false; }

@Override public void waitWhileFull() throws InterruptedException { // FIXME } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

More Books

Students also viewed these Databases questions

Question

what is the output if 1 2 3 ABC is the input?

Answered: 1 week ago