activemq-cpp-3.8.2
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 
30 namespace decaf {
31 namespace util {
32 
58  template< typename E >
60  public:
61 
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 
101  try {
102  std::auto_ptr< ListIterator<E> > iter( this->listIterator( index ) );
103  return iter->next();
104  } catch( decaf::util::NoSuchElementException& ex ) {
106  __FILE__, __LINE__, "get called with invalid index." );
107  }
108  }
109 
117  virtual E set( int index, const E& element ) {
118 
119  try {
120  std::auto_ptr< ListIterator<E> > iter( this->listIterator( index ) );
121  E result = iter->next();
122  iter->set( element );
123  return result;
124  } catch( decaf::util::NoSuchElementException& ex ) {
126  __FILE__, __LINE__, "set called with invalid index." );
127  }
128  }
129 
137  virtual void add( int index, const E& element ) {
138 
139  try {
140  std::auto_ptr< ListIterator<E> > iter( this->listIterator( index ) );
141  iter->add( element );
142  } catch( decaf::util::NoSuchElementException& ex ) {
144  __FILE__, __LINE__, "add called with invalid index." );
145  }
146  }
147 
157  virtual bool addAll( int index, const Collection<E>& source ) {
158 
159  std::auto_ptr< ListIterator<E> > iter( this->listIterator( index ) );
160  std::auto_ptr< Iterator<E> > srcIter( source.iterator() );
161  int next = iter->nextIndex();
162  while( srcIter->hasNext() ) {
163  iter->add( srcIter->next() );
164  }
165  return next != iter->nextIndex();
166  }
167 
174  virtual E removeAt( int index ) {
175 
176  try {
177  std::auto_ptr< ListIterator<E> > iter( this->listIterator( index ) );
178  E result = iter->next();
179  iter->remove();
180  return result;
181  } catch( decaf::util::NoSuchElementException& ex ) {
183  __FILE__, __LINE__, "set called with invalid index." );
184  }
185  }
186 
187  };
188 
189 }}
190 
191 #endif /* _DECAF_UTIL_ABSTRACTSEQUENTIALLIST_H_ */
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:157
The root interface in the collection hierarchy.
Definition: Collection.h:68
virtual ListIterator< E > * listIterator(int index DECAF_UNUSED)
Definition: AbstractSequentialList.h:83
virtual ListIterator< E > * listIterator()
Definition: AbstractSequentialList.h:76
An iterator for lists that allows the programmer to traverse the list in either direction, modify the list during iteration, and obtain the iterator's current position in the list.
Definition: ListIterator.h:38
virtual ListIterator< E > * listIterator() const
Definition: AbstractSequentialList.h:79
virtual Iterator< E > * iterator()
Definition: AbstractSequentialList.h:69
virtual Iterator< E > * iterator() const
Definition: AbstractSequentialList.h:72
Defines an object that can be used to iterate over the elements of a collection.
Definition: Iterator.h:34
Definition: IndexOutOfBoundsException.h:31
Definition: UnsupportedOperationException.h:32
virtual E set(int index, const E &element)
Replaces the element at the specified position in this list with the specified element.The index of the element to replace. The element to be stored at the specified position.the element previously at the specified position.if the index given is less than zero or greater than the List size. if this is an unmodifiable collection. if the Collection is a container of pointers and does not allow NULL values. if some property of the element prevents it from being added to this collection if the element cannot be added at this time due to insertion restrictions.
Definition: AbstractSequentialList.h:117
virtual decaf::util::Iterator< E > * iterator()=0
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:137
This class provides a skeletal implementation of the List interface to minimize the effort required t...
Definition: AbstractList.h:65
virtual ListIterator< E > * listIterator(int index DECAF_UNUSED) const
Definition: AbstractSequentialList.h:87
#define DECAF_UNUSED
Definition: Config.h:160
Definition: NoSuchElementException.h:31
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:174
virtual ~AbstractSequentialList()
Definition: AbstractSequentialList.h:67
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: AprPool.h:25