Questions Tagged With ivyscripthttps://answers.axonivy.com/tags/ivyscript/?type=rss&user=Genzer%20Hawkerquestions tagged <span class="tag">ivyscript</span>enFri, 29 Apr 2016 07:13:17 -0400Inconveniences when using inner classes in Ivy Scripthttps://answers.axonivy.com/questions/1756/inconveniences-when-using-inner-classes-in-ivy-script<p>Suppose I have two classes, each of them provides <code>Builder</code> API.</p> <pre><code>// This is in Ivy Script import example.Person.Builder; Builder errorPersonBuilder = new Person.Builder(); // this line generates a compilation error saying class Person.Builder not found. Builder workingPersonBuilder = new Builder(); // this works. </code></pre> <p>It is still OK if there is only one <code>Builder</code> inside the context. As soon as there is another:</p> <pre><code>// This is in Ivy Script import example.Person.Builder; import example.Company.Builder; // compilation error of collision, there are two classes named Builder. Builder workingPersonBuilder = new Builder(); // this works, see above. Builder anotherBuilder = new Builder(); // which builder? </code></pre> <p>If Ivy Script could supports the same as normal Java, we could do:</p> <pre><code>import example.Person.Builder; import example.Company.Builder; Person.Builder personBuilder = new Person.Builder(); Company.Builder companyBuilder = new Company.Builder(); </code></pre> <p>Should this be supported in Ivy Script?</p>Genzer HawkerFri, 29 Apr 2016 07:13:17 -0400https://answers.axonivy.com/questions/1756/inconveniences-when-using-inner-classes-in-ivy-scriptinner-classivyscriptList converted from an Enum array in Ivy Script doesn't work correctlyhttps://answers.axonivy.com/questions/1224/list-converted-from-an-enum-array-in-ivy-script-doesn-t-work-correctly<p>Today I found something looks like a bug in Ivy Script.</p> <p>In Ivy Script, I want to have a <code>List</code> of all the elements of an <code>enum</code>, say <code>WorkflowPriority</code>, I simply call <code>WorkflowPriority.values()</code>. However, the instance of <code>List</code> returned by the call doesn't work correctly, especially with operation <code>contains</code> and <code>remove</code>.</p> <p>Here are the tests that I made to check:</p> <p>(This is an Ivy Script snippet)</p> <pre><code>import org.junit.Assert; import com.genzerhawherk.bugs.Lists; import ch.ivyteam.ivy.workflow.WorkflowPriority; // Below are all failed tests Assert.assertTrue(WorkflowPriority.values().contains(WorkflowPriority.HIGH)); List&lt;WorkflowPriority&gt; withGenerics = WorkflowPriority.values(); Assert.assertTrue(withGenerics.contains(WorkflowPriority.HIGH)); List fromEnums = Lists.fromEnums(WorkflowPriority.class); Assert.assertTrue(fromEnums.contains(WorkflowPriority.HIGH)); List fromEnumVarargs = Lists.enumVarArgs(WorkflowPriority.HIGH, WorkflowPriority.EXCEPTION); Assert.assertTrue(fromEnumVarargs.contains(WorkflowPriority.HIGH)); // Below are all passed tests List listComprehensive = [WorkflowPriority.HIGH]; Assert.assertTrue(listComprehensive.contains(WorkflowPriority.HIGH)); List newPriorities = new List().addAll(WorkflowPriority.values()); Assert.assertTrue(newPriorities.contains(WorkflowPriority.HIGH)); List fromList = Lists.toArray([WorkflowPriority.HIGH]); Assert.assertTrue(fromList.contains(WorkflowPriority.HIGH)); List fromVarArgs = Lists.normalVarArgs(WorkflowPriority.HIGH); Assert.assertTrue(fromVarArgs.contains(WorkflowPriority.HIGH)); List&lt;WorkflowPriority&gt; manuallyConstructed = new List&lt;WorkflowPriority&gt;(); manuallyConstructed.add(WorkflowPriority.HIGH); Assert.assertTrue(manuallyConstructed.contains(WorkflowPriority.HIGH)); </code></pre> <p><strong>The bug particularly relates to converting <code>&lt;T extends Enum&lt;T&gt;&gt; T[]</code> into a <code>List&lt;T&gt;</code></strong></p> <p>Below is the class <code>Lists</code> I use in the test</p> <pre><code>public class Lists { public static Object[] toArray(Collection&lt;?&gt; collection) { return collection.toArray(); } @SafeVarargs public static &lt;T&gt; T[] normalVarArgs(T...elements) { return Arrays.copyOf(elements, elements.length); } public static &lt;T extends Enum&lt;T&gt;&gt; T[] fromEnums(Class&lt;T&gt; enums) { return enums.getEnumConstants(); } @SafeVarargs public static &lt;T extends Enum&lt;T&gt;&gt; T[] enumVarArgs(T...enums) { return enums; } } </code></pre>Genzer HawkerThu, 12 Mar 2015 08:27:40 -0400https://answers.axonivy.com/questions/1224/list-converted-from-an-enum-array-in-ivy-script-doesn-t-work-correctlyivyscriptenumlistarrayChaining checking for initialization in Ivy Scripthttps://answers.axonivy.com/questions/890/chaining-checking-for-initialization-in-ivy-script<p>In the Ivy Designer Guide, Chapter 7, section Null handling / Automatic object creation, it states</p> <p>You can to use the .# operator to suppress the automatic object creation. </p> <pre><code>if( in.#customer == null) { // object is null } if (in.#customer is initialized) { // object is not null or has been set to a non-default value } </code></pre> <p>I also discover that we can do a chain of suppresing initialization like this:</p> <pre><code>if (in.#bigDataClass.#smallerDataClass.#smallDataClass.#tinyDataClass.#fieldXyz is initialized) { // Reach here if all of the properties are initialized } else { // Reach here if any of the properties are null } </code></pre> <p>This really reduces the verbosity of the code when I want to check a deep structure of data classes. Despite its usefulness, I cannot find any (Ivy) documentation mentioning about this feature. I only discovered it by chance and have been using it until now.</p> <p>My question is whether this is an official feature but has been forgotten to mention or it is an unofficial/hidden feature and could be dropped in the future?</p> <p>Thanks &amp; Regards</p>Genzer HawkerMon, 04 Aug 2014 11:35:59 -0400https://answers.axonivy.com/questions/890/chaining-checking-for-initialization-in-ivy-scriptivyscriptauto-initialization