lingua-franca 0.10.1
Lingua Franca code generator
Loading...
Searching...
No Matches
org.lflang.util.CollectionUtil Class Reference

Utilities to manipulate collections. More...

Static Public Member Functions

static< K, V > Map< K, V > compute (Map< K, V > map, K k, BiFunction< K, V, V > computation)
 Returns a map that is identical to the original map, except the value for key k is transformed using the given function.
static< T > Set< T > copy (Set< T > set)
 Returns a copy of the set.
static< T > Set< T > immutableSetOf (T first, T... rest)
 Returns an immutable Set that contains all argument values.
static< T > Set< T > minus (Set< T > set, T eltToRemove)
 Returns a set that contains the elements of the given set minus one element.
static< K, V > Map< K, V > plus (Map< K, V > map, K k, V v)
static< T > Set< T > plus (Set< T > set, T t)
 Returns a set which contains the elements of the given set plus the given element.
static< K, V > void removeFromValues (Map< K, Set< V > > map, V valueToRemove)
 Remove the given value from all the sets that are values in the given map.

Detailed Description

Utilities to manipulate collections.

Most of these methods are using specialized collection implementations (possibly unmodifiable) for small collection sizes. No guarantee is made on the mutability of the collections returned from these functions, meaning, callers should always assume they are unmodifiable. Functions that take a collection parameter as input to produce a new one with a transformation require the input collection to have been obtained from one of the utility functions of this class in the first place.

Member Function Documentation

◆ compute()

static< K, V > Map< K, V > org.lflang.util.CollectionUtil.compute ( Map< K, V > map,
K k,
BiFunction< K, V, V > computation )
static

Returns a map that is identical to the original map, except the value for key k is transformed using the given function.

The transformation function takes the key and current value (null if the key is not present) as inputs, and returns the new value to associate to the key (null if the mapping should be removed).

See also
Map#compute(Object, BiFunction)

◆ copy()

static< T > Set< T > org.lflang.util.CollectionUtil.copy ( Set< T > set)
static

Returns a copy of the set.

The returned set should be considered unmodifiable.

Parameters
setinitial set, nullable
<T>Type of elements
Returns
A new set, or the same

◆ immutableSetOf()

static< T > Set< T > org.lflang.util.CollectionUtil.immutableSetOf ( T first,
T... rest )
static

Returns an immutable Set that contains all argument values.

Duplicate elements are removed without error (contrary to Set.of() and friends).

◆ minus()

static< T > Set< T > org.lflang.util.CollectionUtil.minus ( Set< T > set,
T eltToRemove )
static

Returns a set that contains the elements of the given set minus one element.

An empty set is considered empty.

◆ plus() [1/2]

static< K, V > Map< K, V > org.lflang.util.CollectionUtil.plus ( Map< K, V > map,
K k,
V v )
static

◆ plus() [2/2]

static< T > Set< T > org.lflang.util.CollectionUtil.plus ( Set< T > set,
T t )
static

Returns a set which contains the elements of the given set plus the given element.

The returned set should be considered unmodifiable.

Parameters
setinitial set, nullable
tnew element
<T>Type of elements
Returns
A new set, or the same

◆ removeFromValues()

static< K, V > void org.lflang.util.CollectionUtil.removeFromValues ( Map< K, Set< V > > map,
V valueToRemove )
static

Remove the given value from all the sets that are values in the given map.

Use this if the values of the map (the sets) were build with plus.

In org.lflang.graph.DirectedGraph, this is used to properly remove nodes from a graph. There, we use maps to represent edges, where a value in a map is a set of nodes adjacent to the key for that value. Hence, when a node is removed, it needs to be removed not just as a key, but it also needs to be removed from the neighbors sets of any other keys that may contain it.

Parameters
mapA modifiable map
valueToRemoveValue to remove

The documentation for this class was generated from the following file:
  • /Users/runner/work/lingua-franca/lingua-franca/core/src/main/java/org/lflang/util/CollectionUtil.java