public static final class ExpressionFactory.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.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(Object... args)
Returns the first non-null object.
|
static Float |
areasize(Environment env)
Returns the area of a closed way in square meters or
null . |
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 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(Object... args)
Assembles the strings to one.
|
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 Float |
divided_by(float... args)
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 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 |
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 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(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(Object... args)
Creates a list of values, e.g., for the
dashes property. |
static Float |
minus(float... args)
Function associated to the numeric "-" 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 long |
osm_id(Environment env)
Returns the OSM id of the current object.
|
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 float |
plus(float... args)
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> |
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 String |
tag(Environment env,
String key)
Gets the value of the key
key from the object in question. |
static float |
times(float... args)
Function associated to the numeric "*" operator.
|
static String |
tr(String... args)
Translates some text for the current locale.
|
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 float plus(float... args)
args
- argumentspublic static Float minus(float... args)
args
- argumentspublic static float times(float... args)
args
- argumentspublic static Float divided_by(float... args)
args
- argumentspublic static List<Object> list(Object... args)
dashes
property.args
- The values to put in a listArrays.asList(Object[])
public static Integer count(List<?> lst)
lst
- the listpublic static Object any(Object... args)
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.Color(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.Color(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(Object... args)
args
- argumentsUtils.join(java.lang.String, java.util.Collection<?>)
public static String join(String... args)
args
- arguments. First one is used as separatorUtils.join(java.lang.String, java.util.Collection<?>)
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 objectsUtils.join(java.lang.String, java.util.Collection<?>)
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 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 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 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 String role(Environment env)
env
- the environmentEnvironment.getRole()
public static Float areasize(Environment env)
null
.env
- the environmentnull
Geometry.closedWayArea(Way)
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)
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 environmentAbstractPrimitive.getUniqueId()
public static String tr(String... args)
{0}
, {1}
, …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 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 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 {...})