Collections and Gosu enhancements

Enhancements on Gosu collections and related types

Gosu collection and list classes rely on collection classes from the Java language. However, Gosu collections and lists have additional, built-in enhancements compared to Java. Gosu enhancements are Gosu methods and properties added to classes or other types without the subclassing that other languages require to make use of the new methods and properties.

See also

List of enhancement methods and properties on collections

The following tables list the Gosu enhancements to collections and lists, all of which are contained in he gw.lang.enhancements package. The letter T refers to the type of the collection. The syntax <T> comes from the language feature known as generics. For example, for an argument that is listed as conditionBlock(T):Boolean, the argument is a block. That block must take exactly one argument of the list’s type (T) and return a Boolean.

Note: If a type letter such as T appears more than once in arguments or a return result, the letter represents the same type in each usage.

Most collection methods are implemented on Iterable, which is the parent interface of Collection, rather than on Collection or other types that extend Iterable.

Enhancement methods and properties on Iterable<T>

The following table lists the additional methods and properties for iterable objects, which are objects that implement Iterable<T>. The Gosu enhancements are defined in gw.lang.enhancements.CoreIterableEnhancement.

Note: There are also related type-specific enhancements such as CoreIterableIntegerSumEnhancement.
The following methods provide functionality to perform an action on every item in an iterable object. The code examples in the table are based on the following example:
var arrList = {1, 3, 9} // ArrayList<Integer> implements Iterable

Method

Description

Example

each(action-block)

Iterates each element of the iterable object.

var res = 0
arrList.each(\elt -> {res += elt})
print(res)

The output is:

13

eachWithIndex(action-block)

Iterates each element of the iterable object with an index.

var resList = {0, 0, 0, 0} // ArrayList<Integer>
arrList.eachWithIndex(\elt, index -> {resList[index] = elt + 1})
print(resList)

The output is:

[2, 4, 10, 0]

reverse()

Returns a new List<T> that contains all elements in this iterable object in reverse order.

var revList = arrList.reverse()
print(revList)

The output is:

[9, 3, 1]
The following methods provide functionality to filter the elements in an iterable object. The code examples in the table are based on the following example:
var arrList = {1, 3, 9} // ArrayList<Integer> implements Iterable

Method

Description

Example

removeWhere(cond-block)

Removes all elements that satisfy the given criteria. This method returns no value, so it cannot be chained in series. The mutation takes place in the existing iterable object, rather than a new object being created with the specified elements removed.

arrList.removeWhere(\elt -> elt > 8)
print(arrList)

The output is:

[1, 3]

retainWhere(cond-block)

Removes all elements that do not satisfy the given criteria. This method returns no value, so it cannot be chained in series. The mutation takes place in the existing iterable object, rather than a new object being created with only the specified elements.

arrList.retainWhere(\elt -> elt>8)
print(arrList)

The output is:

[9]

where(cond-block)

Returns a new List<T> that contains all elements in this iterable object that satisfy the given condition.

var resList = arrList.where(\elt -> elt>8)
print(resList)

The output is:

[9]

whereTypeIs(Type)

Returns a new List of the given type.

var dList = {1, 3.2, 9} // ArrayList<Double>
var resList = dList.whereTypeIs(Integer) // List<Integer>
print(resList)

The output is:

[1, 9]
The following methods and properties provide information about the collection. The code examples in the table are based on the following example:
var arrList = {1, 3, 9} // ArrayList<Integer> implements Iterable

Method or property

Description

Example

allMatch(cond-block)

Returns true if all elements in the Collection satisfy the condition.

arrList.allMatch(\elt1 -> elt1 < 10) // Evaluates to true

Count property

Returns the number of elements in the Iterable.

arrList.Count // Evaluates to 3

countWhere(cond-block)

Returns the number of elements in the Collection that match the given condition.

arrList.countWhere(\elt1 -> elt1 < 5) // Evaluates to 2

HasElements property

Returns true if this Collection has any elements. Use this method rather than the default collection method isEmpty because HasElements interacts better with null values. For example, the expression coll.HasElements does not return true if the expression coll is null, but coll.isEmpty() returns false.

arrList.HasElements // Evaluates to true

hasMatch(cond-block)

Returns true if this Collection contains any elements that match the given block.

arrList.hasMatch(\elt1 -> elt1 < 5) // Evaluates to true

single()

If there is only one element in the Iterable, returns that value. Otherwise, it throws an IllegalStateException exception.

var oneList = {9} // ArrayList<Integer>
oneList.single() // Evaluates to 9

singleWhere(cond-block)

If there is only one element in the collection that matches the given condition, this method returns that value. Otherwise, it throws an IllegalStateException exception.

print(arrList.singleWhere(\elt -> elt < 3))

The output is:

1
The following methods provide functionality to get a particular element or value from a collection. The code examples in the table are based on the following example:
var arrList = {1, 3, 9} // ArrayList<Integer> implements Iterable

Method

Description

Example

average()

average(block)

With no argument, returns the average of the numeric values in the collection.

With a block argument, returns the average of the numeric values derived from the collection.

print(arrList.average())
print(arrList.average(\elt -> (elt % 3 == 0 ? elt : 0))

The output is:

4.333333333333333333333333333333333
4

first()

Returns the first element in the Collection, or null if the collection is empty.

print(arrList.first())

The output is:

1

firstWhere(cond-block)

Returns the first element in the collection that satisfies the condition, or returns null if none do.

print(arrList.firstWhere(\elt -> elt < 5))

The output is:

3

last()

Returns the last element in the collection, or null if the list is empty.

print(arrList.last())

The output is:

9

lastWhere(cond-block)

Returns the last element in the collection that matches the given condition, or null if no elements match it.

print(arrList.lastWhere(\elt -> elt < 5))

The output is:

3

max()

max(proj-block)

Returns the maximum of the selected values from the collection. This method excludes any null values. If there are no non-null values, this method throws an exception.

With a block argument, returns the maximum of the values derived from the collection.

print(arrList.max())

The output is:

9

maxBy(proj-block)

Returns the maximum T of the collection based on the projection to a Comparable object.

print({"a", "ab", "abc"}.maxBy(\elt -> elt.length))

The output is:

abc

min()

min(proj-block)

Returns the minimum of the selected values from the collection. This method excludes any null values. If there are no non-null values, this method throws an exception.

With a block argument, returns the minimum of the values derived from the collection.

print(arrList.min())

The output is:

1

minBy(proj-block)

Returns the minimum T of the collection based on the projection to a Comparable object.

print({"a", "ab", "abc"}.minBy(\elt -> elt.length))

The output is:

a

sum(proj-block)

Returns the sum of the numeric values selected from the collection.

print({"a", "ab", "abc"}.sum(\elt -> elt.length))

The output is:

6
The following methods provide functionality to convert the collection to another class or format. The code examples in the table are based on the following example:
var arrList = {1, 3, 9} // ArrayList<Integer> implements Iterable

Method

Description

Example

flatMap(proj-block)

Maps each element of the collection to a Collection of values and flattens them into a single List.

Consider the following data structure:
  • A claim object has an Exposures property that contains an array of exposure objects.
  • An exposure has a Notes property that contains a list of Note objects.
  • myClaim is a claim object
var allNotes = myClaim.Exposures.flatMap(\ e -> e.Notes)

The allnotes variable contains a single list that contains all the notes on all the exposures on the claim.

fold(block)

Accumulates the values of a Collection<T> into a single T.

print(arrList.fold(\elt1, elt2 -> elt1 * elt2))
print({"a", "ab", "abc"}.fold(\elt1, elt2 -> elt1 + elt2))

The output is:

27
aababc

join(delimiter)

Joins all elements together as a string with a delimiter.

print(arrList.join("--"))

The output is:

[1--3--9]

map(proj-block)

Returns a List of each element of the Collection<T> mapped to a new value.

print(arrList.map(\elt -> elt + 1))

The output is:

[2, 4, 10]

partitionUniquely(proj-block)

Partitions this Collection into a Map of keys to elements in this Collection. The block argument returns the keys in the map. The elements in the collection are the values in the map. An IllegalStateException exception is thrown if more than one element maps to the same key.

print(arrList.partitionUniquely(\elt -> elt + 1))

The output is:

{2=1, 4=3, 10=9}

reduce(init, reducer-block)

Accumulates the values of a Collection<T> into a single V given an initial seed value.

print(arrList.reduce(100, \x, y -> x + y))

The output is:

113

toCollection()

If this iterable object is already a collection, this method returns the same Collection. Otherwise it creates a new Collection and copies this iterable object to it.

var coll = arrList.toCollection()

toList()

If this iterable object is already a list, this method returns the same List. Otherwise it creates a new List and copies this Iterable to it.

print(arrList.toList())

The output is:

[1,3,9]

toSet()

Converts the iterable object to a Set.

print(arrList.toSet())

The output is:

[1,3,9]

toTypedArray()

Converts the Iterable<T> object into an array T[].

var myTypedArray = arrList.toTypedArray()
print("myTypedArray type: ${typeof myTypedArray } " )
for (i in myTypedArray) {
  print(i)
}

The output is:

myTypedArray type: java.lang.Integer[]
1
3
9
The following methods provide functionality to act on two collections. The code examples in the table are based on the following example:
var arrList = {1, 3, 9} // ArrayList<Integer> implements Iterable
var arrList2 = {4, 9, 12, 12, 32}

Method

Description

Example
concat(collection<T>) Returns a new Collection<T> that is the concatenation of this iterable object and the other collection
var concList = arrList.concat(arrList2)
print(concList)

The output is:

[1, 3, 9, 4, 9, 12, 12, 32]

disjunction(collection<T>)

Returns a new Set<T> that is the symmetric difference of this collection and the other collection. This set contains the elements that exist in either one of the collections but not in both collections.

var sdList = arrList.disjunction(arrList2)
print(sdList)

The output is:

[1, 3, 4, 12, 32]

intersect(collection<T>)

Returns a Set<T> that is the intersection of the two collection objects. This set contains only the elements that exist in both of the collections.

var interList = arrList.intersect(arrList2)
print(interList)

The output is:

[9]

subtract(collection<T>)

Returns a new Set<T> that is the subtraction of the other collection from this collection. This set contains the elements that exist only in the collection that calls the method and do not exist in the collection that is the method argument.

var subList = arrList.subtract(arrList2)
print(subList)

The output is:

[1, 3]

union(collection<T>)

Returns a new Set<T> that is the union of the two collections. This set contains one instance of every element from both of the collections. If either collection has duplicated elements, the result contains only one instance of that element.

var unionList = arrList.union(arrList2)
print(unionList)

The output is:

[1, 3, 9, 4, 12, 32]
zip(iterable<R>) Returns a List<T,R> of gw.util.Pair elements that contain corresponding values from the two iterable objects. If one iterable object contains more elements than the other one, any extra elements are discarded.
var zipList = arrList.zip(arrList2)
print(zipList)

The output is:

[(1, 4), (3, 9), (9, 12)]

Enhancement methods and properties on Collection<T>

The Gosu enhancements are defined in gw.lang.enhancements.CoreCollectionEnhancement.gsx.

The following methods provide functionality to sort the elements in a collection.
Note: By default, these methods do not use a localized sort collation order. For localized sorting, pass a comparator as a second argument to the method.
The following table lists the available enhancement methods on Collection. The code examples in the table are based on the following example:
var strArrList = {"wolf cub", "puppy", "tiger cub", "kitten"} // ArrayList implements Collection

Method

Description

Example

orderBy(proj-block)

Returns a new List<T> ordered by a block that you provide. This method is different from sortBy, which sorts in place.

var strArrListSorted = strArrList.orderBy(\elt -> elt.length)
print(strArrListSorted)

The output is:

[puppy, kitten, wolf cub, tiger cub]

orderByDescending(proj-block)

Returns a new List<T> reverse ordered by the given value. This method is different from sortByDescending, which sorts in place.

var strArrListSortedDesc = strArrList.orderByDescending(\elt -> elt.length)
print(strArrListSortedDesc)

The output is:

[tiger cub, wolf cub, kitten, puppy]

Enhancement methods on List<T>

The following table lists the available enhancement methods on List<T>. The Gosu enhancements are defined in gw.lang.enhancements.CoreListEnhancement.gsx, gw.lang.enhancements.CoreListOfComparablesEnhancement.gsx and gw.lang.enhancements.CoreIOrderedListEnhancement.gsx. The code examples in the table are based on the following example:
var arrList = {1, 3, 9} // ArrayList implements List

Method

Description

Example

cast(Type)

Converts the Collection<T> into a collection of Type. An IllegalArgumentException exception is thrown if the cast is invalid. For example, the expression objList.cast(String) throws an exception.

var objList : ArrayList<Object> // ArrayList implements List
objList = {1, 3, 9}
var intList = objList.cast(Integer) // ArrayList<Integer>
print(intList)

The output is:

[1, 3, 9]

copy()

Creates a copy of the list as a List<T>.

var newList = arrList.copy()
print(newList)

The output is:

[1, 3, 9]

freeze()

Returns a new unmodifiable version of the list as a List<T>. An attempt to modify the frozen list throws an UnsupportedOperationException exception.

var frozenList = arrList.freeze()
print(frozenList)

The output is:

[1, 3, 9]

partition(proj-block)

Partitions this List object into a Map of keys to sub-lists of elements in this list. The block argument returns the keys in the map. The elements in the list are added to List objects, which are the values in the map.

var q = Query.make(Address).compare(Address#State, NotEquals, null)
var qList = q.select().toList()
var pMap = qList.partition(\elt -> elt.State)
for (k in pMap.Keys) {
  print("${k}:")
  for (v in pMap[k]) {
    print("\t${v}")
  }
}

The output is similar to the following lines, which have been truncated:

NV:
  300 W Sahara Ave, Floor 0000, Developer Unit Habitation Cube #0000
...
NY:
  3240 Riverdale Ave, Floor 0000, Developer Unit Habitation Cube #0000
...
Tokyo:
  〒107-8556 Tokyo, 港区市, 1-1, 2-chome, Minami-Aoyama, Floor 0000, Japan
...

shuffle()

Returns a List<T> that contains the same elements in a random order.

var shuffList = arrList.shuffle() // ArrayList<Integer>
print(shuffList)

The output is similar to the following:

[3, 1, 9]

sort()

sort(comparator)

Sorts the list in place, with optional support for localized sorting. By default, this method does not use a localized sort collation order. For localized sorting, pass a comparator as an argument to the method. This method returns the original list, sorted in place.

Note: Ensure the collection is cast to a sortable type.
var strArrList : ArrayList<String> // ArrayList implements List
strArrList = {"wolf cub", "puppy", "tiger cub", "kitten"}
var newArrList = strArrList.sort()
print("strArrList: ${strArrList}")
print("newArrList: ${newArrList}")
print("${strArrList === newArrList}")

The output is:

strArrList: [kitten, puppy, tiger cub, wolf cub]
newArrList: [kitten, puppy, tiger cub, wolf cub]
true

sortBy(proj-block)

sortBy(proj-block, comparator)

Sorts the list in place but instead of comparing the items directly like sort does, uses a block that returns the item to compare. By default, this method does not use a localized sort collation order. For localized sorting, pass a comparator as a second argument to the method.

This method returns the original list, sorted in place. This method is different from orderBy, which returns a new List<T> and does not sort the list in place.

Note: Ensure the collection is cast to a sortable type.
var strArrList : ArrayList<String> // ArrayList implements List
strArrList = {"wolf cub", "puppy", "tiger cub", "kitten"}
var newArrList = strArrList.sortBy(\elt -> elt.length)
print("strArrList: ${strArrList}")
print("newArrList: ${newArrList}")
print("${strArrList === newArrList}")
The output is:
strArrList: [puppy, kitten, wolf cub, tiger cub]
newArrList: [puppy, kitten, wolf cub, tiger cub]
true

sortByDescending(proj-block)

sortByDescending(proj-block, comparator)

Same as sortBy, but sorts the list in place in descending order. This method is different from orderByDescending, which returns a new List<T>. This method returns the original list, sorted in place.

Note: Ensure the collection is cast to a sortable type.
var strArrList : ArrayList<String> // ArrayList implements List
strArrList = {"wolf cub", "puppy", "tiger cub", "kitten"}
var newArrList = strArrList.sortByDescending(\elt -> elt.length)
print("strArrList: ${strArrList}")
print("newArrList: ${newArrList}")
print("${strArrList === newArrList}")
The output is:
strArrList: [tiger cub, wolf cub, kitten, puppy]
newArrList: [tiger cub, wolf cub, kitten, puppy]
true

sortDescending()

sortDescending(comparator)

Same as sort, but sorts the list in place in descending order. This method returns the original list, sorted in place.

Note: Ensure the collection is cast to a sortable type.
var strArrList : ArrayList<String> // ArrayList implements List
strArrList = {"wolf cub", "puppy", "tiger cub", "kitten"}
var newArrList = strArrList.sortDescending()
print("strArrList: ${strArrList}")
print("newArrList: ${newArrList}")
print("${strArrList === newArrList}")
The output is:
strArrList: [wolf cub, tiger cub, puppy, kitten]
newArrList: [wolf cub, tiger cub, puppy, kitten]
true

Enhancement methods on Set<T>

The following table lists the available methods and properties on Set<T>. The Gosu enhancements are defined in gw.lang.enhancements.CoreSetEnhancement.gsx.

The following table lists the available methods on Set<T>. The code examples in the table are based on the following example:
var set = new HashSet() // A set of type Object
set.add("String 1")
set.add("String 2")

Method

Description

Example

cast(Type)

Returns a copy of the set as a Set<Type> object.

var strSet = set.cast(String)
print(strSet)

The output is:

[String 1, String 2]

copy()

Returns a copy of the set as a Set<T> object.

var newSet = set.copy()
print(newSet)

The output is:

[String 1, String 2]

freeze()

Returns a new unmodifiable copy of the set as a Set<T> object.

var frozenSet = set.freeze()
print(frozenSet)

The output is:

[String 1, String 2]
partition()

Partitions this Set object into a Map of keys to sub-sets of elements in this set. The block argument returns the keys in the map. The elements in this set are added to HashSet objects, which are the values in the map.

var q = Query.make(Address).compare(Address#State, NotEquals, null)
var qSet = q.select().toSet()
var pMap = qSet.partition(\elt -> elt.State)
for (k in pMap.Keys) {
  print("${k}:")
  for (v in pMap[k]) {
    print("\t${v}")
  }
}

The output is similar to the following lines, which have been truncated:

NV:
  300 W Sahara Ave, Floor 0000, Developer Unit Habitation Cube #0000
...
NY:
  3240 Riverdale Ave, Floor 0000, Developer Unit Habitation Cube #0000
...
Tokyo:
  〒107-8556 Tokyo, 港区市, 1-1, 2-chome, Minami-Aoyama, Floor 0000, Japan
...

powerSet()

Returns the power set of the set as a Set<Set<T>> object.

var pwrSet = set.powerSet()
print(pwrSet)

The output is:

[[], [String 1, String 2], [String 1], [String 2]]

See also

List of enhancement methods and properties on maps

The following tables list the available enhancement methods and properties on Map<K,V>. The symbol K represents the key class. The symbol V represents the value class. The Gosu enhancements are defined in gw.lang.enhancements.CoreMapEnhancement.gsx.

The following methods and properties provide functionality for general usage of a map. The code examples in the table are based on the following example:
var mapper = new HashMap<String, String>()
mapper.put("aKey", "aValue")
mapper.put("bKey", "bValue")

Method or property

Description

Example

copy()

Returns a HashMap object that is a copy of this map object. This method always returns a HashMap object, even if the original map was another class that implements the Map interface.

var newMap = mapper.copy()
print(newMap)
The output is:
{bKey=bValue, aKey=aValue}

Count property

The number of keys in the map.

print(mapper.Count)
The output is:
2

Keys property

A collection of all keys in the map.

print(mapper.Keys)
The output is:
{bKey, aKey}

toAutoMap(defaultValueBlock)

Returns an AutoMap object that wraps the current map and provides handling of default values. The method takes a default value mapping block with the same meaning as in the constructor for the AutoMap object. The block takes one argument (the key) and returns a default value that is appropriate for that key.

var autoMap = new HashMap<String, String>().toAutoMap(\k -> " length  ${mapper [k].length} mapped")
autoMap["aKey"] = mapper["aKey"] + autoMap["aKey"]
autoMap["new"] = "Hello World" + autoMap["new"]
for (k in autoMap.Keys) {
  print("Key ${k} = ${autoMap[k]}")
}
The output is:
Key new = Hello World length 0 mapped
Key aKey = aValue length 6 mapped

Values property

A collection of all values in the map.

print(mapper.Values)
The output is:
{bValue, aValue}
The following methods provide functionality to perform an action on every item in a map. The code examples in the table are based on the following example:
var mapper = new HashMap<String, String>()
mapper.put("aKey", "aValue")
mapper.put("bKey", "bValue")

Method

Description

Example

eachKey(block)

Runs a block for every key in the map. The block must take one argument (the key) and return no value.

mapper.eachKey(\k -> {/* Your method call here */ 
  mapper[k] = mapper[k] + "Status: Reviewed";
  print("Key ${k} = ${ mapper[k]}")
})
The output is:
Key bKey = bValue Status: Reviewed
Key aKey = aValue Status: Reviewed

eachKeyAndValue(block)

Runs a block for every key-value pair in the map. The block must take two arguments: a key and a value. The block must return no value.

var res = "Mapper"
mapper.eachKeyAndValue(\k, val -> {res += " | ${k}:${val}"})
print(res)
The output is:
Mapper | bKey:bValue | aKey:aValue

eachValue(block)

Runs a block for every value in the map. The block must take one argument (the value) and return no value.

var res2 = "Values"
mapper.eachValue(\value -> {res2 += " | ${value}"})
print(res2)
The output is:
Values | bValue | aValue
The following methods provide functionality to filter and remap a map. The methods that have retain in the name are destructive. The methods with filter in the name create a new map and do not modify the original map. The code examples in the table are based on the following example:
var mapper = new HashMap<String, String>()
mapper.put("aKey", "aValue")
mapper.put("bKey", "bValue")

Method

Description

Example

filterByKeys(keyFilter)

Returns a new map that is a clone of the original map but without entries whose keys do not satisfy the keyFilter expression. The key filter block must take one argument (a key) and return true or false.

var filterMap1 = mapper.filterByKeys(\k -> k=="aKey")
print(filterMap1)
The output is:
{aKey=aValue}

filterByValues(valueFilter)

Returns a new map that is a clone of the original map but without entries whose values do not satisfy the valueFilter expression. The key filter block must take one argument (a value) and return true or false.

var filterMap2 = mapper.filterByValues(\value -> value=="bValue")
print(filterMap2)
The output is:
{bKey=bValue}

mapValues(mapperBlock)

Returns a new map that contains the same keys as the original map but different values based on a block that you provide. The block must take one argument (the original value) and return a new value based on that value. The values can have an entirely different type.

Gosu infers the return type of the block based on what you return and creates the appropriate type of map. For example, the Gosu code in the Example column takes a Map<String, String> and maps it to a new object of type Map<String,Integer>.

var remapper = mapper.mapValues(\value -> value.length)
print(remapper)
The output is:
{bKey=6, aKey=6}

retainWhereKeys(keyFilter)

Destructively removes all entries whose keys do not satisfy the keyFilter expression. Returns true if and only if this map changed as a result of the block. The key filter block must take one argument (a key) and return true or false.

mapper.retainWhereKeys(\k -> k == "aKey")
print(mapper)
The output is:
{aKey=aValue}

retainWhereValues(valueFilter)

Destructively removes all entries whose values do not satisfy the valueFilter expression. Return true if this map changed as a result of the call. The value filter block must take one argument (a value) and return true or false.

mapper.retainWhereValues(\value -> value == "bValue")
print(mapper)
The output is:
{bKey=bValue}
The following methods provide functionality to use properties files for a map. The code examples in the table are based on the following example:
var mapper = new HashMap<String, String>()
mapper.put("aKey", "aValue")
mapper.put("bKey", "bValue")
The examples also use a properties file that contains the following lines:
name=Default values
maxAge=100
minAge=18

Method

Description

Example

readFromPropertiesFile(file)

Reads the contents of this map from a file in the Java properties format using APIs on java.util.Properties. The method takes a java.io.File object and returns a map of the keys and values. The return type is Map<String,String>.

This example reads the text {bKey=bValue, aKey=aValue} from the file:

var file = new java.io.File("c:\\Guidewire\\myprops.properties")
var propsMapper : Map<String, String>
propsMapper = propsMapper.readFromPropertiesFile(file)
print(propsMapper)
The output is:
{maxAge=100, minAge=18, name=Default values}

writeToPropertiesFile(file)

writeToPropertiesFile(file, comments)

Writes the contents of this map to a file in the Java properties format using APIs on java.util.Properties. The method takes a java.io.File object and returns nothing. The second method signature takes a String object to write comments in the properties file.

This example writes the text {bKey=bValue, aKey=aValue} to the file:

var file = new java.io.File("C:\\Guidewire\\newprops.properties")
mapper.writeToPropertiesFile(file)

File contents:

#
#Mon Oct 07 11:59:25 PDT 2019
bKey=bValue
aKey=aValue