diff --git a/cloudinary-core/src/main/java/com/cloudinary/transformation/BaseExpression.java b/cloudinary-core/src/main/java/com/cloudinary/transformation/BaseExpression.java index 993be1e7..cd5f4433 100644 --- a/cloudinary-core/src/main/java/com/cloudinary/transformation/BaseExpression.java +++ b/cloudinary-core/src/main/java/com/cloudinary/transformation/BaseExpression.java @@ -26,7 +26,8 @@ public abstract class BaseExpression { "*", "mul", "/", "div", "+", "add", - "-", "sub" + "-", "sub", + "^", "pow" ); public static final Map PREDEFINED_VARS = ObjectUtils.asMap( "width", "w", @@ -245,6 +246,29 @@ public T sub() { return (T) this; } + /** + * Utility shortcut method which invokes on this Expression instance {@link #pow()} method, takes its result and + * invokes {@link #value(Object)} method on it. Effectively, invocation of this shortcut results in + * "to the power of value" sub-expression added to the end of current expression instance. + * + * @param value argument for {@link #value(Object)} call + * @return result of {@link #value(Object)} call + */ + public T pow(Object value) { + return (T) pow().value(value); + } + + /** + * Adds "to the power of" sub-expression to the end of the list of already present sub-expressions in this + * expression instance. + * + * @return this expression instance + */ + public T pow() { + expressions.add("pow"); + return (T) this; + } + public T value(Object value) { expressions.add(String.valueOf(value)); return (T) this; diff --git a/cloudinary-core/src/test/java/com/cloudinary/TransformationTest.java b/cloudinary-core/src/test/java/com/cloudinary/TransformationTest.java index 9e41deef..18356791 100644 --- a/cloudinary-core/src/test/java/com/cloudinary/TransformationTest.java +++ b/cloudinary-core/src/test/java/com/cloudinary/TransformationTest.java @@ -210,4 +210,12 @@ public void testSupportStringInterpolation() { ).fontFamily("Arial").fontSize(18)); assertEquals("c_scale,l_text:Arial_18:$(start)Hello%20$(name)$(ext)%252C%20%24%28no%20%29%20%24%28%20no%29$(end)", t.generate()); } + + @Test + public void testShouldSupportPowOperator() { + Transformation t = new Transformation() + .variables(variable("$small", 150), variable("$big", "$small ^ 1.5")); + + assertEquals("$small_150,$big_$small_pow_1.5", t.generate()); + } } \ No newline at end of file