Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public abstract class BaseExpression<T extends BaseExpression> {
"*", "mul",
"/", "div",
"+", "add",
"-", "sub"
"-", "sub",
"^", "pow"
);
public static final Map<String, String> PREDEFINED_VARS = ObjectUtils.asMap(
"width", "w",
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}