org.jacorb.notification.util
Class WildcardMap

java.lang.Object
  extended byorg.jacorb.notification.util.WildcardMap
Direct Known Subclasses:
CachingWildcardMap

public class WildcardMap
extends java.lang.Object

An Object that maps String Keys to Values. A WildcardMap cannot contain duplicate keys. Each Key has exactly one Entry associated. A Key can contain the Wildcard Character '*' which matches zero or more characters of the key. The WildcardMap supports two semantics of accessing the entries. The first way is to ignore the special meaning of the Wildcard character and to just return the entries as they were inserted.
This way you could put some entries in a WildcardMap and fetch them again using the Operation getNoExpansion():

 WildcardMap wc = new WildcardMap();
 wc.put("abc", new Integer(1));
 wc.put("a*", new Integer(2));
 wc.getNoExpansion("abc") => 1
 wc.getNoExpansion("a*") => 2
 wc.getNoExpansion("xyz") => null
 
This behaviour is similiar to a Map.
The other way using the WildcardMap is to call the Operation getWithExpansion(). This Operations matches the requested Key to all contained Keys. If the Key of an Entry contains the Wildcard Character '*' it is matched as expected by the semantic of '*'. The Operations returns an array of all matching entries:
 wc.getWithExpansion("abc") => [1,2]
 wc.getWithExpansion("a") => [2]
 wc.getWithExpansion("abcd") => [2]
 wc.getWithExpansion("xyz") => []
 

Version:
$Id: WildcardMap.java,v 1.12 2004/05/06 12:40:00 nicolas Exp $
Author:
Alphonse Bendt

Constructor Summary
WildcardMap()
           
WildcardMap(int topLevelSize)
           
 
Method Summary
 void clear()
          clear this map
 java.lang.Object getNoExpansion(java.lang.Object key)
          Returns the value to which this map maps the specified key.
 java.lang.Object[] getWithExpansion(java.lang.Object key)
          Returns the value to which this map maps the specified key.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          The operation put associates the specified value with the specified key in this map.
 java.lang.Object remove(java.lang.Object key)
          remove the specified key from this Map.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WildcardMap

public WildcardMap(int topLevelSize)

WildcardMap

public WildcardMap()
Method Detail

clear

public void clear()
clear this map


remove

public java.lang.Object remove(java.lang.Object key)
remove the specified key from this Map.


put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
The operation put associates the specified value with the specified key in this map. The String representation of the Key toString() is used. If the map previously contained a mapping for this key, the old value is replaced by the specified value.

Parameters:
key - key with which String representation the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with specified key, or null if there was no mapping for key.

getNoExpansion

public java.lang.Object getNoExpansion(java.lang.Object key)
Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key.

Parameters:
key - key whose associated value is to be returned
Returns:
the value to which this map maps the specified key, or null if the map contains no mapping for this key.

getWithExpansion

public java.lang.Object[] getWithExpansion(java.lang.Object key)
Returns the value to which this map maps the specified key. Additionaly return all Values which keys contain a Wildcard and match the requested key. Returns null if the map contains no mapping for this key.

Parameters:
key - key whose associated value is to be returned
Returns:
an Array of all Matching entries or null if no matching entry could be found.

toString

public java.lang.String toString()
Returns:
a String representation of this WildcardMap