activemq-cpp-3.8.2
AbstractQueue.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef ABSTRACTQUEUE_H_
19 #define ABSTRACTQUEUE_H_
20 
21 #include <decaf/util/Config.h>
26 #include <decaf/lang/Iterable.h>
27 #include <decaf/util/Iterator.h>
28 #include <decaf/util/Queue.h>
29 #include <memory>
30 
31 namespace decaf {
32 namespace util {
33 
46  template< typename E >
47  class AbstractQueue : public decaf::util::Queue<E>,
49  public:
50 
51  AbstractQueue() : Queue<E>() {}
52 
53  virtual ~AbstractQueue() {}
54 
61  virtual bool add(const E& value) {
62 
63  if (this->offer(value )) {
64  return true;
65  }
66 
68  __FILE__, __LINE__, "Unable to add specified element to the Queue." );
69  }
70 
78  virtual bool addAll(const Collection<E>& collection) {
79 
80  if (this == &collection) {
82  __FILE__, __LINE__, "A Queue cannot be added to itself." );
83  }
84 
85  return AbstractCollection<E>::addAll(collection);
86  }
87 
89 
95  virtual E remove() {
96 
97  E result;
98  if (this->poll(result) == true) {
99  return result;
100  }
101 
103  __FILE__, __LINE__, "Unable to remove specified element from the Queue." );
104  }
105 
112  virtual E element() const {
113 
114  E result;
115  if (this->peek( result ) == true) {
116  return result;
117  }
118 
120  __FILE__, __LINE__, "Unable to remove specified element from the Queue." );
121  }
122 
128  virtual void clear() {
129 
130  if (this->isEmpty()) {
131  return;
132  }
133 
134  E result;
135  bool successful = true;
136 
137  do {
138  successful = this->poll(result);
139  } while(successful);
140  }
141  };
142 
143 }}
144 
145 #endif /* ABSTRACTQUEUE_H_ */
virtual E element() const
Gets but not removes the element in the head of the queue.Throws a NoSuchElementException if there is...
Definition: AbstractQueue.h:112
The root interface in the collection hierarchy.
Definition: Collection.h:68
virtual void clear()
Removes all of the elements from this collection (optional operation).The collection will be empty af...
Definition: AbstractQueue.h:128
This class provides a skeletal implementation of the Collection interface, to minimize the effort req...
Definition: AbstractCollection.h:58
virtual bool peek(E &result) const =0
Gets but not removes the element in the head of the queue.
AbstractQueue()
Definition: AbstractQueue.h:51
virtual ~AbstractQueue()
Definition: AbstractQueue.h:53
virtual bool addAll(const Collection< E > &collection)
Adds all of the elements in the specified collection to this collection.The behavior of this operatio...
Definition: AbstractQueue.h:78
A kind of collection provides advanced operations than other basic collections, such as insertion...
Definition: Queue.h:55
virtual bool offer(const E &value)=0
Inserts the specified element into the queue provided that the condition allows such an operation...
virtual bool addAll(const Collection< E > &collection)
Adds all of the elements in the specified collection to this collection.The behavior of this operatio...
Definition: AbstractCollection.h:223
virtual bool poll(E &result)=0
Gets and removes the element in the head of the queue.
Definition: IllegalArgumentException.h:31
Definition: IllegalStateException.h:32
virtual bool isEmpty() const
Returns true if this collection contains no elements.
Definition: AbstractCollection.h:200
Definition: NoSuchElementException.h:31
This class provides skeletal implementations of some Queue operations.
Definition: AbstractQueue.h:47
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: AprPool.h:25
virtual bool add(const E &value)
Returns true if this collection changed as a result of the call.(Returns false if this collection doe...
Definition: AbstractQueue.h:61