Class LazyId

java.lang.Object
io.fluxcapacitor.javaclient.common.LazyId

public class LazyId extends Object
A lazily initialized identifier that serializes as a plain string.

Unlike using Lombok's lazy getters, LazyId ensures the ID is generated only once and remains stable even after calling .toBuilder() on the enclosing object. This makes it useful in scenarios where the ID should be deterministically generated only once per logical instance, including deserialization and cloning scenarios.

If the ID is not provided directly, a supplier (e.g., FluxCapacitor::generateId) can be used to compute it lazily on first access. The ID is then cached and reused.

  • Constructor Details

    • LazyId

      public LazyId()
      Constructs a new LazyId with a default ID supplier using FluxCapacitor::generateId.
    • LazyId

      public LazyId(Supplier<String> supplier)
      Constructs a new LazyId with the specified supplier. The ID will be computed when accessed.
      Parameters:
      supplier - the supplier used to generate the ID
    • LazyId

      public LazyId(Object id)
      Constructs a LazyId with a known ID value. No computation will occur.
      Parameters:
      id - the ID value (converted to string if non-null)
  • Method Details

    • toString

      public String toString()
      Returns the ID value as a string.
      Overrides:
      toString in class Object