Java – Limiter capacity transfer queue

An attempt to create a limited capacity LinkedTransferQueue by deformation.
Limiting capacity also means losing some functionality:

import java.util.AbstractQueue;
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TransferQueue;
import java.util.function.Predicate;

/ **
* A limited capacity transfer queue.
* /
public class LimitLinkedTransferQueue implements TransferQueue {

private ending int maxSize;
private volatile int size = 0;
LinkedTransferQueue private end tail;

Public LimitLinkedTransferQueue () {
this (Integer.MAX_VALUE);
}

Public LimitLinkedTransferQueue (final int maxSize) {
this.maxSize = maxSize;
yes (maxSize < 1) throw new IllegalArgumentException(maxSize + " is not a valid. Should be > one ");
queue = new LinkedTransferQueue <> ();
}

//--Add

/ **
* Insert an element in the tail of this queue if it is possible to do it immediately without violating
* capacity restrictions, they become true when done correctly and throw an IllegalStateException exception if there is no space
* available.
* /
@Cancel
public boolean complement (end E e) {
if (this.size> = this.maxSize) returns false;
final boolean result = queue.add (e);
yes (result) {
size ++;
return result
}
launch a new IllegalStateException ("Queue is full");
}

/ **
* Insert an element in the tail of this queue if it is possible to do it immediately without violating
* capacity restrictions, returning true on success and false if there is no space available at present.
* /
@Cancel
public boolean offer (final E e) {
if (size> = maxSize) returns false;
final boolean result = queue.offer (e);
yes (result) {
size ++;
}
return result
}

// - withdraw

/ **
* Specified by {@link AbstractQueue # remove ()]}
* /
@Cancel
public e remove () {
E final element = queue.remove ();
if (element! = null) {
size--;
}
return element
}

/ **
* Specified by {@link LinkedTransferQueue # remove (Object)}.
* /
@Cancel
delete public boolean (final object o) {
final boolean result = queue.remove (o);
yes (result) {
size--;
}
return result
}

/ **
* Specified by {@link LinkedTransferQueue # removeIf (Predicate)}.
* /
@Cancel
Boolean public removeIf (Final predicate filter) {

final boolean result = queue.removeIf (filter);
yes (result) {
size = queue.size ();
}
return result
}

/ **
* Specified by {@link AbstractQueue # element ()]}
* /
@Cancel
element E public () {
return queue.element ();
}

/ **
* Specified by {@link AbstractQueue # peek ()]}
* /
@Cancel
peek E public () {
return queue.peek ();
}

/ **
* Specified by {@link LinkedTransferQueue # poll ()}.
* /
@Cancel
E public survey () {
element E final = queue.poll ();
if (element! = null) {
size--;
}
return element
}

/ **
* Specified by {@link LinkedTransferQueue # poll (long, TimeUnit)}.
* /
@Cancel
The public survey E (final long wait time, unit TimeUnit final) launches InterruptedException {
element E final = queue.poll (timeout, unit);
if (element! = null) {
// the timed survey can consume an element that is not in the queue, produced by tryTransfer ()
size = queue.size (); // so the size should be verified
}
return element
}

/ **
* Specified by {@link LinkedTransferQueue # take ()}.
* /
@Cancel
public E take () launches InterruptedException {
E final element = queue.take ();
// take can consume an element that is not in the queue, produced by tryTransfer ()
size = queue.size (); // so the size should be verified
return element
}

//--bulk

/ **
* If adding all the elements in c would violate the capacity constraints, the method returns
* False and does not add elements. 
* Otherwise specified by {@link AbstractQueue # addAll (Collection)} * / @Cancel public boolean addAll (final collection c) { if (this.size + c.size ()> this.maxSize) returns false; final boolean result = queue.addAll (c); yes (result) { size = queue.size (); } return result } / ** * Specified by {@link LinkedTransferQueue # removeAll (Collection)}. * / @Cancel Boolean public removeAll (Final collection c) { final boolean result = queue.removeAll (c); yes (result) { size = queue.size (); } return result } / ** * Specified by {@link LinkedTransferQueue # retainAll (Collection))}. * / @Cancel public boolean retainAll (final collection c) { final Boolean result = queue.retainAll (c); yes (result) { size = queue.size (); } return result } / ** * Specified by {@link LinkedTransferQueue # drainTo (Collection))}. * / @Cancel Int public drainage (Final collection do){ final int drained = queue.drainTo (c); yes (drained> 0) { size = queue.size (); } drained return; } / ** * Specified by {@link LinkedTransferQueue # drainTo (Collection, int))}. * / @Cancel Int public drainage (Final collection c, final int maxElements) { final int drained = queue.drainTo (c, maxElements); yes (drained> 0) { size = queue.size (); } drained return; } / ** * Specified by {@link LinkedTransferQueue # clear ())}. * / @Cancel public vacuum clear () { queue.clear (); size = 0; } //--to transfer / ** * Specified by {@link LinkedTransferQueue # tryTransfer (Object)}.
* Size changes are handled by the consumption methods {@link #take ()} and * {@link #poll (long, TimeUnit)}. * / @Cancel public boolean tryTransfer (final E e) { return queue.tryTransfer (e); } // - utilities / ** * * / @Cancel public int size () { return size; } / ** * * / @Cancel public int remainingCapacity () { return maxSize - size; } / ** * Specified by {@link BlockingQueue # contains (Object)} * / @Cancel public boolean contains (final object o) { return queue.contains (o); } / ** * Specified by {@link Collection # isEmpty ()} * / @Cancel public boolean isEmpty () { return size == 0; } / ** * Specified by {@link Collection # iterator ()} * / @Cancel public iterator iterator () { return queue.iterator (); } / ** * Specified by {@link Collection # toArray ()} * / @Cancel Public object[] toArray () { return queue.toArray (); } / ** * Specified by {@link Collection # toArray (Object[])} * / @Cancel public T[] toArray (final T[] a) { return queue.toArray (a); } / ** * Specified by {@link Collection # includesAll (Collection)} * / @Cancel public boolean contains all (final collection c) { return queue.containsAll (c); } / ** * Specified by {@link TransferQueue # getWaitingConsumer ()} * / @Cancel public boolean hasWaitingConsumer () { return queue.hasWaitingConsumer (); } / ** * Specified by {@link TransferQueue # getWaitingConsumerCount ()} * / @Cancel public int getWaitingConsumerCount () { return queue.getWaitingConsumerCount (); } // - Not supported (all) / ** * Not supported * / @Cancel Public transfer canceled (end E e) launches InterruptedException { launch new UnsupportedOperationException (); } / ** * Not supported * / @Cancel public Boolean tryTransfer (end E e, long end timeout, end TimeUnit unit) launches InterruptedException { launch new UnsupportedOperationException (); } / ** * Not supported * / @Cancel public Boolean offer (end E e, long end timeout, final TimeUnit unit) launches InterruptedException { launch new UnsupportedOperationException (); } / ** * Not supported * / @Cancel public empty place (end E e) launches InterruptedException { launch new UnsupportedOperationException (); } }

Feedback would be appreciated.