Skip navigation links

Oracle® Coherence Java API Reference
v3.5.1

E15583-01


com.tangosol.util
Class SimpleMapIndex

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.util.SimpleMapIndex

All Implemented Interfaces:
MapIndex, MapListener, java.util.EventListener

public class SimpleMapIndex
extends Base
implements MapIndex, MapListener

SimpleMapIndex is a MapIndex implemenation used to correlate property values extracted from resource map entries with corresponding keys using what is commonly known as an Inverted Index algorithm..

Since:
Coherence 3.5
Author:
tb 2009.03.19

Field Summary
protected  java.util.Comparator m_comparator
          Comparator used to sort the index.
protected  ValueExtractor m_extractor
          ValueExtractor object that this MapIndex uses to extract an indexable property value from a [converted] value stored in the resource map.
protected  boolean m_fOrdered
          Specifies whether or not this MapIndex orders the contents of the indexed information.
protected  boolean m_fSplitCollection
          If a value extracted by the ValueExtractor is a Collection, this property specifies whether or not it should be treated as a Collection of contained attributes or indexed as a single composite attribute.
protected  SegmentedHashMap m_mapForward
          Map that contains the index values (forward index).
protected  java.util.Map m_mapInverse
          Map that contains the index contents (inverse index).

 

Constructor Summary
SimpleMapIndex(ValueExtractor extractor, boolean fOrdered, java.util.Comparator comparator)
          Construct an index for the given map.

 

Method Summary
protected  java.lang.Object addInverseMapping(java.util.Map mapIndex, java.lang.Object oIxValue, java.lang.Object oKey)
          Add a new mapping from the given indexed value to the given key in the supplied index.
 void delete(java.util.Map.Entry entry)
          Update this index in response to a remove operation on a cache.
 void entryDeleted(MapEvent evt)
          Invoked when a map entry has been removed.
 void entryInserted(MapEvent evt)
          Invoked when a map entry has been inserted.
 void entryUpdated(MapEvent evt)
          Invoked when a map entry has been updated.
 boolean equals(java.lang.Object o)
          Compares the specified object with this index for equality.
 java.lang.Object get(java.lang.Object oKey)
          Using the index information if possible, get the value associated with the specified key.
 java.util.Comparator getComparator()
          Get the Comparator used to sort the index.
 java.util.Map getIndexContents()
          Get the Map that contains the index contents.
 ValueExtractor getValueExtractor()
          Obtain the ValueExtractor object that the MapIndex uses to extract an indexable Object from a value stored in the indexed Map.
 int hashCode()
          Returns the hash code value for this MapIndex.
 void insert(java.util.Map.Entry entry)
          Update this index in response to a insert operation on a cache.
 boolean isOrdered()
          Determine if the MapIndex orders the contents of the indexed information.
protected  void removeInverseMapping(java.util.Map mapIndex, java.lang.Object oIxValue, java.lang.Object oKey)
          Remove the mapping from the given indexed value to the given key from the supplied index.
 java.lang.String toString()
          Returns a string representation of this SimpleMapIndex.
 void update(java.util.Map.Entry entry)
          Update this index in response to an update operation on a cache.

 

Field Detail

m_extractor

protected ValueExtractor m_extractor
ValueExtractor object that this MapIndex uses to extract an indexable property value from a [converted] value stored in the resource map.

m_comparator

protected java.util.Comparator m_comparator
Comparator used to sort the index. Used iff the Ordered flag is true. Null implies a natural order.

m_fOrdered

protected boolean m_fOrdered
Specifies whether or not this MapIndex orders the contents of the indexed information.

m_mapForward

protected SegmentedHashMap m_mapForward
Map that contains the index values (forward index). The keys of the Map are the keys to the ResourceMap and the values are the extracted values. This map is used by the IndexAwareComparators to avoid a conversion and value extraction steps. <p/> Note: We intentionally narrow the map type to have access to the getEntry() method.

m_mapInverse

protected java.util.Map m_mapInverse
Map that contains the index contents (inverse index). The keys of the Map are the return values from the ValueExtractor operating against the entries of the resource map, and for each key, the corresponding value stored in the Map is a Set of keys to the resource map.

m_fSplitCollection

protected boolean m_fSplitCollection
If a value extracted by the ValueExtractor is a Collection, this property specifies whether or not it should be treated as a Collection of contained attributes or indexed as a single composite attribute.

Constructor Detail

SimpleMapIndex

public SimpleMapIndex(ValueExtractor extractor,
                      boolean fOrdered,
                      java.util.Comparator comparator)
Construct an index for the given map.
Parameters:
extractor - the ValueExtractor that is used to extract an indexed value from a resource map entry
fOrdered - true iff the contents of the indexed information should be ordered; false otherwise
comparator - the Comparator object which imposes an ordering on entries in the index map; or null if the entries' values natural ordering should be used

Method Detail

getValueExtractor

public ValueExtractor getValueExtractor()
Obtain the ValueExtractor object that the MapIndex uses to extract an indexable Object from a value stored in the indexed Map. This property is never null.
Specified by:
getValueExtractor in interface MapIndex
Returns:
a ValueExtractor object, never null

isOrdered

public boolean isOrdered()
Determine if the MapIndex orders the contents of the indexed information. To determine in which way the contents are ordered, get the Comparator from the index contents SortedMap object.
Specified by:
isOrdered in interface MapIndex
Returns:
true if the index contents are ordered, false otherwise

getComparator

public java.util.Comparator getComparator()
Get the Comparator used to sort the index.
Specified by:
getComparator in interface MapIndex
Returns:
the comparator

getIndexContents

public java.util.Map getIndexContents()
Get the Map that contains the index contents.

The keys of the Map are the return values from the ValueExtractor operating against the indexed Map's values, and for each key, the corresponding value stored in the Map is a Set of keys to the indexed Map.

If the MapIndex is known to be ordered, then the returned Map object will be an instance of SortedMap. The SortedMap may or may not have a Comparator object associated with it; see SortedMap.comparator().

A client should assume that the returned Map object is read-only and must not attempt to modify it.

Specified by:
getIndexContents in interface MapIndex
Returns:
a Map (or a SortedMap) of the index contents

get

public java.lang.Object get(java.lang.Object oKey)
Using the index information if possible, get the value associated with the specified key. This is expected to be more efficient than using the ValueExtractor against an object containing the value, because the index should already have the necessary information at hand.
Specified by:
get in interface MapIndex
Parameters:
oKey - the key that specifies the object to extract the value from
Returns:
the value that would be extracted by this MapIndex's ValueExtractor from the object specified by the passed key

insert

public void insert(java.util.Map.Entry entry)
Update this index in response to a insert operation on a cache.
Specified by:
insert in interface MapIndex
Parameters:
entry - the entry representing the object being inserted

update

public void update(java.util.Map.Entry entry)
Update this index in response to an update operation on a cache.
Specified by:
update in interface MapIndex
Parameters:
entry - the entry representing the object being updated

delete

public void delete(java.util.Map.Entry entry)
Update this index in response to a remove operation on a cache.
Specified by:
delete in interface MapIndex
Parameters:
entry - the entry representing the object being removed

entryInserted

public void entryInserted(MapEvent evt)
Invoked when a map entry has been inserted.
Specified by:
entryInserted in interface MapListener
Parameters:
evt - the MapEvent carrying the insert information

entryUpdated

public void entryUpdated(MapEvent evt)
Invoked when a map entry has been updated.
Specified by:
entryUpdated in interface MapListener
Parameters:
evt - the MapEvent carrying the update information

entryDeleted

public void entryDeleted(MapEvent evt)
Invoked when a map entry has been removed.
Specified by:
entryDeleted in interface MapListener
Parameters:
evt - the MapEvent carrying the delete information

addInverseMapping

protected java.lang.Object addInverseMapping(java.util.Map mapIndex,
                                             java.lang.Object oIxValue,
                                             java.lang.Object oKey)
Add a new mapping from the given indexed value to the given key in the supplied index.
Parameters:
mapIndex - the index to which to add the mapping
oIxValue - the indexed value (serves as a key in the inverse index)
oKey - the key to insert into the inverse index
Returns:
an already existing reference that is "equal" to the specified value (if available)

removeInverseMapping

protected void removeInverseMapping(java.util.Map mapIndex,
                                    java.lang.Object oIxValue,
                                    java.lang.Object oKey)
Remove the mapping from the given indexed value to the given key from the supplied index.
Parameters:
mapIndex - the index from which to remove the mapping
oIxValue - the indexed value
oKey - the key

toString

public java.lang.String toString()
Returns a string representation of this SimpleMapIndex. The string representation consists of the index's extrtactor, the ordered value, and the contents of the index (the inverse index).
Returns:
a String representation of this SimpleMapIndex

equals

public boolean equals(java.lang.Object o)
Compares the specified object with this index for equality. Returns true if the given object is also a SimpleMapIndex and the two represent the same index.
Parameters:
o - object to be compared for equality with this MapIndex
Returns:
true if the specified object is equal to this index

hashCode

public int hashCode()
Returns the hash code value for this MapIndex.
Returns:
the hash code value for this MapIndex

Skip navigation links

Oracle® Coherence Java API Reference
v3.5.1

E15583-01


Copyright © 2000, 2009, Oracle. All rights reserved.