Changeset 16259 in josm for trunk/src/org
- Timestamp:
- 2020-04-11T17:36:58+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java
r15893 r16259 18 18 import java.util.Objects; 19 19 import java.util.Optional; 20 import java.util.function.BiFunction; 21 import java.util.function.Function; 20 22 import java.util.function.Predicate; 21 23 import java.util.function.Supplier; … … 402 404 } 403 405 406 /** 407 * First applies {@code mapper} to both sides and then applies {@code operator} on the two results. 408 * @param mapper the mapping function 409 * @param operator the operator 410 * @param <T> the type of the intermediate result 411 * @param <U> the type of the result 412 * @return {@code operator.apply(mapper.apply(lhs), mapper.apply(rhs))} 413 */ 414 public <T, U> U map(Function<Match, T> mapper, BiFunction<T, T, U> operator) { 415 return operator.apply(mapper.apply(lhs), mapper.apply(rhs)); 416 } 417 404 418 protected static String parenthesis(Match m) { 405 419 return '(' + m.toString() + ')'; … … 562 576 @Override 563 577 public String toString() { 564 return (lhs instanceof AbstractBinaryMatch && !(lhs instanceof And) ? parenthesis(lhs) : lhs) + " && " 565 + (rhs instanceof AbstractBinaryMatch && !(rhs instanceof And) ? parenthesis(rhs) : rhs); 578 return map(m -> m instanceof AbstractBinaryMatch && !(m instanceof And) ? parenthesis(m) : m, (s1, s2) -> s1 + " && " + s2); 566 579 } 567 580 } … … 592 605 @Override 593 606 public String toString() { 594 return (lhs instanceof AbstractBinaryMatch && !(lhs instanceof Or) ? parenthesis(lhs) : lhs) + " || " 595 + (rhs instanceof AbstractBinaryMatch && !(rhs instanceof Or) ? parenthesis(rhs) : rhs); 607 return map(m -> m instanceof AbstractBinaryMatch && !(m instanceof Or) ? parenthesis(m) : m, (s1, s2) -> s1 + " || " + s2); 596 608 } 597 609 } … … 622 634 @Override 623 635 public String toString() { 624 return (lhs instanceof AbstractBinaryMatch && !(lhs instanceof Xor) ? parenthesis(lhs) : lhs) + " ^ " 625 + (rhs instanceof AbstractBinaryMatch && !(rhs instanceof Xor) ? parenthesis(rhs) : rhs); 636 return map(m -> m instanceof AbstractBinaryMatch && !(m instanceof Xor) ? parenthesis(m) : m, (s1, s2) -> s1 + " ^ " + s2); 626 637 } 627 638 }
Note:
See TracChangeset
for help on using the changeset viewer.