Interface MergePolicy


public interface MergePolicy
Decides whether a storage holding one variant of a type may accept another variant of the same type, and what the stored variant becomes (ARCHITECTURE.md ยง9.2). Different types never merge, whatever the policy says.

Implementations must be deterministic and must not use floating point.

  • Field Details

    • STRICT

      static final MergePolicy STRICT
      Only equal variants merge. The default for every category.
  • Method Details

    • canMerge

      boolean canMerge(@NotNull @NotNull ResourceVariant existing, @NotNull @NotNull ResourceVariant incoming)
    • merge

      @NotNull @NotNull ResourceVariant merge(@NotNull @NotNull ResourceVariant existing, long existingAmount, @NotNull @NotNull ResourceVariant incoming, long incomingAmount)
      Only called when canMerge(ResourceVariant, ResourceVariant) returned true.
      Returns:
      the variant stored after adding incomingAmount of incoming to existingAmount of existing
    • weightedAverage

      @NotNull static @NotNull MergePolicy weightedAverage(@NotNull @NotNull ResourceComponentType<Long> component)
      Merges variants that differ only in component, replacing it by the amount-weighted average (rounded down). Example: mixing 100 mB of steam at 400 K into 300 mB at 300 K gives 400 mB at 325 K.