Class Functions
- java.lang.Object
-
- org.openstreetmap.josm.gui.mappaint.mapcss.Functions
-
public final class Functions extends Object
List of functions that can be used in MapCSS expressions. First parameter can be of typeEnvironment
(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 annotationExpressionFactory.NullableArguments
to allow null arguments. Every method must be static.- Since:
- 15245 (extracted from
ExpressionFactory
)
-
-
Constructor Summary
Constructors Modifier Constructor Description private
Functions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static float
alpha(Color c)
Get the value of the alpha channel in the rgba color modelstatic 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 ornull
.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 modelstatic 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 keykey
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 Integer
count(List<?> lst)
Returns the number of elements in a list.static int
count_roles(Environment env, String... roles)
Returns the number of primitives in a relation with the specified roles.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 objectsa
andb
are equal.static Object
eval(Object o)
Identity function for compatibility with MapCSS specification.static Object
get(List<?> lst, float n)
Get then
th element of the listlst
(counting starts at 0).static double
gpx_distance(Environment env)
Returns the lowest distance between the OSM object and a GPX pointstatic boolean
greater(float a, float b)
Function associated to the logical ">" operator.static boolean
greater_equal(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 modelstatic 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 isclosed and oriented anticlockwise
, or non-closed and the1st, 2nd and last node are in anticlockwise order
.static boolean
is_clockwise(Environment env)
Determines whether the way isclosed and oriented clockwise
, or non-closed and the1st, 2nd and last node are in clockwise order
.static Boolean
is_prop_set(Environment env, String key)
Determines whether propertykey
is set.static Boolean
is_prop_set(Environment env, String key, String layer)
Determines whether propertykey
is set on layerlayer
.static boolean
is_right_hand_traffic(Environment env)
check if there is right-hand traffic at the current locationstatic 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(Environment ignored, String... args)
Assembles the strings to one, where the first entry is used as separator.static String
join_list(String separator, List<String> values)
Joins a list ofvalues
into a single string with fields separated byseparator
.static String
JOSM_pref(Environment env, String key, String def)
static Boolean
JOSM_search(Environment env, String searchStr)
Determines whether the JOSM search withsearchStr
applies to the object.static boolean
less(float a, float b)
Function associated to the logical "<" operator.static boolean
less_equal(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 thedashes
property.static String
lower(String s)
Converts strings
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(boolean b)
Function associated to the logical "!" operator.static boolean
not_equal(Object a, Object b)
Determines if the objectsa
andb
are not equal.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 keykey
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 keykey
from the object's parent(s).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 propertykey
, e.g.,prop("width")
.static Object
prop(Environment env, String key, String layer)
Returns the value of the propertykey
from layerlayer
.static float
red(Color c)
Get the value of the red color channel in the rgb color modelstatic 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 stringtarget
matches patternpattern
static boolean
regexp_test(String pattern, String target, String flags)
Tests if stringtarget
matches patternpattern
static String
replace(String s, String target, String replacement)
Replaces ins
every target} substring byreplacement
.static Color
rgb(float r, float g, float b)
Creates a color value with the specified amounts ofr
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 ofr
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(Environment ignored, String... sortables)
Sort an array of stringsstatic List<String>
sort_list(List<String> sortables)
Sort a list of stringsstatic List<String>
split(String sep, String toSplit)
Splits stringtoSplit
at occurrences of the separator stringsep
and returns a list of matches.static String
substring(String s, float begin)
Returns the substring ofs
starting at indexbegin
(inclusive, 0-indexed).static String
substring(String s, float begin, float end)
Returns the substring ofs
starting at indexbegin
(inclusive) and ending at indexend
, (exclusive, 0-indexed).static String
tag(Environment env, String key)
Gets the value of the keykey
from the object in question.static List<String>
tag_regex(Environment env, String keyRegex)
Get keys that follow a regexstatic List<String>
tag_regex(Environment env, String keyRegex, String flags)
Get keys that follow a regexstatic 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 String
trim(String s)
Trim whitespaces from the strings
.static List<String>
trim_list(List<String> strings)
Trim whitespaces from the stringsstrings
.static List<String>
uniq(Environment ignored, String... values)
Get unique valuesstatic List<String>
uniq_list(List<String> values)
Get unique valuesstatic String
upper(String s)
Converts strings
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 ornull
.static String
XML_encode(String s)
XML-encode a string.
-
-
-
Constructor Detail
-
Functions
private Functions()
-
-
Method Detail
-
eval
public static Object eval(Object o)
Identity function for compatibility with MapCSS specification.- Parameters:
o
- any object- Returns:
o
unchanged
-
plus
public static double plus(double a, double b)
Function associated to the numeric "+" operator.- Parameters:
a
- the first operandb
- the second operand- Returns:
- Sum of arguments
- See Also:
Float.sum(float, float)
-
minus
public static double minus(double a, double b)
Function associated to the numeric "-" operator.- Parameters:
a
- the first operandb
- the second operand- Returns:
- Subtraction of arguments
-
times
public static double times(double a, double b)
Function associated to the numeric "*" operator.- Parameters:
a
- the first operandb
- the second operand- Returns:
- Multiplication of arguments
-
divided_by
public static double divided_by(double a, double b)
Function associated to the numeric "/" operator.- Parameters:
a
- the first operandb
- the second operand- Returns:
- Division of arguments
-
mod
public static float mod(float a, float b)
Function associated to the math modulo "%" operator.- Parameters:
a
- first valueb
- second value- Returns:
a mod b
, e.g.,mod(7, 5) = 2
-
list
public static List<Object> list(Environment ignored, Object... args)
Creates a list of values, e.g., for thedashes
property.- Parameters:
ignored
- The environment (ignored)args
- The values to put in a list- Returns:
- list of values
- See Also:
Arrays.asList(Object[])
-
count
public static Integer count(List<?> lst)
Returns the number of elements in a list.- Parameters:
lst
- the list- Returns:
- length of the list
-
any
public static Object any(Environment ignored, Object... args)
Returns the first non-null object. The name originates from MapCSS standard.- Parameters:
ignored
- The environment (ignored)args
- arguments- Returns:
- the first non-null object
- See Also:
Utils.firstNonNull(Object[])
-
get
public static Object get(List<?> lst, float n)
Get then
th element of the listlst
(counting starts at 0).- Parameters:
lst
- listn
- index- Returns:
n
th element of the list, ornull
if index out of range- Since:
- 5699
-
split
public static List<String> split(String sep, String toSplit)
Splits stringtoSplit
at occurrences of the separator stringsep
and returns a list of matches.- Parameters:
sep
- separator stringtoSplit
- string to split- Returns:
- list of matches
- Since:
- 5699
- See Also:
String.split(String)
-
rgb
public static Color rgb(float r, float g, float b)
Creates a color value with the specified amounts ofr
ed,g
reen,b
lue (arguments from 0.0 to 1.0)- Parameters:
r
- the red componentg
- the green componentb
- the blue component- Returns:
- color matching the given components
- See Also:
Color(float, float, float)
-
rgba
public static Color rgba(float r, float g, float b, float alpha)
Creates a color value with the specified amounts ofr
ed,g
reen,b
lue,alpha
(arguments from 0.0 to 1.0)- Parameters:
r
- the red componentg
- the green componentb
- the blue componentalpha
- the alpha component- Returns:
- color matching the given components
- See Also:
Color(float, float, float, float)
-
hsb_color
public static Color hsb_color(float h, float s, float b)
Create color from hsb color model. (arguments form 0.0 to 1.0)- Parameters:
h
- hues
- saturationb
- brightness- Returns:
- the corresponding color
-
html2color
public static Color html2color(String html)
Creates a color value from an HTML notation, i.e.,#rrggbb
.- Parameters:
html
- HTML notation- Returns:
- color matching the given notation
-
color2html
public static String color2html(Color c)
Computes the HTML notation (#rrggbb
) for a color value).- Parameters:
c
- color- Returns:
- HTML notation matching the given color
-
red
public static float red(Color c)
Get the value of the red color channel in the rgb color model- Parameters:
c
- color- Returns:
- the red color channel in the range [0;1]
- See Also:
Color.getRed()
-
green
public static float green(Color c)
Get the value of the green color channel in the rgb color model- Parameters:
c
- color- Returns:
- the green color channel in the range [0;1]
- See Also:
Color.getGreen()
-
blue
public static float blue(Color c)
Get the value of the blue color channel in the rgb color model- Parameters:
c
- color- Returns:
- the blue color channel in the range [0;1]
- See Also:
Color.getBlue()
-
alpha
public static float alpha(Color c)
Get the value of the alpha channel in the rgba color model- Parameters:
c
- color- Returns:
- the alpha channel in the range [0;1]
- See Also:
Color.getAlpha()
-
concat
public static String concat(Environment ignored, Object... args)
Assembles the strings to one.- Parameters:
ignored
- The environment (ignored)args
- arguments- Returns:
- assembled string
- See Also:
Collectors.joining()
-
join
public static String join(Environment ignored, String... args)
Assembles the strings to one, where the first entry is used as separator.- Parameters:
ignored
- The environment (ignored)args
- arguments. First one is used as separator- Returns:
- assembled string
- See Also:
String.join(java.lang.CharSequence, java.lang.CharSequence...)
-
join_list
public static String join_list(String separator, List<String> values)
Joins a list ofvalues
into a single string with fields separated byseparator
.- Parameters:
separator
- the separatorvalues
- collection of objects- Returns:
- assembled string
- See Also:
String.join(java.lang.CharSequence, java.lang.CharSequence...)
-
prop
public static Object prop(Environment env, String key)
Returns the value of the propertykey
, e.g.,prop("width")
.- Parameters:
env
- the environmentkey
- the property key- Returns:
- the property value
-
prop
public static Object prop(Environment env, String key, String layer)
Returns the value of the propertykey
from layerlayer
.- Parameters:
env
- the environmentkey
- the property keylayer
- layer- Returns:
- the property value
-
is_prop_set
public static Boolean is_prop_set(Environment env, String key)
Determines whether propertykey
is set.- Parameters:
env
- the environmentkey
- the property key- Returns:
true
if the property is set,false
otherwise
-
is_prop_set
public static Boolean is_prop_set(Environment env, String key, String layer)
Determines whether propertykey
is set on layerlayer
.- Parameters:
env
- the environmentkey
- the property keylayer
- layer- Returns:
true
if the property is set,false
otherwise
-
tag
public static String tag(Environment env, String key)
Gets the value of the keykey
from the object in question.- Parameters:
env
- the environmentkey
- the OSM key- Returns:
- the value for given key
-
tag_regex
public static List<String> tag_regex(Environment env, String keyRegex)
Get keys that follow a regex- Parameters:
env
- the environmentkeyRegex
- the pattern that the key must match- Returns:
- the values for the keys that match the pattern
- Since:
- 15315
- See Also:
tag_regex(Environment, String, String)
-
tag_regex
public static List<String> tag_regex(Environment env, String keyRegex, String flags)
Get keys that follow a regex- Parameters:
env
- the environmentkeyRegex
- the pattern that the key must matchflags
- a string that may contain "i" (case insensitive), "m" (multiline) and "s" ("dot all")- Returns:
- the values for the keys that match the pattern
- Since:
- 15315
- See Also:
Pattern.CASE_INSENSITIVE
,Pattern.DOTALL
,Pattern.MULTILINE
-
parse_regex_flags
private static int parse_regex_flags(String flags)
Parse flags for regex usage. Shouldn't be used in mapcss- Parameters:
flags
- a string that may contain "i" (case insensitive), "m" (multiline) and "s" ("dot all")- Returns:
- An int that can be used by a
Pattern
object - See Also:
Pattern.CASE_INSENSITIVE
,Pattern.DOTALL
,Pattern.MULTILINE
-
parent_tag
public static String parent_tag(Environment env, String key)
Gets the first non-null value of the keykey
from the object's parent(s).- Parameters:
env
- the environmentkey
- the OSM key- Returns:
- first non-null value of the key
key
from the object's parent(s)
-
parent_tags
public static List<String> parent_tags(Environment env, String key)
Gets a list of all non-null values of the keykey
from the object's parent(s). The values are sorted according toAlphanumComparator
.- Parameters:
env
- the environmentkey
- the OSM key- Returns:
- a list of non-null values of the key
key
from the object's parent(s)
-
child_tag
public static String child_tag(Environment env, String key)
Gets the value of the keykey
from the object's child.- Parameters:
env
- the environmentkey
- the OSM key- Returns:
- the value of the key
key
from the object's child, ornull
if there is no child
-
parent_osm_id
public static Long parent_osm_id(Environment env)
Returns the OSM id of the object's parent.Parent must be matched by child selector.
- Parameters:
env
- the environment- Returns:
- the OSM id of the object's parent, if available, or
null
- See Also:
PrimitiveId.getUniqueId()
-
gpx_distance
public static double gpx_distance(Environment env)
Returns the lowest distance between the OSM object and a GPX point- Parameters:
env
- the environment- Returns:
- the distance between the object and the closest gpx point or
Double.MAX_VALUE
- Since:
- 14802
-
has_tag_key
public static boolean has_tag_key(Environment env, String key)
Determines whether the object has a tag with the given key.- Parameters:
env
- the environmentkey
- the OSM key- Returns:
true
if the object has a tag with the given key,false
otherwise
-
index
public static Float index(Environment env)
Returns the index of node in parent way or member in parent relation.- Parameters:
env
- the environment- Returns:
- the index as float. Starts at 1
-
sort
public static List<String> sort(Environment ignored, String... sortables)
Sort an array of strings- Parameters:
ignored
- The environment (ignored)sortables
- The array to sort- Returns:
- The sorted list
- Since:
- 15279
-
sort_list
public static List<String> sort_list(List<String> sortables)
Sort a list of strings- Parameters:
sortables
- The list to sort- Returns:
- The sorted list
- Since:
- 15279
-
uniq
public static List<String> uniq(Environment ignored, String... values)
Get unique values- Parameters:
ignored
- The environment (ignored)values
- A list of values that may have duplicates- Returns:
- A list with no duplicates
- Since:
- 15323
-
uniq_list
public static List<String> uniq_list(List<String> values)
Get unique values- Parameters:
values
- A list of values that may have duplicates- Returns:
- A list with no duplicates
- Since:
- 15323
-
role
public static String role(Environment env)
Returns the role of current object in parent relation, or role of child if current object is a relation.- Parameters:
env
- the environment- Returns:
- role of current object in parent relation, or role of child if current object is a relation
- See Also:
Environment.getRole()
-
count_roles
public static int count_roles(Environment env, String... roles)
Returns the number of primitives in a relation with the specified roles.- Parameters:
env
- the environmentroles
- The roles to count in the relation- Returns:
- The number of relation members with the specified role
- Since:
- 15196
-
areasize
public static Float areasize(Environment env)
Returns the area of a closed way or multipolygon in square meters ornull
.- Parameters:
env
- the environment- Returns:
- the area of a closed way or multipolygon in square meters or
null
- See Also:
Geometry.computeArea(IPrimitive)
-
waylength
public static Float waylength(Environment env)
Returns the length of the way in metres ornull
.- Parameters:
env
- the environment- Returns:
- the length of the way in metres or
null
. - See Also:
Way.getLength()
-
not
public static boolean not(boolean b)
Function associated to the logical "!" operator.- Parameters:
b
- boolean value- Returns:
true
if!b
-
greater_equal
public static boolean greater_equal(float a, float b)
Function associated to the logical ">=" operator.- Parameters:
a
- first valueb
- second value- Returns:
true
ifa >= b
-
less_equal
public static boolean less_equal(float a, float b)
Function associated to the logical "<=" operator.- Parameters:
a
- first valueb
- second value- Returns:
true
ifa <= b
-
greater
public static boolean greater(float a, float b)
Function associated to the logical ">" operator.- Parameters:
a
- first valueb
- second value- Returns:
true
ifa > b
-
less
public static boolean less(float a, float b)
Function associated to the logical "<" operator.- Parameters:
a
- first valueb
- second value- Returns:
true
ifa < b
-
degree_to_radians
public static double degree_to_radians(double degree)
Converts an angle in degrees to radians.- Parameters:
degree
- the angle in degrees- Returns:
- the angle in radians
- See Also:
Math.toRadians(double)
-
cardinal_to_radians
public static Double cardinal_to_radians(String cardinal)
Converts an angle diven in cardinal directions to radians. The following values are supported:n
,north
,ne
,northeast
,e
,east
,se
,southeast
,s
,south
,sw
,southwest
,w
,west
,nw
,northwest
.- Parameters:
cardinal
- the angle in cardinal directions.- Returns:
- the angle in radians
- See Also:
RotationAngle.parseCardinalRotation(String)
-
equal
public static boolean equal(Object a, Object b)
Determines if the objectsa
andb
are equal.- Parameters:
a
- First objectb
- Second object- Returns:
true
if objects are equal,false
otherwise- See Also:
Object.equals(Object)
-
not_equal
public static boolean not_equal(Object a, Object b)
Determines if the objectsa
andb
are not equal.- Parameters:
a
- First objectb
- Second object- Returns:
false
if objects are equal,true
otherwise- See Also:
Object.equals(Object)
-
JOSM_search
public static Boolean JOSM_search(Environment env, String searchStr)
Determines whether the JOSM search withsearchStr
applies to the object.- Parameters:
env
- the environmentsearchStr
- the search string- Returns:
true
if the JOSM search withsearchStr
applies to the object- See Also:
SearchCompiler
-
JOSM_pref
public static String JOSM_pref(Environment env, String key, String def)
Obtains the JOSM'keyPreferences
string for keykey
, and defaults todef
if that is null. If the default value can be converted to aColor
, theNamedColorProperty
is retrieved as string.- Parameters:
env
- the environmentkey
- Key in JOSM preferencedef
- Default value- Returns:
- value for key, or default value if not found
-
regexp_test
public static boolean regexp_test(String pattern, String target)
Tests if stringtarget
matches patternpattern
- Parameters:
pattern
- The regex expressiontarget
- The character sequence to be matched- Returns:
true
if, and only if, the entire region sequence matches the pattern- Since:
- 5699
- See Also:
Pattern.matches(String, CharSequence)
-
regexp_test
public static boolean regexp_test(String pattern, String target, String flags)
Tests if stringtarget
matches patternpattern
- Parameters:
pattern
- The regex expressiontarget
- The character sequence to be matchedflags
- a string that may contain "i" (case insensitive), "m" (multiline) and "s" ("dot all")- Returns:
true
if, and only if, the entire region sequence matches the pattern- Since:
- 5699
- See Also:
Pattern.CASE_INSENSITIVE
,Pattern.DOTALL
,Pattern.MULTILINE
-
regexp_match
public 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. The first element (index 0) is the complete match (i.e. string). Further elements correspond to the bracketed parts of the regular expression.- Parameters:
pattern
- The regex expressiontarget
- The character sequence to be matchedflags
- a string that may contain "i" (case insensitive), "m" (multiline) and "s" ("dot all")- Returns:
- a list of capture groups if
Matcher.matches()
, ornull
. - Since:
- 5701
- See Also:
Pattern.CASE_INSENSITIVE
,Pattern.DOTALL
,Pattern.MULTILINE
-
regexp_match
public 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. The first element (index 0) is the complete match (i.e. string). Further elements correspond to the bracketed parts of the regular expression.- Parameters:
pattern
- The regex expressiontarget
- The character sequence to be matched- Returns:
- a list of capture groups if
Matcher.matches()
, ornull
. - Since:
- 5701
-
osm_id
public static long osm_id(Environment env)
Returns the OSM id of the current object.- Parameters:
env
- the environment- Returns:
- the OSM id of the current object
- See Also:
PrimitiveId.getUniqueId()
-
osm_user_name
public static String osm_user_name(Environment env)
Returns the OSM user name who last touched the current object.- Parameters:
env
- the environment- Returns:
- the OSM user name who last touched the current object
- Since:
- 15246
- See Also:
IPrimitive.getUser()
-
osm_user_id
public static long osm_user_id(Environment env)
Returns the OSM user id who last touched the current object.- Parameters:
env
- the environment- Returns:
- the OSM user id who last touched the current object
- Since:
- 15246
- See Also:
IPrimitive.getUser()
-
osm_version
public static int osm_version(Environment env)
Returns the version number of the current object.- Parameters:
env
- the environment- Returns:
- the version number of the current object
- Since:
- 15246
- See Also:
IPrimitive.getVersion()
-
osm_changeset_id
public static int osm_changeset_id(Environment env)
Returns the id of the changeset the current object was last uploaded to.- Parameters:
env
- the environment- Returns:
- the id of the changeset the current object was last uploaded to
- Since:
- 15246
- See Also:
IPrimitive.getChangesetId()
-
osm_timestamp
public static int osm_timestamp(Environment env)
Returns the time of last modification to the current object, as timestamp.- Parameters:
env
- the environment- Returns:
- the time of last modification to the current object, as timestamp
- Since:
- 15246
- See Also:
IPrimitive.getRawTimestamp()
-
tr
public static String tr(Environment ignored, String... args)
Translates some text for the current locale. The first argument is the text to translate, and the subsequent arguments are parameters for the string indicated by{0}
,{1}
, …- Parameters:
ignored
- The environment (ignored)args
- arguments- Returns:
- the translated string
-
substring
public static String substring(String s, float begin)
Returns the substring ofs
starting at indexbegin
(inclusive, 0-indexed).- Parameters:
s
- The base stringbegin
- The start index- Returns:
- the substring
- See Also:
String.substring(int)
-
substring
public static String substring(String s, float begin, float end)
Returns the substring ofs
starting at indexbegin
(inclusive) and ending at indexend
, (exclusive, 0-indexed).- Parameters:
s
- The base stringbegin
- The start indexend
- The end index- Returns:
- the substring
- See Also:
String.substring(int, int)
-
replace
public static String replace(String s, String target, String replacement)
Replaces ins
every target} substring byreplacement
.- Parameters:
s
- The source stringtarget
- The sequence of char values to be replacedreplacement
- The replacement sequence of char values- Returns:
- The resulting string
- See Also:
String.replace(CharSequence, CharSequence)
-
upper
public static String upper(String s)
Converts strings
to uppercase.- Parameters:
s
- The source string- Returns:
- The resulting string
- Since:
- 11756
- See Also:
String.toUpperCase(Locale)
-
lower
public static String lower(String s)
Converts strings
to lowercase.- Parameters:
s
- The source string- Returns:
- The resulting string
- Since:
- 11756
- See Also:
String.toLowerCase(Locale)
-
title
public 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".- Parameters:
str
- The source string- Returns:
- The resulting string
- Since:
- 17613
- See Also:
Character.toTitleCase(char)
-
trim
public static String trim(String s)
Trim whitespaces from the strings
.- Parameters:
s
- The source string- Returns:
- The resulting string
- Since:
- 11756
- See Also:
Utils.strip(java.lang.String)
-
trim_list
public static List<String> trim_list(List<String> strings)
Trim whitespaces from the stringsstrings
.- Parameters:
strings
- The list of strings to strip- Returns:
- The resulting string
- Since:
- 15591
- See Also:
Utils.strip(java.lang.String)
-
is_similar
public 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.- Parameters:
string1
- first string to comparestring2
- second string to compare- Returns:
- true if the normalized strings are different but only a "little bit"
- Since:
- 14371
- See Also:
Utils.isSimilar(java.lang.String, java.lang.String)
-
URL_decode
public static String URL_decode(String s)
Percent-decode a string. (See https://en.wikipedia.org/wiki/Percent-encoding) This is especially useful for wikipedia titles- Parameters:
s
- url-encoded string- Returns:
- the decoded string, or original in case of an error
- Since:
- 11756
-
URL_encode
public static String URL_encode(String s)
Percent-encode a string. (See https://en.wikipedia.org/wiki/Percent-encoding) This is especially useful for data urls, e.g.concat("data:image/svg+xml,", URL_encode("<svg>...</svg>"));
- Parameters:
s
- arbitrary string- Returns:
- the encoded string
-
XML_encode
public static String XML_encode(String s)
XML-encode a string. Escapes special characters in xml. Alternative to using <![CDATA[ ... ]]> blocks.- Parameters:
s
- arbitrary string- Returns:
- the encoded string
-
CRC32_checksum
public static long CRC32_checksum(String s)
Calculates the CRC32 checksum from a string (based on RFC 1952).- Parameters:
s
- the string- Returns:
- long value from 0 to 2^32-1
-
is_right_hand_traffic
public static boolean is_right_hand_traffic(Environment env)
check if there is right-hand traffic at the current location- Parameters:
env
- the environment- Returns:
- true if there is right-hand traffic
- Since:
- 7193
-
is_clockwise
public static boolean is_clockwise(Environment env)
Determines whether the way isclosed and oriented clockwise
, or non-closed and the1st, 2nd and last node are in clockwise order
.- Parameters:
env
- the environment- Returns:
- true if the way is closed and oriented clockwise
-
is_anticlockwise
public static boolean is_anticlockwise(Environment env)
Determines whether the way isclosed and oriented anticlockwise
, or non-closed and the1st, 2nd and last node are in anticlockwise order
.- Parameters:
env
- the environment- Returns:
- true if the way is closed and oriented clockwise
-
print
public static Object print(Object o)
Prints the object to the command line (for debugging purpose).- Parameters:
o
- the object- Returns:
- the same object, unchanged
-
println
public static Object println(Object o)
Prints the object to the command line, with new line at the end (for debugging purpose).- Parameters:
o
- the object- Returns:
- the same object, unchanged
-
number_of_tags
public static int number_of_tags(Environment env)
Get the number of tags for the current primitive.- Parameters:
env
- the environment- Returns:
- number of tags
-
setting
public static Object setting(Environment env, String key)
Get value of a setting.- Parameters:
env
- the environmentkey
- setting key (given as layer identifier, e.g. setting::mykey {...})- Returns:
- the value of the setting (calculated when the style is loaded)
-
center
public static LatLon center(Environment env)
Returns the center of the environment OSM primitive.- Parameters:
env
- the environment- Returns:
- the center of the environment OSM primitive
- Since:
- 11247
-
inside
public static boolean inside(Environment env, String codes)
Determines if the object is inside territories matching given ISO3166 codes.- Parameters:
env
- the environmentcodes
- comma-separated list of ISO3166-1-alpha2 or ISO3166-2 country/subdivision codes- Returns:
true
if the object is inside territory matching given ISO3166 codes- Since:
- 11247
-
outside
public static boolean outside(Environment env, String codes)
Determines if the object is outside territories matching given ISO3166 codes.- Parameters:
env
- the environmentcodes
- comma-separated list of ISO3166-1-alpha2 or ISO3166-2 country/subdivision codes- Returns:
true
if the object is outside territory matching given ISO3166 codes- Since:
- 11247
-
at
public static boolean at(Environment env, double lat, double lon)
Determines if the object centroid lies at given lat/lon coordinates.- Parameters:
env
- the environmentlat
- latitude, i.e., the north-south position in degreeslon
- longitude, i.e., the east-west position in degrees- Returns:
true
if the object centroid lies at given lat/lon coordinates- Since:
- 12514
-
to_boolean
public static boolean to_boolean(String value)
Parses the string argument as a boolean.- Parameters:
value
- theString
containing the boolean representation to be parsed- Returns:
- the boolean represented by the string argument
- Since:
- 16110
- See Also:
Boolean.parseBoolean(java.lang.String)
-
to_byte
public static byte to_byte(String value)
Parses the string argument as a byte.- Parameters:
value
- theString
containing the byte representation to be parsed- Returns:
- the byte represented by the string argument
- Since:
- 16110
- See Also:
Byte.parseByte(java.lang.String, int)
-
to_short
public static short to_short(String value)
Parses the string argument as a short.- Parameters:
value
- theString
containing the short representation to be parsed- Returns:
- the short represented by the string argument
- Since:
- 16110
- See Also:
Short.parseShort(java.lang.String, int)
-
to_int
public static int to_int(String value)
Parses the string argument as an int.- Parameters:
value
- theString
containing the int representation to be parsed- Returns:
- the int represented by the string argument
- Since:
- 16110
- See Also:
Integer.parseInt(java.lang.String, int)
-
to_long
public static long to_long(String value)
Parses the string argument as a long.- Parameters:
value
- theString
containing the long representation to be parsed- Returns:
- the long represented by the string argument
- Since:
- 16110
- See Also:
Long.parseLong(java.lang.String, int)
-
to_float
public static float to_float(String value)
Parses the string argument as a float.- Parameters:
value
- theString
containing the float representation to be parsed- Returns:
- the float represented by the string argument
- Since:
- 16110
- See Also:
Float.parseFloat(java.lang.String)
-
to_double
public static double to_double(String value)
Parses the string argument as a double.- Parameters:
value
- theString
containing the double representation to be parsed- Returns:
- the double represented by the string argument
- Since:
- 16110
- See Also:
Double.parseDouble(java.lang.String)
-
-