AbstractList Class Reference

#include <coherence/util/AbstractList.hpp>

Inherits AbstractCollection, and List.

Inherited by LinkedList, and SubList.

List of all members.


Detailed Description

This class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface.

Public Types

typedef spec::Handle Handle
 AbstractList Handle definition.
typedef spec::View View
 AbstractList View definition.
typedef spec::Holder Holder
 AbstractList Holder definition.

Public Member Functions

virtual bool equals (Object::View v) const
 Compares the specified object with this list for equality.

Two lists are defined to be equal iff they contain the same elements in the same order. This definition ensures that the equals method works properly across different implementations of the List interface.

Parameters:
vObj the Object to be compared for equality with this list
Returns:
true if the specified Object is equal to this list.

virtual size32_t hashCode () const
 The hash code of a List is defined as follows: size32_t nHash = 1; for (Iterator::Handle hIter = list.iterator(); hIter->hasNext(); ) { Object::View v = hIter->next(); nHash = 31 * nHash + (NULL == v ? 0 : v->hashCode()); } This ensures that l1->equals(l2) implies that l1->hashCode() == l2->hashCode() for any two lists l1 and l2, as required by the general contract of Object::hashCode().

Returns:
the hash code value for this list

virtual bool isImmutable () const
 Return true iff no further changes can be made to the Object, that would effect the outcome of a call to its equals method.

Except for Objects which are naturally immutable (such as String), being immutable generally implies that the Object is only referenced via const pointers or views. Objects which hold references to child Objects, may need to take the immutability of their children into account when determining their own immutability.

This extended check is not performed by the default implementation, but can be integrated into the immutability checks by overiding this method, as well as making use of MemberHandles to reference child Objects.

A typicial derived implementaiton may look as follows:

 bool isImmutable() const
     {
     if (m_fImmutable) // check recorded state
         {
         return true; // already marked as immutable, avoid calculation
         }
     else if (Object::isImmutable()) // ensure shallow immutability
         {
         // ensure deap immutability
         if (m_child1->isImmutable() && m_child2->isImmutable() ...
                                     && m_childN->isImmutable())
             {
             // record and return immutability
             return m_fImmutable = true;
             }
         // some Objects which comprise this Object are still mutable
         }
     return false;
     }
 

The default implementation return true iff the Object is only referenced via const pointers and or views.

Returns:
true iff the Object is immutable


Protected Attributes

size32_t m_nHashCode
 The cached hash of all the array elements.

Member Data Documentation

size32_t m_nHashCode [mutable, protected]

The cached hash of all the array elements.

The hash code is not cached until the List becomes immutable. A value of 0 indicates that the has has not been cached.


The documentation for this class was generated from the following file: Copyright (c) 2000-2008 Oracle. All rights reserved.