Utility Classes and Methods
A Utility Class node contains a utility class with methods that can be called from other methods in your application. Utility classes support standard Java syntax and class structure.
Because a utility class can be made application-agnostic, it allows you to share Java code across different methods and reuse algorithm implementations across multiple applications. Methods defined in a utility class can be called from any other method within the same application.
For example, consider the following method, which builds all geometries in the model:
public static void runAllGeom() {
model.geom().run();
}
The name of the utility class must match the tag of the Utility Class node. If the Utility Class node is named util1, you can call the method above from another method using:
util1.runAllGeom();
When working with utility classes, it is often useful to enable the View all code setting under Preferences > Application Builder > Methods. This setting allows you to view the full class structure and add import statements for Java libraries.
The figure below shows the default structure of a newly added Utility Class node named util1.
The figure below shows a (renamed) utility class Utilities from the Organ Pipe Designer app, available in the Application Libraries under the Acoustics Module.
This utility class defines several methods that are called from some of the standard methods in the app. The figure below shows an example call from the method addPipeDiameter to the utility class method getHighestNumericParameterValue, using the following syntax:
double dbl = Utilities.getHighestNumericParameterValue(dSweepTableInputs);
Unlike standard methods, utility class methods are not restricted to the data types defined in the Declarations node. They can accept and return general Java types, including custom data types. Such custom data types are defined using class definitions, where you specify the structure and behavior of your own Java objects.