Package adams.core
Class Placeholders
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.Placeholders
-
- All Implemented Interfaces:
LoggingSupporter
,SizeOfHandler
,Serializable
public class Placeholders extends LoggingObject
A class for accessing the system-wide defined placeholders.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
ADAMS_PLACEHOLDERS
the environment variable to obtain placeholders from (semi-colon separated placeholder=path pairs).static String
CWD
the placeholder for the current working directory.static String
FILENAME
the filename.static String
HOME
the placeholder for the home directory.protected Set<String>
m_NoCollapse
the placeholders that are not to be collapsed.protected Map<String,String>
m_Placeholders
the placeholders.protected Properties
m_Properties
the properties.protected static Placeholders
m_Singleton
the singleton.static String
NO_COLLAPSE
the list of placeholders only to expand, but not collapse.static String
PLACEHOLDER_END
the ending string of a placeholder.static String
PLACEHOLDER_START
the starting string of a placeholder.static String
PROJECT
the placeholder for the project directory.static String
SEPARATOR
the separator for key-value pairs.static String
TMP
the placeholder for the tmp directory.-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
collapse(String s)
Matches all placeholders against the string.static String
collapseStr(String s)
Adds placeholders to the given string.protected String
doExpand(String s)
Expands all placeholders in the given string.String
expand(String s)
Expands all placeholders in the given string.static String
expandStr(String s)
Expands the placeholders in the given string.String
get(String key)
Returns the placeholder for the given (uppercase!) key.static Placeholders
getSingleton()
Returns the singleton instance of the Placeholders.boolean
has(String key)
Checks whether the placeholder exists.protected void
initialize()
loads the props file and interpretes it.boolean
isValid(String s)
Checks whether all placeholders in the given string can be expanded.static boolean
isValidStr(String s)
Checks whether all placeholders can be expanded.static void
main(String[] args)
For outputting placeholders.Set<String>
noCollapse()
Returns the placeholders that are excluded from collapsing.Set<String>
placeholders()
Returns all stored placeholder keys (local + global).String
remove(String key)
Removes the placeholder value under the specified key.String
set(String key, String value)
Sets the placeholder value under the specified key.Properties
toProperties()
Turns the global placeholders into a properties object.String
toString()
Returns the underlying properties storing the placeholders as simple string.-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
FILENAME
public static final String FILENAME
the filename.- See Also:
- Constant Field Values
-
CWD
public static final String CWD
the placeholder for the current working directory.- See Also:
- Constant Field Values
-
PROJECT
public static final String PROJECT
the placeholder for the project directory.- See Also:
- Constant Field Values
-
TMP
public static final String TMP
the placeholder for the tmp directory.- See Also:
- Constant Field Values
-
HOME
public static final String HOME
the placeholder for the home directory.- See Also:
- Constant Field Values
-
PLACEHOLDER_START
public static final String PLACEHOLDER_START
the starting string of a placeholder.- See Also:
- Constant Field Values
-
PLACEHOLDER_END
public static final String PLACEHOLDER_END
the ending string of a placeholder.- See Also:
- Constant Field Values
-
SEPARATOR
public static final String SEPARATOR
the separator for key-value pairs.- See Also:
- Constant Field Values
-
NO_COLLAPSE
public static final String NO_COLLAPSE
the list of placeholders only to expand, but not collapse.- See Also:
- Constant Field Values
-
ADAMS_PLACEHOLDERS
public static final String ADAMS_PLACEHOLDERS
the environment variable to obtain placeholders from (semi-colon separated placeholder=path pairs).- See Also:
- Constant Field Values
-
m_Singleton
protected static Placeholders m_Singleton
the singleton.
-
m_Properties
protected Properties m_Properties
the properties.
-
-
Method Detail
-
initialize
protected void initialize()
loads the props file and interpretes it.
-
placeholders
public Set<String> placeholders()
Returns all stored placeholder keys (local + global).- Returns:
- the placeholder keys (local + global)
-
noCollapse
public Set<String> noCollapse()
Returns the placeholders that are excluded from collapsing.- Returns:
- the placeholder keys
-
has
public boolean has(String key)
Checks whether the placeholder exists.- Parameters:
key
- the (uppercase) name of the placeholder to check- Returns:
- true if available
-
get
public String get(String key)
Returns the placeholder for the given (uppercase!) key. Trailing path element separators ("/" or "\") are always stripped.- Parameters:
key
- the (uppercase) name of the placeholder to retrieve- Returns:
- the value, null if not found
-
set
public String set(String key, String value)
Sets the placeholder value under the specified key.- Parameters:
key
- the placeholder key (uppercase!)value
- the value of the placeholder- Returns:
- any previously stored value for the placeholder, null if none previously stored
-
remove
public String remove(String key)
Removes the placeholder value under the specified key.- Parameters:
key
- the placeholder key (uppercase!) to remove- Returns:
- any previously stored value for the placeholder, null if none previously stored
-
isValid
public boolean isValid(String s)
Checks whether all placeholders in the given string can be expanded.- Parameters:
s
- the string to check- Returns:
- true if all placeholders could be expanded
-
expand
public String expand(String s)
Expands all placeholders in the given string.- Parameters:
s
- the string to expand- Returns:
- the string with the placeholders replaced
-
doExpand
protected String doExpand(String s)
Expands all placeholders in the given string.- Parameters:
s
- the string to expand- Returns:
- the string with the placeholders replaced
-
collapse
public String collapse(String s)
Matches all placeholders against the string. The one that shortens the string most, will be used.- Parameters:
s
- the string to process- Returns:
- the processed string
-
toString
public String toString()
Returns the underlying properties storing the placeholders as simple string.
-
toProperties
public Properties toProperties()
Turns the global placeholders into a properties object.- Returns:
- the generated properties
-
getSingleton
public static Placeholders getSingleton()
Returns the singleton instance of the Placeholders.- Returns:
- the singleton
-
isValidStr
public static boolean isValidStr(String s)
Checks whether all placeholders can be expanded.- Parameters:
s
- the string to process- Returns:
- true if all placeholders could be expanded
-
expandStr
public static String expandStr(String s)
Expands the placeholders in the given string.- Parameters:
s
- the string to process- Returns:
- the processed string
-
collapseStr
public static String collapseStr(String s)
Adds placeholders to the given string.- Parameters:
s
- the string to process- Returns:
- the processed string
-
main
public static void main(String[] args)
For outputting placeholders.- Parameters:
args
- the commandline arguments: [-env]
-
-