Force-Framework

Mark Brennand

ImmutableV1

global with sharing class ImmutableV1
Description

Class providing the Collections API implementation.

Use these classes to create and manage immutable Lists, Sets and Maps.

List and Set functionality is combined and provided by the Collection interface.

See README for full details of the Collection API.

Copyright (c) 2025 Mark Brennand, released under MIT License.

AuthorMark Brennand

Methods

  of

global static ReadOnlyMap of(final Map<Object, Object> source)
Description

Creates an immutable Map from the given source Map.

The key to the Map is of an unknown type.

Parametersource: The source Map.
ReturnsThe immutable Map.

  of

global static ReadOnlyMap of(final Map<Id, Object> source)
Description

Creates an immutable Map from the given source Map.

The key to the Map is an SObject Id.

Parametersource: The source Map.
ReturnsThe immutable Map.

  of

global static ReadOnlyMap of(final Map<String, Object> source)
Description

Creates an immutable Map from the given source Map.

The key to the Map is a String.

Parametersource: The source Map.
ReturnsThe immutable Map.

  of

global static Collection of(final Iterable<Object> source)
Description

Creates an immutable List from the given Iterable.

Parametersource: The Iterable.
ReturnsThe immutable List.

ImmutableV1.APIException

global with sharing class APIException extends ForceFwException
DescriptionException thrown when an operation in the Immutable API fails.

ImmutableV1.Collection

global interface Collection extends ArrayV1.Methods
Description

Interface for List and Set that supports conversion to a List and the functionality of the ArrayV1.Methods interface.

A ReadOnlyMap or ReadyOnlySet may have reduce(), filter(), transform() etc. called on it.

Methods

  contains

Boolean contains(final Object element)
Description

Determines whether collection contains the given object.

Parameterelement: The object to be checked.
ReturnsTrue if the collection contains the object, false if not.

  containsAll

Boolean containsAll(final Iterable<Object> objs)
Description

Determines whether the collection contains all the objects in the Iterable argument.

Parameterobjs: The objects to be matched.
ReturnsTrue if the collection contains all the objects, false if not.

  get

Object get(final Integer index)
Description

Retrieves the element at the given index in the List.

Parameterindex: The positional index.
ReturnsThe element.

  indexOf

Integer indexOf(final Object element)
Description

Finds the positional index in the List of the given object.

Parameterelement: The object to find.
ReturnsThe positional index, or -1 if not found.

  isEmpty

Boolean isEmpty()
Description

Checks if the collection is empty.

ReturnsTrue if the collection is empty, otherwise false.

  size

Integer size()
Description

Returns the number of elements in the collection.

ReturnsThe number of elements in the collection.

  toList

List<Object> toList(final List<Object> result)
Description

Converts the contents of a collection to a List.

The collection's elements will be added to the List passed as argument. This method allows a List of a specific type to be populated from a collection.

Parameterresult: The List to be populated.
ReturnsThe populated List.

  toList

List<Object> toList()
Description

Converts the contents of a collection to a List.

The returned List will be of type Object. This will prevent it being cast to a List of any other type, even if the List contains that type.

ReturnsThe collection's contents as a List.

ImmutableV1.ReadOnlyMap

global interface ReadOnlyMap extends Iterable<Object>
Description

An immutable Map.

It has all the accessor functionality of a Map but has had the update capability removed.

It provides one item of functionality not present in a Map, iteration over the implementation, the Objects returned by the Iterator will be the Map's keys.

Methods

  containsKey

Boolean containsKey(final Object key)
Description

Checks if the map contains the specified key.

Parameterkey: The key to check
ReturnsTrue if the map contains the key, false otherwise

  get

Object get(final Object key)
Description

Retrieves the value associated with the specified key.

Parameterkey: The key whose associated value is to be returned.
ReturnsThe value associated with the key, or null if the key is not found.

  keySet

Set<Object> keySet()
Description

Returns the keys to the Map's elements.

ReturnsThe keys.

  size

Integer size()
Description

Returns the number of keys in the Map.

ReturnsThe number of keys in the Map.

  values

List<Object> values()
Description

Returns a List of the values stored in the Map.

ReturnsThe values.