Changeset 7530 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2014-09-12T16:11:41+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r7509 r7530 28 28 import org.openstreetmap.josm.data.osm.Node; 29 29 import org.openstreetmap.josm.data.osm.OsmPrimitive; 30 import org.openstreetmap.josm.data.osm.Way; 30 31 import org.openstreetmap.josm.gui.mappaint.Cascade; 31 32 import org.openstreetmap.josm.gui.mappaint.Environment; … … 120 121 } 121 122 123 /** 124 * Function associated to the numeric "+" operator. 125 * @param args arguments 126 * @return Sum of arguments 127 */ 122 128 public static float plus(float... args) { 123 129 float res = 0; … … 128 134 } 129 135 136 /** 137 * Function associated to the numeric "-" operator. 138 * @param args arguments 139 * @return Substraction of arguments 140 */ 130 141 public static Float minus(float... args) { 131 142 if (args.length == 0) { … … 142 153 } 143 154 155 /** 156 * Function associated to the numeric "*" operator. 157 * @param args arguments 158 * @return Multiplication of arguments 159 */ 144 160 public static float times(float... args) { 145 161 float res = 1; … … 150 166 } 151 167 168 /** 169 * Function associated to the numeric "/" operator. 170 * @param args arguments 171 * @return Division of arguments 172 */ 152 173 public static Float divided_by(float... args) { 153 174 if (args.length == 0) { … … 166 187 /** 167 188 * Creates a list of values, e.g., for the {@code dashes} property. 189 * @param args The values to put in a list 190 * @return list of values 168 191 * @see Arrays#asList(Object[]) 169 192 */ … … 183 206 /** 184 207 * Returns the first non-null object. The name originates from the {@code COALESCE} SQL function. 208 * @param args arguments 209 * @return the first non-null object 185 210 * @deprecated Deprecated in favour of {@link #any(Object...)} from the MapCSS standard. 186 211 */ … … 194 219 * Returns the first non-null object. 195 220 * The name originates from <a href="http://wiki.openstreetmap.org/wiki/MapCSS/0.2/eval">MapCSS standard</a>. 221 * @param args arguments 222 * @return the first non-null object 196 223 * @see #coalesce(Object...) 197 224 * @see Utils#firstNonNull(Object[]) … … 204 231 /** 205 232 * Get the {@code n}th element of the list {@code lst} (counting starts at 0). 233 * @param lst list 234 * @param n index 235 * @return {@code n}th element of the list, or {@code null} if index out of range 206 236 * @since 5699 207 237 */ … … 216 246 /** 217 247 * Splits string {@code toSplit} at occurrences of the separator string {@code sep} and returns a list of matches. 248 * @param sep separator string 249 * @param toSplit string to split 250 * @return list of matches 218 251 * @see String#split(String) 219 252 * @since 5699 … … 225 258 /** 226 259 * Creates a color value with the specified amounts of {@code r}ed, {@code g}reen, {@code b}lue (arguments from 0.0 to 1.0) 260 * @param r the red component 261 * @param g the green component 262 * @param b the blue component 263 * @return color matching the given components 227 264 * @see Color#Color(float, float, float) 228 265 */ … … 235 272 } 236 273 274 /** 275 * Creates a color value with the specified amounts of {@code r}ed, {@code g}reen, {@code b}lue, {@code alpha} (arguments from 0.0 to 1.0) 276 * @param r the red component 277 * @param g the green component 278 * @param b the blue component 279 * @param alpha the alpha component 280 * @return color matching the given components 281 * @see Color#Color(float, float, float, float) 282 */ 237 283 public static Color rgba(float r, float g, float b, float alpha) { 238 284 try { … … 260 306 /** 261 307 * Creates a color value from an HTML notation, i.e., {@code #rrggbb}. 308 * @param html HTML notation 309 * @return color matching the given notation 262 310 */ 263 311 public static Color html2color(String html) { … … 267 315 /** 268 316 * Computes the HTML notation ({@code #rrggbb}) for a color value). 317 * @param c color 318 * @return HTML notation matching the given color 269 319 */ 270 320 public static String color2html(Color c) { … … 274 324 /** 275 325 * Get the value of the red color channel in the rgb color model 326 * @param c color 276 327 * @return the red color channel in the range [0;1] 277 328 * @see java.awt.Color#getRed() … … 283 334 /** 284 335 * Get the value of the green color channel in the rgb color model 336 * @param c color 285 337 * @return the green color channel in the range [0;1] 286 338 * @see java.awt.Color#getGreen() … … 292 344 /** 293 345 * Get the value of the blue color channel in the rgb color model 346 * @param c color 294 347 * @return the blue color channel in the range [0;1] 295 348 * @see java.awt.Color#getBlue() … … 301 354 /** 302 355 * Get the value of the alpha channel in the rgba color model 356 * @param c color 303 357 * @return the alpha channel in the range [0;1] 304 358 * @see java.awt.Color#getAlpha() … … 310 364 /** 311 365 * Assembles the strings to one. 366 * @param args arguments 367 * @return assembled string 312 368 * @see Utils#join 313 369 */ … … 319 375 /** 320 376 * Assembles the strings to one, where the first entry is used as separator. 377 * @param args arguments. First one is used as separator 378 * @return assembled string 321 379 * @see Utils#join 322 380 */ … … 328 386 /** 329 387 * Returns the value of the property {@code key}, e.g., {@code prop("width")}. 388 * @param env the environment 389 * @param key the property key 390 * @return the property value 330 391 */ 331 392 public static Object prop(final Environment env, String key) { … … 335 396 /** 336 397 * Returns the value of the property {@code key} from layer {@code layer}. 398 * @param env the environment 399 * @param key the property key 400 * @return the property value 337 401 */ 338 402 public static Object prop(final Environment env, String key, String layer) { … … 342 406 /** 343 407 * Determines whether property {@code key} is set. 408 * @param env the environment 409 * @param key the property key 410 * @return {@code true} if the property is set, {@code false} otherwise 344 411 */ 345 412 public static Boolean is_prop_set(final Environment env, String key) { … … 349 416 /** 350 417 * Determines whether property {@code key} is set on layer {@code layer}. 418 * @param env the environment 419 * @param key the property key 420 * @return {@code true} if the property is set, {@code false} otherwise 351 421 */ 352 422 public static Boolean is_prop_set(final Environment env, String key, String layer) { … … 356 426 /** 357 427 * Gets the value of the key {@code key} from the object in question. 428 * @param env the environment 429 * @param key the OSM key 430 * @return the value for given key 358 431 */ 359 432 public static String tag(final Environment env, String key) { … … 363 436 /** 364 437 * Gets the first non-null value of the key {@code key} from the object's parent(s). 438 * @param env the environment 439 * @param key the OSM key 440 * @return first non-null value of the key {@code key} from the object's parent(s) 365 441 */ 366 442 public static String parent_tag(final Environment env, String key) { … … 380 456 } 381 457 458 /** 459 * Gets the value of the key {@code key} from the object's child. 460 * @param env the environment 461 * @param key the OSM key 462 * @return the value of the key {@code key} from the object's child, or {@code null} if there is no child 463 */ 382 464 public static String child_tag(final Environment env, String key) { 383 465 return env.child == null ? null : env.child.get(key); … … 386 468 /** 387 469 * Determines whether the object has a tag with the given key. 470 * @param env the environment 471 * @param key the OSM key 472 * @return {@code true} if the object has a tag with the given key, {@code false} otherwise 388 473 */ 389 474 public static boolean has_tag_key(final Environment env, String key) { … … 393 478 /** 394 479 * Returns the index of node in parent way or member in parent relation. 480 * @param env the environment 481 * @return the index as float. Starts at 1 395 482 */ 396 483 public static Float index(final Environment env) { … … 401 488 } 402 489 490 /** 491 * Returns the role of current object in parent relation, or role of child if current object is a relation. 492 * @param env the environment 493 * @return role of current object in parent relation, or role of child if current object is a relation 494 * @see Environment#getRole() 495 */ 403 496 public static String role(final Environment env) { 404 497 return env.getRole(); 405 498 } 406 499 500 /** 501 * Function associated to the logical "!" operator. 502 * @param b boolean value 503 * @return {@code true} if {@code !b} 504 */ 407 505 public static boolean not(boolean b) { 408 506 return !b; 409 507 } 410 508 509 /** 510 * Function associated to the logical ">=" operator. 511 * @param a first value 512 * @param b second value 513 * @return {@code true} if {@code a >= b} 514 */ 411 515 public static boolean greater_equal(float a, float b) { 412 516 return a >= b; 413 517 } 414 518 519 /** 520 * Function associated to the logical "<=" operator. 521 * @param a first value 522 * @param b second value 523 * @return {@code true} if {@code a <= b} 524 */ 415 525 public static boolean less_equal(float a, float b) { 416 526 return a <= b; 417 527 } 418 528 529 /** 530 * Function associated to the logical ">" operator. 531 * @param a first value 532 * @param b second value 533 * @return {@code true} if {@code a > b} 534 */ 419 535 public static boolean greater(float a, float b) { 420 536 return a > b; 421 537 } 422 538 539 /** 540 * Function associated to the logical "<" operator. 541 * @param a first value 542 * @param b second value 543 * @return {@code true} if {@code a < b} 544 */ 423 545 public static boolean less(float a, float b) { 424 546 return a < b; … … 427 549 /** 428 550 * Determines if the objects {@code a} and {@code b} are equal. 551 * @param a First object 552 * @param b Second object 553 * @return {@code true} if objects are equal, {@code false} otherwise 429 554 * @see Object#equals(Object) 430 555 */ … … 437 562 /** 438 563 * Determines whether the JOSM search with {@code searchStr} applies to the object. 564 * @param env the environment 565 * @param searchStr the search string 566 * @return {@code true} if the JOSM search with {@code searchStr} applies to the object 567 * @see SearchCompiler 439 568 */ 440 569 public static Boolean JOSM_search(final Environment env, String searchStr) { … … 451 580 * Obtains the JOSM'key {@link org.openstreetmap.josm.data.Preferences} string for key {@code key}, 452 581 * and defaults to {@code def} if that is null. 582 * @param key Key in JOSM preference 583 * @param def Default value 584 * @return value for key, or default value if not found 453 585 * @see org.openstreetmap.josm.data.Preferences#get(String, String) 454 586 */ … … 460 592 /** 461 593 * Tests if string {@code target} matches pattern {@code pattern} 594 * @param pattern The regex expression 595 * @param target The character sequence to be matched 596 * @return {@code true} if, and only if, the entire region sequence matches the pattern 462 597 * @see Pattern#matches(String, CharSequence) 463 598 * @since 5699 … … 469 604 /** 470 605 * Tests if string {@code target} matches pattern {@code pattern} 606 * @param pattern The regex expression 607 * @param target The character sequence to be matched 471 608 * @param flags a string that may contain "i" (case insensitive), "m" (multiline) and "s" ("dot all") 609 * @return {@code true} if, and only if, the entire region sequence matches the pattern 610 * @see Pattern#CASE_INSENSITIVE 611 * @see Pattern#DOTALL 612 * @see Pattern#MULTILINE 472 613 * @since 5699 473 614 */ … … 490 631 * The first element (index 0) is the complete match (i.e. string). 491 632 * Further elements correspond to the bracketed parts of the regular expression. 633 * @param pattern The regex expression 634 * @param target The character sequence to be matched 492 635 * @param flags a string that may contain "i" (case insensitive), "m" (multiline) and "s" ("dot all") 636 * @return a list of capture groups if {@link Matcher#matches()}, or {@code null}. 637 * @see Pattern#CASE_INSENSITIVE 638 * @see Pattern#DOTALL 639 * @see Pattern#MULTILINE 493 640 * @since 5701 494 641 */ … … 504 651 f |= Pattern.MULTILINE; 505 652 } 506 Matcher m = Pattern.compile(pattern, f).matcher(target); 507 return Utils.getMatches(m); 653 return Utils.getMatches(Pattern.compile(pattern, f).matcher(target)); 508 654 } 509 655 … … 512 658 * The first element (index 0) is the complete match (i.e. string). 513 659 * Further elements correspond to the bracketed parts of the regular expression. 660 * @param pattern The regex expression 661 * @param target The character sequence to be matched 662 * @return a list of capture groups if {@link Matcher#matches()}, or {@code null}. 514 663 * @since 5701 515 664 */ 516 665 public static List<String> regexp_match(String pattern, String target) { 517 Matcher m = Pattern.compile(pattern).matcher(target); 518 return Utils.getMatches(m); 666 return Utils.getMatches(Pattern.compile(pattern).matcher(target)); 519 667 } 520 668 521 669 /** 522 670 * Returns the OSM id of the current object. 671 * @param env the environment 672 * @return the OSM id of the current object 523 673 * @see OsmPrimitive#getUniqueId() 524 674 */ … … 529 679 /** 530 680 * Translates some text for the current locale. The first argument is the text to translate, 531 * and the subsequent arguments are parameters for the string indicated by {@code {0}}, {@code {1}}, … 681 * and the subsequent arguments are parameters for the string indicated by <code>{0}</code>, <code>{1}</code>, … 682 * @param args arguments 683 * @return the translated string 532 684 */ 533 685 @NullableArguments … … 564 716 /** 565 717 * Replaces in {@code s} every {@code} target} substring by {@code replacement}. 566 * * @see String#replace(CharSequence, CharSequence) 718 * @param s The source string 719 * @param target The sequence of char values to be replaced 720 * @param replacement The replacement sequence of char values 721 * @return The resulting string 722 * @see String#replace(CharSequence, CharSequence) 567 723 */ 568 724 public static String replace(String s, String target, String replacement) { … … 722 878 private Expression condition, firstOption, secondOption; 723 879 880 /** 881 * Constructs a new {@code CondOperator}. 882 * @param condition condition 883 * @param firstOption first option 884 * @param secondOption second option 885 */ 724 886 public CondOperator(Expression condition, Expression firstOption, Expression secondOption) { 725 887 this.condition = condition; … … 738 900 } 739 901 902 /** 903 * "And" logical operator. 904 */ 740 905 public static class AndOperator implements Expression { 741 906 742 907 private List<Expression> args; 743 908 909 /** 910 * Constructs a new {@code AndOperator}. 911 * @param args arguments 912 */ 744 913 public AndOperator(List<Expression> args) { 745 914 this.args = args; … … 758 927 } 759 928 929 /** 930 * "Or" logical operator. 931 */ 760 932 public static class OrOperator implements Expression { 761 933 762 934 private List<Expression> args; 763 935 936 /** 937 * Constructs a new {@code OrOperator}. 938 * @param args arguments 939 */ 764 940 public OrOperator(List<Expression> args) { 765 941 this.args = args; … … 779 955 780 956 /** 781 * Function to calculate the length of a string or list in a MapCSS eval 782 * expression. 957 * Function to calculate the length of a string or list in a MapCSS eval expression. 783 958 * 784 * Separate implementation to support overloading for different 785 * argument types. 959 * Separate implementation to support overloading for different argument types. 786 960 * 787 961 * The use for calculating the length of a list is deprecated, use … … 792 966 private Expression arg; 793 967 968 /** 969 * Constructs a new {@code LengthFunction}. 970 * @param args arguments 971 */ 794 972 public LengthFunction(Expression args) { 795 973 this.arg = args; … … 816 994 private final boolean computeMax; 817 995 996 /** 997 * Constructs a new {@code MinMaxFunction}. 998 * @param args arguments 999 * @param computeMax if {@code true}, compute max. If {@code false}, compute min 1000 */ 818 1001 public MinMaxFunction(final List<Expression> args, final boolean computeMax) { 819 1002 this.args = args; … … 860 1043 private final boolean needsEnvironment; 861 1044 1045 /** 1046 * Constructs a new {@code ParameterFunction}. 1047 */ 862 1048 public ParameterFunction(Method m, List<Expression> args, boolean needsEnvironment) { 863 1049 this.m = m; … … 914 1100 return b.toString(); 915 1101 } 916 917 1102 } 918 1103 … … 932 1117 private final Class<?> arrayComponentType; 933 1118 1119 /** 1120 * Constructs a new {@code ArrayFunction}. 1121 */ 934 1122 public ArrayFunction(Method m, List<Expression> args) { 935 1123 this.m = m; … … 964 1152 return result; 965 1153 } 1154 966 1155 @Override 967 1156 public String toString() { … … 976 1165 return b.toString(); 977 1166 } 978 979 1167 } 980 981 1168 }
Note:
See TracChangeset
for help on using the changeset viewer.