activemq-cpp-3.9.5
AbstractSequentialList.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 _DECAF_UTIL_ABSTRACTSEQUENTIALLIST_H_
19#define _DECAF_UTIL_ABSTRACTSEQUENTIALLIST_H_
20
21#include <decaf/util/Config.h>
25#include <decaf/lang/Iterable.h>
26#include <decaf/util/Iterator.h>
28#include <memory>
29
30namespace decaf {
31namespace util {
32
58 template< typename E >
60 public:
61
62 using AbstractList<E>::add;
63 using AbstractList<E>::addAll;
64
65 public:
66
68
69 virtual Iterator<E>* iterator() {
70 return this->listIterator( 0 );
71 }
72 virtual Iterator<E>* iterator() const {
73 return this->listIterator( 0 );
74 }
75
77 return this->listIterator( 0 );
78 }
79 virtual ListIterator<E>* listIterator() const {
80 return this->listIterator( 0 );
81 }
82
83 virtual ListIterator<E>* listIterator(int index DECAF_UNUSED) {
85 __FILE__, __LINE__, "Abstract sequential list does not implement the listIterator.");
86 }
87 virtual ListIterator<E>* listIterator(int index DECAF_UNUSED) const {
89 __FILE__, __LINE__, "Abstract sequential list does not implement the listIterator.");
90 }
91
99 virtual E get(int index) const {
100 try {
101 std::auto_ptr<ListIterator<E> > iter(this->listIterator(index));
102 return iter->next();
105 __FILE__, __LINE__, "get called with invalid index.");
106 }
107 }
108
116 virtual E set(int index, const E& element) {
117 try {
118 std::auto_ptr<ListIterator<E> > iter(this->listIterator(index));
119 E result = iter->next();
120 iter->set(element);
121 return result;
124 __FILE__, __LINE__, "set called with invalid index.");
125 }
126 }
127
135 virtual void add(int index, const E& element) {
136 try {
137 std::auto_ptr<ListIterator<E> > iter(this->listIterator(index));
138 iter->add(element);
141 __FILE__, __LINE__, "add called with invalid index.");
142 }
143 }
144
154 virtual bool addAll(int index, const Collection<E>& source) {
155 std::auto_ptr<ListIterator<E> > iter(this->listIterator(index));
156 std::auto_ptr<Iterator<E> > srcIter(source.iterator());
157 int next = iter->nextIndex();
158 while (srcIter->hasNext()) {
159 iter->add(srcIter->next());
160 }
161 return next != iter->nextIndex();
162 }
163
170 virtual E removeAt(int index) {
171 try {
172 std::auto_ptr<ListIterator<E> > iter(this->listIterator(index));
173 E result = iter->next();
174 iter->remove();
175 return result;
178 __FILE__, __LINE__, "set called with invalid index.");
179 }
180 }
181
182 };
183
184}}
185
186#endif /* _DECAF_UTIL_ABSTRACTSEQUENTIALLIST_H_ */
virtual decaf::util::Iterator< E > * iterator()=0
Definition IndexOutOfBoundsException.h:31
Definition UnsupportedOperationException.h:32
This class provides a skeletal implementation of the List interface to minimize the effort required t...
Definition AbstractList.h:66
AbstractList()
Definition AbstractList.h:341
This class provides a skeletal implementation of the List interface to minimize the effort required t...
Definition AbstractSequentialList.h:59
virtual E removeAt(int index)
Removes the element at the specified position in this list.Shifts any subsequent elements to the left...
Definition AbstractSequentialList.h:170
virtual ListIterator< E > * listIterator(int index DECAF_UNUSED)
Definition AbstractSequentialList.h:83
virtual E get(int index) const
Gets the element contained at position passed.value at index specified.
Definition AbstractSequentialList.h:99
virtual ListIterator< E > * listIterator()
Definition AbstractSequentialList.h:76
virtual bool addAll(int index, const Collection< E > &source)
Inserts all of the elements in the specified collection into this list at the specified position (opt...
Definition AbstractSequentialList.h:154
virtual ListIterator< E > * listIterator() const
Definition AbstractSequentialList.h:79
virtual Iterator< E > * iterator()
Definition AbstractSequentialList.h:69
virtual ~AbstractSequentialList()
Definition AbstractSequentialList.h:67
virtual ListIterator< E > * listIterator(int index DECAF_UNUSED) const
Definition AbstractSequentialList.h:87
virtual void add(int index, const E &element)
Inserts the specified element at the specified position in this list.Shifts the element currently at ...
Definition AbstractSequentialList.h:135
virtual Iterator< E > * iterator() const
Definition AbstractSequentialList.h:72
virtual E set(int index, const E &element)
Replaces the element at the specified position in this list with the specified element....
Definition AbstractSequentialList.h:116
The root interface in the collection hierarchy.
Definition Collection.h:69
Defines an object that can be used to iterate over the elements of a collection.
Definition Iterator.h:34
An iterator for lists that allows the programmer to traverse the list in either direction,...
Definition ListIterator.h:38
Definition NoSuchElementException.h:31
Definition AbstractCollection.h:33
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition AprPool.h:25