I. Overview of the CLASS structure:
Java.lang.Object java.util.abstractcollection<e> java.util.abstractqueue<e>
Type parameter:
E
-The type declaration of the element saved in this collection: Public abstract class
abstractqueue<e> extends Abstractcollection <E> implementsQueue <E>
This class provides a
Queue
backbone implementation of some operations. Implementations in this class apply when a basic implementation
does not allow the inclusion of a null element.
add
,
remove
and
element
methods are based on
offer
,
poll
and methods, respectively,
peek
but they indicate failure by throwing an exception instead of returning false or null .
Extending the Queue implementation of this class must define at least one method that does not allow the insertion of a null element, and that method, Queue.offer(E)
Queue.peek()
Queue.poll()
Collection.size()
and both, and Collection.iterator()
both support Iterator.remove()
methods. It is also common to override other methods. If these requirements are not met, you can instead consider AbstractCollection
creating a subclass.
This class is a member of the Java collections Framework.
second, the construction method
Abstractqueue () The construction method used by the subclass.
Iii. details of the method
1.Add(e e)
true illegalstateexception.
Offer true illegalstateexception.
-
specified by:
-
interface
collection<e>
add
-
specified by:
-
interface
queue<e>
Add
-
Overwrite:
-
class
abstractcollection<e>
Add
-
parameter:
-
e
-element to add
-
return:
- true (according to
Collection.add (E)
)
-
thrown:
-
illegalstateexception
-If the element cannot be added at this time because of capacity constraints
-
classcastexception
-As The class of the specified element does not allow the element to be added to this queue
-
nullpointerexception
-If the specified element is null and this queue does not allow null elements
-
illegalargumentexception
-If some properties of this element do not allow the element to be added to this queue
2,
public E
remove
()
-
gets and removes the header for this queue. This method differs from
poll
in that it throws an exception when this queue is empty.
This implementation returns the result of poll unless the queue is empty.
-
-
specified by:
-
Interface
queue< ; E>
Remove
-
-
return:
-
header for this queue
-
thrown:
-
nosuchelementexcep tion
-If this queue is empty
3, public e
element () gets the header of this queue without removing it. This method differs from
Peek
in that it throws an exception when this queue is empty. This implementation returns the result of peek unless the queue is empty.
-
specified by:
-
interface
Queue<e>
in
element
-
return:
-
header for this queue
-
thrown:
-
nosuchelementexception
-If this queue is empty
4,
public void
Clear
poll until it returns null .
Designated by:
Collection<E>
in the interface.
clear
Covered:
AbstractCollection<E>
in the class
clear
5,addall(CollectionE> C)
illegalargumentexception. In addition, if the specified collection is modified while this operation is in progress, the behavior of this operation is indeterminate.
null Element), if a run-time exception is encountered, it may cause only certain elements to be added successfully when the associated exception is thrown.
-
Designated by:
-
Collection<E>
in the interface.
addAll
-
Covered:
-
AbstractCollection<E>
in the
addAll
class
-
Parameters:
-
c
-The collection that contains the elements to add to this queue
-
Return:
-
Returns true if this queue has changed because of a call
-
Thrown:
-
ClassCastException
-If the class that specifies the collection element does not allow the element to be added to this queue
-
NullPointerException
-If the specified collection contains a null element and this queue does not allow a null element, or the specified co Llection is null
-
IllegalArgumentException
-If certain properties of the specified collection element do not allow the element to be added to this queue, or collection is the queue
-
IllegalStateException
-As All elements cannot be added at this time due to insertion limit
Abstractqueue in Java