Top Description Inners Fields Constructors Methods
org.apache.commons.text

public abstract Class StrLookup<V>

extends Object
implements StringLookup
Class Inheritance
All Implemented Interfaces
org.apache.commons.text.lookup.StringLookup, java.util.function.UnaryOperator, java.util.function.Function
Known Direct Subclasses
org.apache.commons.text.StrLookup.MapStrLookup, org.apache.commons.text.StrLookup.ResourceBundleLookup, org.apache.commons.text.StrLookup.SystemPropertiesStrLookup
Annotations
@Deprecated
Type Parameters
<V>
the type of the values supported by the lookup
Imports
java.util.Collections, .Map, .Objects, .ResourceBundle, org.apache.commons.text.lookup.StringLookup, .StringLookupFactory

Deprecated

Deprecated as of 1.3, use StringLookupFactory instead. This class will be removed in 2.0.

Lookup a String key to a String value.

This class represents the simplest form of a string to string map. It has a benefit over a map in that it can create the result on demand based on the key.

This class comes complete with various factory methods. If these do not suffice, you can subclass and implement your own matcher.

For example, it would be possible to implement a lookup that used the key as a primary key, and looked up the value on demand from the database

Since
1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
StrLookup.MapStrLookup<
the type of the values supported by the lookup
V
>

References Deprecated StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.
Lookup implementation that uses a Map.
private static class
StrLookup.ResourceBundleLookup

References Deprecated StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.
Lookup implementation based on a ResourceBundle.
private static class
StrLookup.SystemPropertiesStrLookup

References Deprecated StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.
Lookup implementation based on system properties.

Field Summary

Modifier and TypeField and Description
private static final StrLookup<String>
NONE_LOOKUP

References Deprecated StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.
Lookup that always returns null.
private static final StrLookup<String>
SYSTEM_PROPERTIES_LOOKUP

References Deprecated StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.
Lookup based on system properties.

Constructor Summary

AccessConstructor and Description
protected
StrLookup()

Constructs a new instance for subclasses.

Method Summary

Modifier and TypeMethod and Description
public static <
the type of the values supported by the lookup.
V
>
StrLookup<V>

Returns:

a lookup using the map, not null.
mapLookup
(final Map<String, V>
the map of keys to values, may be null.
map
)
References Deprecated StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.

Returns a lookup which looks up values using a map.

public static StrLookup<?>

Returns:

a lookup that always returns null, not null.
noneLookup
()
References Deprecated StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.

Returns a lookup which always returns null.

public static StrLookup<String>

Returns:

a lookup using the map, not null.
resourceBundleLookup
(final ResourceBundle
the map of keys to values, may be null.
resourceBundle
)
References Deprecated StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.

Returns a lookup which looks up values using a ResourceBundle.

public static StrLookup<String>

Returns:

a lookup using system properties, not null.
systemPropertiesLookup
()
References Deprecated StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.

Returns a new lookup which uses a copy of the current System properties.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

NONE_LOOKUPback to summary
private static final StrLookup<String> NONE_LOOKUP

References Deprecated

StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Lookup that always returns null.

SYSTEM_PROPERTIES_LOOKUPback to summary
private static final StrLookup<String> SYSTEM_PROPERTIES_LOOKUP

References Deprecated

StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Lookup based on system properties.

Constructor Detail

StrLookupback to summary
protected StrLookup()

Constructs a new instance for subclasses.

Method Detail

mapLookupback to summary
public static <V> StrLookup<V> mapLookup(final Map<String, V> map)

References Deprecated

StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Returns a lookup which looks up values using a map.

If the map is null, then null will be returned from every lookup. The map result object is converted to a string using toString().

Parameters
<V>
the type of the values supported by the lookup.
map:Map<String, V>

the map of keys to values, may be null.

Returns:StrLookup<V>

a lookup using the map, not null.

noneLookupback to summary
public static StrLookup<?> noneLookup()

References Deprecated

StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Returns a lookup which always returns null.

Returns:StrLookup<?>

a lookup that always returns null, not null.

resourceBundleLookupback to summary
public static StrLookup<String> resourceBundleLookup(final ResourceBundle resourceBundle)

References Deprecated

StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Returns a lookup which looks up values using a ResourceBundle.

If the ResourceBundle is null, then null will be returned from every lookup. The map result object is converted to a string using toString().

Parameters
resourceBundle:ResourceBundle

the map of keys to values, may be null.

Returns:StrLookup<String>

a lookup using the map, not null.

See Also
StringLookupFactory#resourceBundleStringLookup(String)
systemPropertiesLookupback to summary
public static StrLookup<String> systemPropertiesLookup()

References Deprecated

StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Returns a new lookup which uses a copy of the current System properties.

If a security manager blocked access to system properties, then null will be returned from every lookup.

If a null key is used, this lookup will throw a NullPointerException.

Returns:StrLookup<String>

a lookup using system properties, not null.

org.apache.commons.text back to summary

private final Class StrLookup.MapStrLookup<V>

extends StrLookup<V>
Class Inheritance
Type Parameters
<V>
the type of the values supported by the lookup

References Deprecated

StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Lookup implementation that uses a Map.

Field Summary

Modifier and TypeField and Description
private final Map<String, V>
map

Map keys are variable names and value.

Constructor Summary

AccessConstructor and Description
private
MapStrLookup(final Map<String, V>
the map of keys to values, may be null
map
)

Creates a new instance backed by a Map.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

The matching value, null if no match
lookup
(final String
the key to be looked up, may be null
key
)

Implements org.apache.commons.text.lookup.StringLookup.lookup.

Looks up a String key to a String value using the map.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.apache.commons.text.StrLookup:
mapLookupnoneLookupresourceBundleLookupsystemPropertiesLookup

Field Detail

mapback to summary
private final Map<String, V> map

Map keys are variable names and value.

Constructor Detail

MapStrLookupback to summary
private MapStrLookup(final Map<String, V> map)

Creates a new instance backed by a Map.

Parameters
map:Map<String, V>

the map of keys to values, may be null

Method Detail

lookupback to summary
public String lookup(final String key)

Implements org.apache.commons.text.lookup.StringLookup.lookup.

Looks up a String key to a String value using the map.

If the map is null, then null is returned. The map result object is converted to a string using toString().

Parameters
key:String

the key to be looked up, may be null

Returns:String

The matching value, null if no match

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
org.apache.commons.text back to summary

private final Class StrLookup.ResourceBundleLookup

extends StrLookup<String>
Class Inheritance

References Deprecated

StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Lookup implementation based on a ResourceBundle.

Field Summary

Modifier and TypeField and Description
private final ResourceBundle
resourceBundle

ResourceBundle keys are variable names and value.

Constructor Summary

AccessConstructor and Description
private
ResourceBundleLookup(final ResourceBundle
the ResourceBundle of keys to values, may be null.
resourceBundle
)

Creates a new instance backed by a ResourceBundle.

Method Summary

Modifier and TypeMethod and Description
public String
lookup(final String key)

Implements org.apache.commons.text.lookup.StringLookup.lookup.

Looks up a String key to provide a String value.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.apache.commons.text.StrLookup:
mapLookupnoneLookupresourceBundleLookupsystemPropertiesLookup

Field Detail

resourceBundleback to summary
private final ResourceBundle resourceBundle

ResourceBundle keys are variable names and value.

Constructor Detail

ResourceBundleLookupback to summary
private ResourceBundleLookup(final ResourceBundle resourceBundle)

Creates a new instance backed by a ResourceBundle.

Parameters
resourceBundle:ResourceBundle

the ResourceBundle of keys to values, may be null.

Method Detail

lookupback to summary
public String lookup(final String key)

Implements org.apache.commons.text.lookup.StringLookup.lookup.

Doc from org.apache.commons.text.lookup.StringLookup.lookup.

Looks up a String key to provide a String value.

The internal implementation may use any mechanism to return the value. The simplest implementation is to use a Map. However, virtually any implementation is possible.

For example, it would be possible to implement a lookup that used the key as a primary key, and looked up the value on demand from the database Or, a numeric based implementation could be created that treats the key as an integer, increments the value and return the result as a string - converting 1 to 2, 15 to 16 etc.

This method always returns a String, regardless of the underlying data, by converting it as necessary. For example:

Map<String, Object> map = new HashMap<String, Object>();
map.put("number", Integer.valueOf(2));
assertEquals("2", StringLookupFactory.mapStringLookup(map).lookup("number"));
Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
org.apache.commons.text back to summary

private final Class StrLookup.SystemPropertiesStrLookup

extends StrLookup<String>
Class Inheritance

References Deprecated

StrLookup is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Lookup implementation based on system properties.

Constructor Summary

AccessConstructor and Description
private
SystemPropertiesStrLookup()

Private for Spotbugs SING_SINGLETON_GETTER_NOT_SYNCHRONIZED.

Method Summary

Modifier and TypeMethod and Description
public String
lookup(final String key)

Implements org.apache.commons.text.lookup.StringLookup.lookup.

Looks up a String key to provide a String value.

Inherited from org.apache.commons.text.StrLookup:
mapLookupnoneLookupresourceBundleLookupsystemPropertiesLookup

Constructor Detail

SystemPropertiesStrLookupback to summary
private SystemPropertiesStrLookup()

Private for Spotbugs SING_SINGLETON_GETTER_NOT_SYNCHRONIZED.

Method Detail

lookupback to summary
public String lookup(final String key)

Implements org.apache.commons.text.lookup.StringLookup.lookup.

Doc from org.apache.commons.text.lookup.StringLookup.lookup.

Looks up a String key to provide a String value.

The internal implementation may use any mechanism to return the value. The simplest implementation is to use a Map. However, virtually any implementation is possible.

For example, it would be possible to implement a lookup that used the key as a primary key, and looked up the value on demand from the database Or, a numeric based implementation could be created that treats the key as an integer, increments the value and return the result as a string - converting 1 to 2, 15 to 16 etc.

This method always returns a String, regardless of the underlying data, by converting it as necessary. For example:

Map<String, Object> map = new HashMap<String, Object>();
map.put("number", Integer.valueOf(2));
assertEquals("2", StringLookupFactory.mapStringLookup(map).lookup("number"));
This implementation directly accesses system properties.
Annotations
@Override