public final class Functions extends Object
Environment
(if needed). This is
automatically filled in by JOSM and the user only sees the remaining arguments.
When one of the user supplied arguments cannot be converted the
expected type or is null, the function is not called and it returns null
immediately. Add the annotation ExpressionFactory.NullableArguments
to allow null arguments.
Every method must be static.ExpressionFactory
)Modifier | Constructor and Description |
---|---|
private |
Functions() |
Modifier and Type | Method and Description |
---|---|
static float |
alpha(Color c)
Get the value of the alpha channel in the rgba color model
|
static Object |
any(Environment ignored,
Object... args)
Returns the first non-null object.
|
static Float |
areasize(Environment env)
Returns the area of a closed way or multipolygon in square meters or
null . |
static boolean |
at(Environment env,
double lat,
double lon)
Determines if the object centroid lies at given lat/lon coordinates.
|
static float |
blue(Color c)
Get the value of the blue color channel in the rgb color model
|
static Double |
cardinal_to_radians(String cardinal)
Converts an angle diven in cardinal directions to radians.
|
static LatLon |
center(Environment env)
Returns the center of the environment OSM primitive.
|
static String |
child_tag(Environment env,
String key)
Gets the value of the key
key from the object's child. |
static String |
color2html(Color c)
Computes the HTML notation (
#rrggbb ) for a color value). |
static String |
concat(Environment ignored,
Object... args)
Assembles the strings to one.
|
static int |
count_roles(Environment env,
String... roles)
Returns the number of primitives in a relation with the specified roles.
|
static Integer |
count(List<?> lst)
Returns the number of elements in a list.
|
static long |
CRC32_checksum(String s)
Calculates the CRC32 checksum from a string (based on RFC 1952).
|
static double |
degree_to_radians(double degree)
Converts an angle in degrees to radians.
|
static double |
divided_by(double a,
double b)
Function associated to the numeric "/" operator.
|
static boolean |
equal(Object a,
Object b)
Determines if the objects
a and b are equal. |
static Object |
eval(Object o)
Identity function for compatibility with MapCSS specification.
|
static Object |
get(List<?> lst,
float n)
Get the
n th element of the list lst (counting starts at 0). |
static double |
gpx_distance(Environment env)
Returns the lowest distance between the OSM object and a GPX point
|
static boolean |
greater_equal(float a,
float b)
Function associated to the logical ">=" operator.
|
static boolean |
greater(float a,
float b)
Function associated to the logical ">" operator.
|
static float |
green(Color c)
Get the value of the green color channel in the rgb color model
|
static boolean |
has_tag_key(Environment env,
String key)
Determines whether the object has a tag with the given key.
|
static Color |
hsb_color(float h,
float s,
float b)
Create color from hsb color model.
|
static Color |
html2color(String html)
Creates a color value from an HTML notation, i.e.,
#rrggbb . |
static Float |
index(Environment env)
Returns the index of node in parent way or member in parent relation.
|
static boolean |
inside(Environment env,
String codes)
Determines if the object is inside territories matching given ISO3166 codes.
|
static boolean |
is_anticlockwise(Environment env)
Determines whether the way is
closed and oriented anticlockwise ,
or non-closed and the 1st, 2nd and last node are in anticlockwise order . |
static boolean |
is_clockwise(Environment env)
Determines whether the way is
closed and oriented clockwise ,
or non-closed and the 1st, 2nd and last node are in clockwise order . |
static Boolean |
is_prop_set(Environment env,
String key)
Determines whether property
key is set. |
static Boolean |
is_prop_set(Environment env,
String key,
String layer)
Determines whether property
key is set on layer layer . |
static boolean |
is_right_hand_traffic(Environment env)
check if there is right-hand traffic at the current location
|
static boolean |
is_similar(String string1,
String string2)
Check if two strings are similar, but not identical, i.e., have a Levenshtein distance of 1 or 2.
|
static String |
join_list(String separator,
List<String> values)
Joins a list of
values into a single string with fields separated by separator . |
static String |
join(Environment ignored,
String... args)
Assembles the strings to one, where the first entry is used as separator.
|
static String |
JOSM_pref(Environment env,
String key,
String def)
|
static Boolean |
JOSM_search(Environment env,
String searchStr)
Determines whether the JOSM search with
searchStr applies to the object. |
static boolean |
less_equal(float a,
float b)
Function associated to the logical "<=" operator.
|
static boolean |
less(float a,
float b)
Function associated to the logical "<" operator.
|
static List<Object> |
list(Environment ignored,
Object... args)
Creates a list of values, e.g., for the
dashes property. |
static String |
lower(String s)
Converts string
s to lowercase. |
static double |
minus(double a,
double b)
Function associated to the numeric "-" operator.
|
static float |
mod(float a,
float b)
Function associated to the math modulo "%" operator.
|
static boolean |
not_equal(Object a,
Object b)
Determines if the objects
a and b are not equal. |
static boolean |
not(boolean b)
Function associated to the logical "!" operator.
|
static int |
number_of_tags(Environment env)
Get the number of tags for the current primitive.
|
static int |
osm_changeset_id(Environment env)
Returns the id of the changeset the current object was last uploaded to.
|
static long |
osm_id(Environment env)
Returns the OSM id of the current object.
|
static int |
osm_timestamp(Environment env)
Returns the time of last modification to the current object, as timestamp.
|
static long |
osm_user_id(Environment env)
Returns the OSM user id who last touched the current object.
|
static String |
osm_user_name(Environment env)
Returns the OSM user name who last touched the current object.
|
static int |
osm_version(Environment env)
Returns the version number of the current object.
|
static boolean |
outside(Environment env,
String codes)
Determines if the object is outside territories matching given ISO3166 codes.
|
static Long |
parent_osm_id(Environment env)
Returns the OSM id of the object's parent.
|
static String |
parent_tag(Environment env,
String key)
Gets the first non-null value of the key
key from the object's parent(s). |
static List<String> |
parent_tags(Environment env,
String key)
Gets a list of all non-null values of the key
key from the object's parent(s). |
static Double |
parent_way_angle(Environment env)
Get the rotation angle of the preceding parent way segment at the node location.
|
private static int |
parse_regex_flags(String flags)
Parse flags for regex usage.
|
static double |
plus(double a,
double b)
Function associated to the numeric "+" operator.
|
static Object |
print(Object o)
Prints the object to the command line (for debugging purpose).
|
static Object |
println(Object o)
Prints the object to the command line, with new line at the end
(for debugging purpose).
|
static Object |
prop(Environment env,
String key)
Returns the value of the property
key , e.g., prop("width") . |
static Object |
prop(Environment env,
String key,
String layer)
Returns the value of the property
key from layer layer . |
static float |
red(Color c)
Get the value of the red color channel in the rgb color model
|
static List<String> |
regexp_match(String pattern,
String target)
Tries to match string against pattern regexp and returns a list of capture groups in case of success.
|
static List<String> |
regexp_match(String pattern,
String target,
String flags)
Tries to match string against pattern regexp and returns a list of capture groups in case of success.
|
static boolean |
regexp_test(String pattern,
String target)
Tests if string
target matches pattern pattern |
static boolean |
regexp_test(String pattern,
String target,
String flags)
Tests if string
target matches pattern pattern |
static String |
replace(String s,
String target,
String replacement)
Replaces in
s every target} substring by replacement . |
static Color |
rgb(float r,
float g,
float b)
Creates a color value with the specified amounts of
r ed, g reen, b lue (arguments from 0.0 to 1.0) |
static Color |
rgba(float r,
float g,
float b,
float alpha)
Creates a color value with the specified amounts of
r ed, g reen, b lue, alpha
(arguments from 0.0 to 1.0) |
static String |
role(Environment env)
Returns the role of current object in parent relation, or role of child if current object is a relation.
|
static Object |
setting(Environment env,
String key)
Get value of a setting.
|
static List<String> |
sort_list(List<String> sortables)
Sort a list of strings
|
static List<String> |
sort(Environment ignored,
String... sortables)
Sort an array of strings
|
static List<String> |
split(String sep,
String toSplit)
Splits string
toSplit at occurrences of the separator string sep and returns a list of matches. |
static String |
substring(String s,
float begin)
Returns the substring of
s starting at index begin (inclusive, 0-indexed). |
static String |
substring(String s,
float begin,
float end)
Returns the substring of
s starting at index begin (inclusive)
and ending at index end , (exclusive, 0-indexed). |
static List<String> |
tag_regex(Environment env,
String keyRegex)
Get keys that follow a regex
|
static List<String> |
tag_regex(Environment env,
String keyRegex,
String flags)
Get keys that follow a regex
|
static String |
tag(Environment env,
String key)
Gets the value of the key
key from the object in question. |
static double |
times(double a,
double b)
Function associated to the numeric "*" operator.
|
static String |
title(String str)
Returns a title-cased version of the string where words start with an uppercase character and the remaining characters are lowercase
Also known as "capitalize".
|
static boolean |
to_boolean(String value)
Parses the string argument as a boolean.
|
static byte |
to_byte(String value)
Parses the string argument as a byte.
|
static double |
to_double(String value)
Parses the string argument as a double.
|
static float |
to_float(String value)
Parses the string argument as a float.
|
static int |
to_int(String value)
Parses the string argument as an int.
|
static long |
to_long(String value)
Parses the string argument as a long.
|
static short |
to_short(String value)
Parses the string argument as a short.
|
static String |
tr(Environment ignored,
String... args)
Translates some text for the current locale.
|
static List<String> |
trim_list(List<String> strings)
Trim whitespaces from the strings
strings . |
static String |
trim(String s)
Trim whitespaces from the string
s . |
static List<String> |
uniq_list(List<String> values)
Get unique values
|
static List<String> |
uniq(Environment ignored,
String... values)
Get unique values
|
static String |
upper(String s)
Converts string
s to uppercase. |
static String |
URL_decode(String s)
Percent-decode a string.
|
static String |
URL_encode(String s)
Percent-encode a string.
|
static Float |
waylength(Environment env)
Returns the length of the way in metres or
null . |
static String |
XML_encode(String s)
XML-encode a string.
|
private Functions()
public static Object eval(Object o)
o
- any objecto
unchangedpublic static double plus(double a, double b)
a
- the first operandb
- the second operandFloat.sum(float, float)
public static double minus(double a, double b)
a
- the first operandb
- the second operandpublic static double times(double a, double b)
a
- the first operandb
- the second operandpublic static double divided_by(double a, double b)
a
- the first operandb
- the second operandpublic static float mod(float a, float b)
a
- first valueb
- second valuea mod b
, e.g., mod(7, 5) = 2
public static List<Object> list(Environment ignored, Object... args)
dashes
property.ignored
- The environment (ignored)args
- The values to put in a listArrays.asList(Object[])
public static Integer count(List<?> lst)
lst
- the listpublic static Object any(Environment ignored, Object... args)
ignored
- The environment (ignored)args
- argumentsUtils.firstNonNull(Object[])
public static Object get(List<?> lst, float n)
n
th element of the list lst
(counting starts at 0).lst
- listn
- indexn
th element of the list, or null
if index out of rangepublic static List<String> split(String sep, String toSplit)
toSplit
at occurrences of the separator string sep
and returns a list of matches.sep
- separator stringtoSplit
- string to splitString.split(String)
public static Color rgb(float r, float g, float b)
r
ed, g
reen, b
lue (arguments from 0.0 to 1.0)r
- the red componentg
- the green componentb
- the blue componentColor(float, float, float)
public static Color rgba(float r, float g, float b, float alpha)
r
ed, g
reen, b
lue, alpha
(arguments from 0.0 to 1.0)r
- the red componentg
- the green componentb
- the blue componentalpha
- the alpha componentColor(float, float, float, float)
public static Color hsb_color(float h, float s, float b)
h
- hues
- saturationb
- brightnesspublic static Color html2color(String html)
#rrggbb
.html
- HTML notationpublic static String color2html(Color c)
#rrggbb
) for a color value).c
- colorpublic static float red(Color c)
c
- colorColor.getRed()
public static float green(Color c)
c
- colorColor.getGreen()
public static float blue(Color c)
c
- colorColor.getBlue()
public static float alpha(Color c)
c
- colorColor.getAlpha()
public static String concat(Environment ignored, Object... args)
ignored
- The environment (ignored)args
- argumentsCollectors.joining()
public static String join(Environment ignored, String... args)
ignored
- The environment (ignored)args
- arguments. First one is used as separatorString.join(CharSequence, CharSequence...)
public static String join_list(String separator, List<String> values)
values
into a single string with fields separated by separator
.separator
- the separatorvalues
- collection of objectsString.join(CharSequence, Iterable)
public static Object prop(Environment env, String key)
key
, e.g., prop("width")
.env
- the environmentkey
- the property keypublic static Object prop(Environment env, String key, String layer)
key
from layer layer
.env
- the environmentkey
- the property keylayer
- layerpublic static Boolean is_prop_set(Environment env, String key)
key
is set.env
- the environmentkey
- the property keytrue
if the property is set, false
otherwisepublic static Boolean is_prop_set(Environment env, String key, String layer)
key
is set on layer layer
.env
- the environmentkey
- the property keylayer
- layertrue
if the property is set, false
otherwisepublic static String tag(Environment env, String key)
key
from the object in question.env
- the environmentkey
- the OSM keypublic static List<String> tag_regex(Environment env, String keyRegex)
env
- the environmentkeyRegex
- the pattern that the key must matchtag_regex(Environment, String, String)
public static List<String> tag_regex(Environment env, String keyRegex, String flags)
env
- the environmentkeyRegex
- the pattern that the key must matchflags
- a string that may contain "i" (case insensitive), "m" (multiline) and "s" ("dot all")Pattern.CASE_INSENSITIVE
,
Pattern.DOTALL
,
Pattern.MULTILINE
private static int parse_regex_flags(String flags)
flags
- a string that may contain "i" (case insensitive), "m" (multiline) and "s" ("dot all")Pattern
objectPattern.CASE_INSENSITIVE
,
Pattern.DOTALL
,
Pattern.MULTILINE
public static String parent_tag(Environment env, String key)
key
from the object's parent(s).env
- the environmentkey
- the OSM keykey
from the object's parent(s)public static List<String> parent_tags(Environment env, String key)
key
from the object's parent(s).
The values are sorted according to AlphanumComparator
.env
- the environmentkey
- the OSM keykey
from the object's parent(s)public static Double parent_way_angle(Environment env)
env
- the environmentpublic static String child_tag(Environment env, String key)
key
from the object's child.env
- the environmentkey
- the OSM keykey
from the object's child, or null
if there is no childpublic static Long parent_osm_id(Environment env)
Parent must be matched by child selector.
env
- the environmentnull
PrimitiveId.getUniqueId()
public static double gpx_distance(Environment env)
env
- the environmentDouble.MAX_VALUE
public static boolean has_tag_key(Environment env, String key)
env
- the environmentkey
- the OSM keytrue
if the object has a tag with the given key, false
otherwisepublic static Float index(Environment env)
env
- the environmentpublic static List<String> sort(Environment ignored, String... sortables)
ignored
- The environment (ignored)sortables
- The array to sortpublic static List<String> sort_list(List<String> sortables)
sortables
- The list to sortpublic static List<String> uniq(Environment ignored, String... values)
ignored
- The environment (ignored)values
- A list of values that may have duplicatespublic static List<String> uniq_list(List<String> values)
values
- A list of values that may have duplicatespublic static String role(Environment env)
env
- the environmentEnvironment.getRole()
public static int count_roles(Environment env, String... roles)
env
- the environmentroles
- The roles to count in the relationpublic static Float areasize(Environment env)
null
.env
- the environmentnull
Geometry.computeArea(IPrimitive)
public static Float waylength(Environment env)
null
.env
- the environmentnull
.Way.getLength()
public static boolean not(boolean b)
b
- boolean valuetrue
if !b
public static boolean greater_equal(float a, float b)
a
- first valueb
- second valuetrue
if a >= b
public static boolean less_equal(float a, float b)
a
- first valueb
- second valuetrue
if a <= b
public static boolean greater(float a, float b)
a
- first valueb
- second valuetrue
if a > b
public static boolean less(float a, float b)
a
- first valueb
- second valuetrue
if a < b
public static double degree_to_radians(double degree)
degree
- the angle in degreesMath.toRadians(double)
public static Double cardinal_to_radians(String cardinal)
n
, north
, ne
, northeast
,
e
, east
, se
, southeast
, s
, south
,
sw
, southwest
, w
, west
, nw
, northwest
.cardinal
- the angle in cardinal directions.RotationAngle.parseCardinalRotation(String)
public static boolean equal(Object a, Object b)
a
and b
are equal.a
- First objectb
- Second objecttrue
if objects are equal, false
otherwiseObject.equals(Object)
public static boolean not_equal(Object a, Object b)
a
and b
are not equal.a
- First objectb
- Second objectfalse
if objects are equal, true
otherwiseObject.equals(Object)
public static Boolean JOSM_search(Environment env, String searchStr)
searchStr
applies to the object.env
- the environmentsearchStr
- the search stringtrue
if the JOSM search with searchStr
applies to the objectSearchCompiler
public static String JOSM_pref(Environment env, String key, String def)
Preferences
string for key key
,
and defaults to def
if that is null.
If the default value can be converted to a Color
,
the NamedColorProperty
is retrieved as string.env
- the environmentkey
- Key in JOSM preferencedef
- Default valuepublic static boolean regexp_test(String pattern, String target)
target
matches pattern pattern
pattern
- The regex expressiontarget
- The character sequence to be matchedtrue
if, and only if, the entire region sequence matches the patternPattern.matches(String, CharSequence)
public static boolean regexp_test(String pattern, String target, String flags)
target
matches pattern pattern
pattern
- The regex expressiontarget
- The character sequence to be matchedflags
- a string that may contain "i" (case insensitive), "m" (multiline) and "s" ("dot all")true
if, and only if, the entire region sequence matches the patternPattern.CASE_INSENSITIVE
,
Pattern.DOTALL
,
Pattern.MULTILINE
public static List<String> regexp_match(String pattern, String target, String flags)
pattern
- The regex expressiontarget
- The character sequence to be matchedflags
- a string that may contain "i" (case insensitive), "m" (multiline) and "s" ("dot all")Matcher.matches()
, or null
.Pattern.CASE_INSENSITIVE
,
Pattern.DOTALL
,
Pattern.MULTILINE
public static List<String> regexp_match(String pattern, String target)
pattern
- The regex expressiontarget
- The character sequence to be matchedMatcher.matches()
, or null
.public static long osm_id(Environment env)
env
- the environmentPrimitiveId.getUniqueId()
public static String osm_user_name(Environment env)
env
- the environmentIPrimitive.getUser()
public static long osm_user_id(Environment env)
env
- the environmentIPrimitive.getUser()
public static int osm_version(Environment env)
env
- the environmentIPrimitive.getVersion()
public static int osm_changeset_id(Environment env)
env
- the environmentIPrimitive.getChangesetId()
public static int osm_timestamp(Environment env)
env
- the environmentIPrimitive.getRawTimestamp()
public static String tr(Environment ignored, String... args)
{0}
, {1}
, …ignored
- The environment (ignored)args
- argumentspublic static String substring(String s, float begin)
s
starting at index begin
(inclusive, 0-indexed).s
- The base stringbegin
- The start indexString.substring(int)
public static String substring(String s, float begin, float end)
s
starting at index begin
(inclusive)
and ending at index end
, (exclusive, 0-indexed).s
- The base stringbegin
- The start indexend
- The end indexString.substring(int, int)
public static String replace(String s, String target, String replacement)
s
every target} substring by replacement
.s
- The source stringtarget
- The sequence of char values to be replacedreplacement
- The replacement sequence of char valuesString.replace(CharSequence, CharSequence)
public static String upper(String s)
s
to uppercase.s
- The source stringString.toUpperCase(Locale)
public static String lower(String s)
s
to lowercase.s
- The source stringString.toLowerCase(Locale)
public static String title(String str)
str
- The source stringCharacter.toTitleCase(char)
public static String trim(String s)
s
.s
- The source stringUtils.strip(java.lang.String)
public static List<String> trim_list(List<String> strings)
strings
.strings
- The list of strings to stripUtils.strip(java.lang.String)
public static boolean is_similar(String string1, String string2)
string1
- first string to comparestring2
- second string to compareUtils.isSimilar(java.lang.String, java.lang.String)
public static String URL_decode(String s)
s
- url-encoded stringpublic static String URL_encode(String s)
concat("data:image/svg+xml,", URL_encode("<svg>...</svg>"));
s
- arbitrary stringpublic static String XML_encode(String s)
s
- arbitrary stringpublic static long CRC32_checksum(String s)
s
- the stringpublic static boolean is_right_hand_traffic(Environment env)
env
- the environmentpublic static boolean is_clockwise(Environment env)
closed and oriented clockwise
,
or non-closed and the 1st, 2nd and last node are in clockwise order
.env
- the environmentpublic static boolean is_anticlockwise(Environment env)
closed and oriented anticlockwise
,
or non-closed and the 1st, 2nd and last node are in anticlockwise order
.env
- the environmentpublic static Object print(Object o)
o
- the objectpublic static Object println(Object o)
o
- the objectpublic static int number_of_tags(Environment env)
env
- the environmentpublic static Object setting(Environment env, String key)
env
- the environmentkey
- setting key (given as layer identifier, e.g. setting::mykey {...})public static LatLon center(Environment env)
env
- the environmentpublic static boolean inside(Environment env, String codes)
env
- the environmentcodes
- comma-separated list of ISO3166-1-alpha2 or ISO3166-2 country/subdivision codestrue
if the object is inside territory matching given ISO3166 codespublic static boolean outside(Environment env, String codes)
env
- the environmentcodes
- comma-separated list of ISO3166-1-alpha2 or ISO3166-2 country/subdivision codestrue
if the object is outside territory matching given ISO3166 codespublic static boolean at(Environment env, double lat, double lon)
env
- the environmentlat
- latitude, i.e., the north-south position in degreeslon
- longitude, i.e., the east-west position in degreestrue
if the object centroid lies at given lat/lon coordinatespublic static boolean to_boolean(String value)
value
- the String
containing the boolean representation to be parsedBoolean.parseBoolean(java.lang.String)
public static byte to_byte(String value)
value
- the String
containing the byte representation to be parsedByte.parseByte(java.lang.String, int)
public static short to_short(String value)
value
- the String
containing the short representation to be parsedShort.parseShort(java.lang.String, int)
public static int to_int(String value)
value
- the String
containing the int representation to be parsedInteger.parseInt(java.lang.String, int)
public static long to_long(String value)
value
- the String
containing the long representation to be parsedLong.parseLong(java.lang.String, int)
public static float to_float(String value)
value
- the String
containing the float representation to be parsedFloat.parseFloat(java.lang.String)
public static double to_double(String value)
value
- the String
containing the double representation to be parsedDouble.parseDouble(java.lang.String)