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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleancanMerge(@NotNull ResourceVariant existing, @NotNull ResourceVariant incoming) @NotNull ResourceVariantmerge(@NotNull ResourceVariant existing, long existingAmount, @NotNull ResourceVariant incoming, long incomingAmount) Only called whencanMerge(ResourceVariant, ResourceVariant)returnedtrue.static @NotNull MergePolicyweightedAverage(@NotNull ResourceComponentType<Long> component) Merges variants that differ only incomponent, replacing it by the amount-weighted average (rounded down).
-
Field Details
-
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 whencanMerge(ResourceVariant, ResourceVariant)returnedtrue.- Returns:
- the variant stored after adding
incomingAmountofincomingtoexistingAmountofexisting
-
weightedAverage
@NotNull static @NotNull MergePolicy weightedAverage(@NotNull @NotNull ResourceComponentType<Long> component) Merges variants that differ only incomponent, 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.
-