Class LabelCardinalityValidator

java.lang.Object
org.apache.tinkerpop.gremlin.structure.util.LabelCardinalityValidator

public final class LabelCardinalityValidator extends Object
Validates label operations against a LabelCardinality constraint. All methods are stateless and static.

This class is separated from the enum so that cardinality remains a pure data descriptor while validation logic can be extended, overridden by providers, or tested independently.

Since:
4.0.0
  • Method Details

    • validateAdd

      public static void validateAdd(LabelCardinality cardinality, Set<String> currentLabels, String label, String... moreLabels)
      Validates that adding labels would not violate cardinality constraints.
      Throws:
      IllegalStateException - if mutation is not supported or max would be exceeded
    • validateDrop

      public static void validateDrop(LabelCardinality cardinality, Set<String> currentLabels, String label, String... moreLabels)
      Validates that dropping specific labels would not violate cardinality constraints. Simulates the removal to check whether the minimum label count would be violated.
      Throws:
      IllegalStateException - if mutation is not supported or min would be violated
    • validateDropAll

      public static void validateDropAll(LabelCardinality cardinality, Set<String> currentLabels)
      Validates that dropping all labels would not violate cardinality constraints.
      Throws:
      IllegalStateException - if mutation is not supported or min > 0
    • validateCreation

      public static void validateCreation(LabelCardinality cardinality, Set<String> labels)
      Validates that a set of labels is valid for element creation under this cardinality.
      Throws:
      IllegalStateException - if the label count violates min or max