com.notuvy.util
Class Translation<T>

java.lang.Object
  extended by com.notuvy.util.Translation<T>
Direct Known Subclasses:
Translation.Rewrite

public class Translation<T>
extends Object

A simple utility that adds convenience to lookups beyond what Map defines. There are two problems with Map get() that this utility solves. First, with Map get() is that you need to check if it returned null, whereas this will return a defined fallback value . Second, with Map get(), if you want different forms of the same key to represent the same value (e.g. case-insensitive, whitespace-insensitive), you need to explicitly enumerate ALL possible key values. For trimmed strings, this is not possible because the possibilities are infinite. Instead, this class allows the definition of (possibly multiple) transformations that are performed on the key before matching. It also defines add() as a cascading method, so a fully defined translation table can be created in a single java statement. User: murali Date: Nov 27, 2007 Time: 1:00:04 PM


Nested Class Summary
static interface Translation.KeyTranformation
           
static class Translation.Rewrite
          This customizes the lookup behavior.
 
Field Summary
static Translation.KeyTranformation ALPHANUMERIC
           
static Translation.KeyTranformation CASE_INSENSITIVE
           
static Translation.KeyTranformation TRIMMED
           
 
Constructor Summary
Translation()
           
 
Method Summary
 Translation<T> addTransform(Translation.KeyTranformation pTransform)
          All transformations should be added before any definitions are added.
 void clear()
           
 Translation<T> define(String pKey, T pVal)
           
 boolean defines(String pKey)
           
 T getFallback()
           
 Map<String,T> getUnderlying()
           
 boolean isEmpty()
           
 T lookup(String pKey)
           
 Translation<T> setFallback(T pFallback)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CASE_INSENSITIVE

public static final Translation.KeyTranformation CASE_INSENSITIVE

TRIMMED

public static final Translation.KeyTranformation TRIMMED

ALPHANUMERIC

public static final Translation.KeyTranformation ALPHANUMERIC
Constructor Detail

Translation

public Translation()
Method Detail

getUnderlying

public Map<String,T> getUnderlying()

getFallback

public T getFallback()

setFallback

public Translation<T> setFallback(T pFallback)

addTransform

public Translation<T> addTransform(Translation.KeyTranformation pTransform)
All transformations should be added before any definitions are added. When this method is called, it is NOT retroactively applied to any existing definitions.

Parameters:
pTransform - A new key transform to add.
Returns:
this instance.

define

public Translation<T> define(String pKey,
                             T pVal)

lookup

public T lookup(String pKey)

defines

public boolean defines(String pKey)

isEmpty

public boolean isEmpty()

clear

public void clear()


Copyright © 2013. All Rights Reserved.