18 #ifndef _DECAF_UTIL_STLLIST_H_ 19 #define _DECAF_UTIL_STLLIST_H_ 51 typename std::list<E>::iterator current;
52 typename std::list<E>::iterator prev;
53 typename std::list<E>* list;
57 StlListIterator(
const StlListIterator& );
58 StlListIterator
operator= (
const StlListIterator& );
62 StlListIterator(
typename std::list<E>* list,
int index ) :
63 current( list->begin() ), prev( list->end() ), list( list ) {
65 if( index < (
int)list->size() ) {
66 std::advance( this->current, index );
68 this->current = list->end();
72 virtual ~StlListIterator() {}
75 if( this->current == list->end() ) {
78 "List::Iterator::next - No more elements to return" );
81 this->prev = this->current;
82 return *( this->current++ );
85 virtual bool hasNext()
const {
86 return ( this->current != list->end() );
89 virtual void remove() {
90 if( this->prev == list->end() ) {
93 "List::Iterator::remove - Invalid State to call remove" );
96 this->list->erase( this->prev );
97 this->prev = this->list->end();
100 virtual void add(
const E& e ) {
101 this->list->insert( this->current, e );
104 virtual void set(
const E& e ) {
106 if( this->current == list->end() ) {
107 this->list->insert( this->current, e );
109 *( this->current ) = e;
113 virtual bool hasPrevious()
const {
114 return ( this->current != this->list->begin() );
117 virtual E previous() {
118 if( this->current == this->list->begin() ) {
121 "List::ListIterator::previous - No Previous element." );
124 typename std::list<E>::const_iterator iter = this->current;
128 virtual int nextIndex()
const {
129 if( this->current == this->list->end() ) {
130 return (
int)this->list->size();
133 return (
int)std::distance( this->list->begin(), this->current );
136 virtual int previousIndex()
const {
137 if( this->current == this->list->begin() ) {
141 return (
int)std::distance( this->list->begin(), this->current ) - 1;
149 typename std::list<E>::const_iterator current;
150 typename std::list<E>::const_iterator prev;
151 const typename std::list<E>* list;
155 ConstStlListIterator(
const ConstStlListIterator& );
156 ConstStlListIterator
operator= (
const ConstStlListIterator& );
160 ConstStlListIterator(
const typename std::list<E>* list,
int index ) :
161 ListIterator<E>(), current( list->begin() ), prev( list->end() ), list( list ) {
163 if( index < (
int)list->size() ) {
164 std::advance( this->current, index );
166 this->current = list->end();
170 virtual ~ConstStlListIterator() {}
173 if( this->current == list->end() ) {
176 "List::Iterator::next - No more elements to return" );
179 this->prev = this->current;
180 return *( this->current++ );
183 virtual bool hasNext()
const {
184 return ( this->current != list->end() );
187 virtual void remove() {
191 "List::ListIterator::remove - Const Iterator." );
198 "List::ListIterator::add - Const Iterator." );
205 "List::ListIterator::set - Const Iterator." );
208 virtual bool hasPrevious()
const {
209 return ( this->current != this->list->begin() );
212 virtual E previous() {
213 if( this->current == this->list->begin() ) {
216 "List::ListIterator::previous - No Previous element." );
219 typename std::list<E>::const_iterator iter = this->current;
223 virtual int nextIndex()
const {
224 if( this->current == this->list->end() ) {
225 return (
int)this->list->size();
228 return (
int)std::distance( this->list->begin(), this->current );
231 virtual int previousIndex()
const {
232 if( this->current == this->list->begin() ) {
236 return (
int)std::distance( this->list->begin(), this->current ) - 1;
271 if( listptr ==
NULL ) {
275 return this->values == listptr->values;
284 if( listptr ==
NULL ) {
289 this->values.clear();
290 this->values = listptr->values;
297 return new StlListIterator( &values, 0 );
300 return new ConstStlListIterator( &values, 0 );
307 return new StlListIterator( &values, 0 );
310 return new ConstStlListIterator( &values, 0 );
318 if( index < 0 || index > this->
size() ) {
321 "List::listIterator - Index greater than size() or negative" );
324 return new StlListIterator( &values, index );
328 if( index < 0 || index > this->
size() ) {
331 "List::listIterator - Index greater than size() or negative" );
334 return new ConstStlListIterator( &values, index );
348 return values.empty();
355 return (
int)values.size();
361 virtual E
get(
int index )
const {
363 if( index < 0 || index >= this->
size() ) {
366 "List::get - Index greater than size() or negative" );
370 typename std::list<E>::const_iterator iter = this->values.begin();
371 std::advance( iter, index );
378 virtual E
set(
int index,
const E& element ) {
380 if( index < 0 || index >= this->
size() ) {
383 "List::get - Index greater than size() or negative" );
388 typename std::list<E>::iterator iter = this->values.begin();
389 std::advance( iter, index );
396 virtual void add(
int index,
const E& element ) {
398 if( index < 0 || index > this->
size() ) {
401 "List::add - Index greater than size()" );
405 typename std::list<E>::iterator iter = this->values.begin();
406 std::advance( iter, index );
407 this->values.insert( iter, element );
410 virtual bool add(
const E& value ) {
411 values.insert( values.end(), value );
421 std::vector<E> array = collection.
toArray();
422 typename std::vector<E>::const_iterator vecIter = array.begin();
424 std::auto_ptr< ListIterator<E> > iter( this->
listIterator( (
int)this->values.size() ) );
426 while( vecIter != array.end() ) {
427 iter->add( *( vecIter++) );
438 if( index < 0 || index > this->
size() ) {
441 "List::addAll - Index greater than size()" );
448 std::vector<E> array = collection.
toArray();
449 typename std::vector<E>::const_iterator vecIter = array.begin();
451 std::auto_ptr< ListIterator<E> > iter( this->
listIterator( index ) );
453 while( vecIter != array.end() ) {
454 iter->add( *( vecIter++) );
463 virtual bool remove(
const E& value ) {
465 int origSize = this->
size();
466 this->values.remove( value );
467 return origSize != this->
size();
475 if( index < 0 || index >= this->
size() ) {
478 "List::removeAt - Index greater than size() or negative" );
482 typename std::list<E>::iterator iter = this->values.begin();
483 std::advance( iter, index );
485 this->values.erase( iter );
492 typename std::list<E>::const_iterator iter;
493 iter = std::find( values.begin(), values.end(), value );
495 if( iter == values.end() ) {
499 return (
int)std::distance( values.begin(), iter );
504 typename std::list<E>::const_reverse_iterator iter;
505 iter = std::find( values.rbegin(), values.rend(), value );
507 if( iter == values.rend() ) {
512 return (
int)( this->
size() - std::distance( values.rbegin(), iter ) - 1 );
516 typename std::list<E>::const_iterator iter;
517 iter = std::find( values.begin(), values.end(), value );
518 return iter != values.end();
StlList()
Default constructor - does nothing.
Definition: StlList.h:245
virtual bool contains(const E &value) const
Returns true if this collection contains the specified element.More formally, returns true if and onl...
Definition: StlList.h:515
The root interface in the collection hierarchy.
Definition: Collection.h:68
List class that wraps the STL list object to provide a simpler interface and additional methods not p...
Definition: StlList.h:41
virtual ListIterator< E > * listIterator(int index) const
Definition: StlList.h:326
#define NULL
Definition: Config.h:33
virtual bool isEmpty() const =0
virtual void clear()
Removes all of the elements from this collection (optional operation).The collection will be empty af...
Definition: StlList.h:340
virtual int lastIndexOf(const E &value) const
Returns the index of the last occurrence of the specified element in this list, or -1 if this list do...
Definition: StlList.h:502
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 bool addAll(const Collection< E > &collection)
Adds all of the elements in the specified collection to this collection.The behavior of this operatio...
Definition: StlList.h:415
virtual void copy(const Collection< E > &collection)
Renders this Collection as a Copy of the given Collection.The default implementation iterates over th...
Definition: StlList.h:281
virtual bool equals(const Collection< E > &collection) const
Answers true if this Collection and the one given are the same size and if each element contained in ...
Definition: StlList.h:268
virtual Iterator< E > * iterator()
an iterator over a set of elements of type T.
Definition: StlList.h:296
Defines an object that can be used to iterate over the elements of a collection.
Definition: Iterator.h:34
Definition: IndexOutOfBoundsException.h:31
virtual bool equals(const Collection< E > &collection) const
Answers true if this Collection and the one given are the same size and if each element contained in ...
Definition: AbstractCollection.h:158
Definition: UnsupportedOperationException.h:32
virtual int indexOf(const E &value) const
Returns the index of the first occurrence of the specified element in this list, or -1 if this list d...
Definition: StlList.h:490
virtual ListIterator< E > * listIterator(int index)
index of first element to be returned from the list iterator (by a call to the next method)...
Definition: StlList.h:316
AbstractCollection< E > & operator=(const AbstractCollection< E > &collection)
Assignment Operator, copy element from the source collection to this collection after clearing any el...
Definition: AbstractCollection.h:76
virtual ListIterator< E > * listIterator() const
Definition: StlList.h:309
virtual void add(int index, const E &element)
Inserts the specified element at the specified position in this list.
Definition: StlList.h:396
Definition: IllegalStateException.h:32
This class provides a skeletal implementation of the List interface to minimize the effort required t...
Definition: AbstractList.h:65
virtual E removeAt(int index)
Removes the element at the specified position in this list.Shifts any subsequent elements to the left...
Definition: StlList.h:473
StlList(const StlList &source)
Copy constructor - copies the content of the given set into this one.
Definition: StlList.h:252
virtual bool add(const E &value)
Returns true if this collection changed as a result of the call.
Definition: StlList.h:410
#define DECAF_UNUSED
Definition: Config.h:160
Definition: NoSuchElementException.h:31
virtual ListIterator< E > * listIterator()
a list iterator over the elements in this list (in proper sequence).
Definition: StlList.h:306
virtual void copy(const Collection< E > &collection)
Renders this Collection as a Copy of the given Collection.
Definition: AbstractCollection.h:184
virtual bool addAll(int index, const Collection< E > &collection)
Inserts all of the elements in the specified collection into this list at the specified position (opt...
Definition: StlList.h:436
virtual bool isEmpty() const
Returns true if this collection contains no elements.This implementation returns size() == 0...
Definition: StlList.h:347
virtual Iterator< E > * iterator() const
Definition: StlList.h:299
virtual int size() const
Returns the number of elements in this collection.If this collection contains more than Integer::MAX_...
Definition: StlList.h:354
virtual std::vector< E > toArray() const =0
Returns an array containing all of the elements in this collection.
StlList(const Collection< E > &source)
Copy constructor - copies the content of the given set into this one.
Definition: StlList.h:261
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: AprPool.h:25