@MinDoc(copyright="Copyright 2009 A. Weinert", author="Albrecht Weinert", version="V.56", lastModified="28.06.2021", usage="import", purpose="common map and properties utilities") public abstract class PropMapHelper extends Object
Map
s and properties
especially for
AbstractMap<CharSequence, String>
, used among
others in PropMap
, Prop
and AppLangMap
.Modifier and Type | Class and Description |
---|---|
static class |
PropMapHelper.Entry
An entry: key value pair for (Prop)Maps.
|
static class |
PropMapHelper.Indexed
Designation of an indexed property.
|
Modifier and Type | Field and Description |
---|---|
protected static String |
lastSuccReadEnco
Last successful file encoding for reading or default.
|
static int |
PUSTFI
Modifier public static final.
|
static String |
specialCharsToEscape
Characters to be transformed into backslash (\) escape sequences.
|
Modifier and Type | Method and Description |
---|---|
static String |
doEscape(CharSequence sequ,
boolean escapeSurSpace)
Converting special and control characters to backslash escape
sequences.
|
static Method |
getMethod(Class<?> cl,
String name,
Class<?>... parTypes)
Get a method by signature for a class.
|
static int |
gtPrim(int val)
A next prime number.
|
static void |
load(InputStream input,
CharSequence encoding,
Map<CharSequence,String> map)
Read a list of properties from a stream.
|
static boolean |
oddEndSlashs(CharSequence line)
A character sequence ends with a odd number of (\) backslashes.
|
static int |
posHash(String key)
Positive hash code.
|
static boolean |
setField(Object obj,
String key,
String value)
Setting an object's field (beans property).
|
static void |
store(Map<?,?> map,
OutputStream output,
CharSequence startComment,
CharSequence encoding)
Put a list of properties to an output stream.
|
static String |
unEscape(CharSequence sequ)
Convert backslash escape sequences to the character.
|
public static final String specialCharsToEscape
public static final int PUSTFI
25
Modifier
,
Constant Field Valuesprotected static volatile String lastSuccReadEnco
public static void load(InputStream input, CharSequence encoding, Map<CharSequence,String> map) throws IOException, NullPointerException
Map
.put(key, value)
of the Map<CharSequence, String> map
passed as parameter.map
.Properties
.load(InputStream)
. ComVar.EMPTY_STRING
) as value.ComVar.EMPTY_STRING
) by parameter parsing.encoding
is stripped from surrounding white space. If null or
(then) empty ComVar.FILE_ENCODING
is used. If this or the given
encoding
fails ISO-8859-1 is used.input
- the stream to read the properties fromencoding
- the inputs encoding (or character set)map
- the map to put the properties inIOException
- when problems reading the inputNullPointerException
- when input or map are nullUnsupportedOperationException
- if a put is rejected by
map
, the reason the often being the changing of an
immutable entry's value.IllegalArgumentException
- if put(String, String) is so rejected by
map
.public static String unEscape(CharSequence sequ)
sequ
the backslash escape sequences,
namely \t, \r, \n, \f will be converted to the corresponding control
character.sequ
- sequence to convertIllegalArgumentException
- if \uxxxx - syntactical faultsNullPointerException
- sequ == nullpublic static void store(Map<?,?> map, OutputStream output, CharSequence startComment, CharSequence encoding) throws IOException
Map
map
using the syntactical rules documented with
Properties
.store(OutputStream, String)
and
load(InputStream, CharSequence, Map)
.Properties
.store(OutputStream, String)
respectively an internal helper do (at least
did) faultily not act as there documented.startComment
;
the second one giving the actual date by
TimeHelper
.TimeHelper.format(CharSequence, java.time.ZonedDateTime)
.Map.entrySet()
and
Set.toArray()
. (This operation is synchronised with
map.) Every non null entry in that array will be output in the text
form key = value
. Special characters
are converted before by the method
doEscape((CharSequence, true)
)
to backslash escape sequences.encoding
is stripped from surrounding white space. If null or
(then) empty ComVar.FILE_ENCODING
is used. If this or the given
encoding
fails ISO-8859-1 is used.startComment
will be substituted by a raw hint
to the syntax "Map: key = value". If startComment
is
multi line, each line except the first one must start by # or
"smuggle in" a key value pair, strictly obeying the syntax.
This is NOT checked in this method.map
- the propertiesoutput
- the stream to write the properties tostartComment
- a describing comment to put at the beginencoding
- the streams encoding (character set)IOException
- when output problemsNullPointerException
- when output or map are nullpublic static String doEscape(CharSequence sequ, boolean escapeSurSpace)
escapeSurSpace
is true, a given leading and / trailing space
in sequ
are replaced by "\ ".\
, tab, form feed, line feed and return as well as
= # : and ! will be converted to\\
, \t
, \f
, \n
,
\r
respectively \=
, \#
and so
on.load(InputStream, CharSequence, Map)
.\uxxxx
,
xxxx being the four digit hexadecimal Unicode number (see.
TextHelper.fourDigitHex(Appendable, int)
.sequ
- the sequence to convertescapeSurSpace
- true: convert starting and trailing blank (if
there) to "\ "public static final int posHash(String key)
String
.String.hashCode()
of key
made
non negative by cutting the (31st) sign bit off.key
- may be empty but never nullpublic static boolean oddEndSlashs(CharSequence line)
line
ends
with one or a higher odd number of sequential \ backslashes.line
- sequence to be consideredNullPointerException
- if line is nullpublic static int gtPrim(int val)
val
. One usage is getting the
next about double prime size, when enlarging / rehashing a
container.public static Method getMethod(Class<?> cl, String name, Class<?>... parTypes)
cl.getMethod(name, parTypes)
except returning null instead of
raising exceptions when no method object could be delivered.cl
- the class having the method searched for (hopefully)name
- the name of the methodparTypes
- the parameter typespublic static boolean setField(Object obj, String key, String value) throws SecurityException, IllegalArgumentException
obj
or key
is null, nothing will happen except
returning false.obj
to set its property named key
by the value
value
.obj
is of type AttrSettable
andAttrSettable
.setAttribute(key, value
does not return
NO_KNOWN_ATTRIBUTE
.obj
a
SecurityException will happen.obj
's property named key
by the
value
is effected either by accessing a public object variable
or by using a public method named setKey()
.key
may designate an indexed property according to the
rules of
PropMapHelper.Indexed
.make(key)
. If this is
the case, with the key
shortened by the index two parameter
set methods setKey(int index, ..)
are searched for.value
is null.key
designates possibly an indexed property,
setKey(int, String) and afterwards setKey(int, CharSequence).value
is null.value
is decodable
as int by (TextHelper.asIntObj(CharSequence)
.value
is decodable
as a binary ("truth") value by
TextHelper.asBoolObj(CharSequence)
.value
as colour by
ColorHelper.getColor(CharSequence)
). Is that impossible an
IllegalArgumentException
is thrown, otherwise of cause the
setter is called.Color
the property has to be either a colour or is
wrong. Hence the IllegalArgumentException before the search for
public variables.AttrSettable
.setAttribute(key, value
; see above.value
. This case if forwarded by this method
as an IllegalArgumentException
, too.key
is tried. Preconditions:obj
and not inherited.CharSequence
is gladly accepted for setters).value
is null or not
interpretable according to the variable's (int or boolean) type.
No exception is raised due to non fitting types or values.key
contains white spaces or otherwise does not comply
to Java's rules for variable names, with all described efforts nothing
will be effected. To avoid these waste of resources and time a filtering
of keys before or while looping over all properties should be done by
the caller. The method
Prop.setFields(Object)
which uses this method, tries to avoid
those wasteful calls.obj
- the object, whose property key might be changedkey
- name of the propertyvalue
- new value of the propertySecurityException
- if the runtime forbids introspection into objIllegalArgumentException
- if a called setter throws itself
an exception , like for example
IllegalArgumentException
or a
PropertyVetoException
. The exception's message
is forwarded via the new IllegalArgumentException
Prop.setFields(Object)