- Timestamp:
- 2021-04-13T21:12:08+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r17764 r17769 55 55 } 56 56 57 static Factory ofNumberVarArgs(DoubleBinaryOperator operator) { 58 return args -> env -> args.stream() 57 static Factory ofNumberVarArgs(double identity, DoubleUnaryOperator unaryOperator, DoubleBinaryOperator operator) { 58 return args -> env -> args.isEmpty() 59 ? identity 60 : args.size() == 1 61 ? unaryOperator.applyAsDouble(Cascade.convertTo(args.get(0).evaluate(env), Double.class)) 62 : args.stream() 59 63 .map(arg -> Cascade.convertTo(arg.evaluate(env), Double.class)) 60 64 .filter(Objects::nonNull) … … 162 166 FACTORY_MAP.put("count_roles", Factory.ofStringVarargs(Functions::count_roles)); 163 167 FACTORY_MAP.put("degree_to_radians", Factory.of(Functions::degree_to_radians)); 164 FACTORY_MAP.put("divided_by", Factory.ofNumberVarArgs( Functions::divided_by));168 FACTORY_MAP.put("divided_by", Factory.ofNumberVarArgs(1.0, DoubleUnaryOperator.identity(), Functions::divided_by)); 165 169 FACTORY_MAP.put("equal", Factory.of(Object.class, Object.class, Functions::equal)); 166 170 FACTORY_MAP.put("eval", Factory.of(Object.class, Functions::eval)); … … 189 193 FACTORY_MAP.put("log", Factory.of(Math::log)); 190 194 FACTORY_MAP.put("lower", Factory.of(String.class, Functions::lower)); 191 FACTORY_MAP.put("minus", Factory.ofNumberVarArgs( Functions::minus));195 FACTORY_MAP.put("minus", Factory.ofNumberVarArgs(0.0, v -> -v, Functions::minus)); 192 196 FACTORY_MAP.put("mod", Factory.of(float.class, float.class, Functions::mod)); 193 197 FACTORY_MAP.put("not", Factory.of(boolean.class, Functions::not)); … … 204 208 FACTORY_MAP.put("parent_tag", Factory.ofEnv(String.class, Functions::parent_tag)); 205 209 FACTORY_MAP.put("parent_tags", Factory.ofEnv(String.class, Functions::parent_tags)); 206 FACTORY_MAP.put("plus", Factory.ofNumberVarArgs( Functions::plus));210 FACTORY_MAP.put("plus", Factory.ofNumberVarArgs(0.0, DoubleUnaryOperator.identity(), Functions::plus)); 207 211 FACTORY_MAP.put("print", Factory.of(Object.class, Functions::print)); 208 212 FACTORY_MAP.put("println", Factory.of(Object.class, Functions::println)); … … 229 233 FACTORY_MAP.put("tan", Factory.of(Math::tan)); 230 234 FACTORY_MAP.put("tanh", Factory.of(Math::tanh)); 231 FACTORY_MAP.put("times", Factory.ofNumberVarArgs( Functions::times));235 FACTORY_MAP.put("times", Factory.ofNumberVarArgs(1.0, DoubleUnaryOperator.identity(), Functions::times)); 232 236 FACTORY_MAP.put("title", Factory.of(String.class, Functions::title)); 233 237 FACTORY_MAP.put("to_boolean", Factory.of(String.class, Functions::to_boolean));
Note:
See TracChangeset
for help on using the changeset viewer.