nyla.solutions.global.patterns.creational.builder.mapped.ReLookupTextMapFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nyla.solutions.global Show documentation
Show all versions of nyla.solutions.global Show documentation
Nyla Solutions Global Java API provides support for basic application
utilities (application configuration, data encryption, debugger and text
processing).
The newest version!
package nyla.solutions.global.patterns.creational.builder.mapped;
import java.util.Map;
import java.util.TreeMap;
import nyla.solutions.global.exception.RequiredException;
import nyla.solutions.global.exception.SystemException;
import nyla.solutions.global.util.Text;
/**
* Implements a MapFactory by id.
*
* The LookupTable is a map of maps where the key is a regular expression.
* @author Gregory Green
*
*/
public class ReLookupTextMapFactory implements MapFactoryById
{
/**
*
* @param input the value to check against a regular expression
* @return Map of Textable objects
*/
public Map createMap()
{
if(Text.isNull(this.id))
throw new RequiredException("ReLookupTextMap.id");
if (this.lookupTable == null || lookupTable.isEmpty())
throw new RequiredException(
"this.lookupTable in ReLookupTextMapById.lookupTextMap");
String re = null;
for (Map.Entry> entry : lookupTable.entrySet())
{
//process next source value
re = entry.getKey();
//the key contains a RE, test if it matches the current source value
if(Text.matches(id,re))//sourceValue.matches(re)
{
return entry.getValue();
}//end for re iteration
}//end lookup re
throw new SystemException("No map found for \""+id+" in regExp keys "+this.lookupTable.keySet());
}// --------------------------------------------
/**
* @return the lookupTable
*/
public Map> getLookupTable()
{
return lookupTable;
}
/**
* The key of the lookup table is a regular expression
* @param lookupTable the lookupTable to set
*/
public void setLookupTable(Map> lookupTable)
{
this.lookupTable = new TreeMap> (lookupTable);
}// --------------------------------------------
/**
* @return the id
*/
public String getId()
{
return id;
}// --------------------------------------------
/**
* @param id the id to set
*/
public void setId(String id)
{
this.id = id;
}
private TreeMap> lookupTable = null;
private String id = null;
}