Class LicenseChoice

java.lang.Object
org.cyclonedx.model.LicenseChoice

public class LicenseChoice extends Object
Represents a choice of licenses for a component or service. In CycloneDX 1.7+, this implements an item-level choice model where an array can contain a mix of License, Expression, and ExpressionDetailed objects. For earlier versions (1.6 and below), this enforces an array-level choice where the entire array must be either all licenses, or a single expression, or a single detailed expression.
Since:
9.0.0
  • Constructor Details

    • LicenseChoice

      public LicenseChoice()
  • Method Details

    • getItems

      public List<LicenseItem> getItems()
      Gets the list of license items. Each item can be a License, Expression, or ExpressionDetailed. This is the primary API for CycloneDX 1.7+ support.
    • setItems

      public void setItems(List<LicenseItem> items)
    • addItem

      public void addItem(LicenseItem item)
      Adds a license item to the choice
    • addLicense

      public void addLicense(License license)
      Convenience method to add a License
    • addExpression

      public void addExpression(Expression expression)
      Convenience method to add an Expression
    • addExpressionDetailed

      public void addExpressionDetailed(ExpressionDetailed expressionDetailed)
      Convenience method to add an ExpressionDetailed
    • getLicenses

      @Deprecated public List<License> getLicenses()
      Deprecated.
      Use getItems() and filter by type instead. Returns only License items for backward compatibility with pre-1.7 API.
    • setLicenses

      @Deprecated public void setLicenses(List<License> licenses)
      Deprecated.
      Use setItems(List) with LicenseItem.ofLicense() instead. Sets licenses, clearing all other items. For backward compatibility with pre-1.7 API.
    • getExpression

      @Deprecated public Expression getExpression()
      Deprecated.
      Use getItems() and filter by type instead. Returns the first Expression item for backward compatibility with pre-1.7 API.
    • setExpression

      @Deprecated public void setExpression(Expression expression)
      Deprecated.
      Use setItems(List) with LicenseItem.ofExpression() instead. Sets a single expression, clearing all other items. For backward compatibility with pre-1.7 API.
    • getExpressionDetailed

      public ExpressionDetailed getExpressionDetailed()
      Returns the first ExpressionDetailed item. Note: This is part of the 1.7 API, not deprecated.
    • setExpressionDetailed

      public void setExpressionDetailed(ExpressionDetailed expressionDetailed)
      Sets a single detailed expression, clearing all other items. Note: This is part of the 1.7 API, not deprecated.
    • isValidForVersion

      public boolean isValidForVersion(Version version)
      Validates whether this choice conforms to a specific version's constraints. For 1.6 and below: array-level choice (all licenses OR single expression OR single expressionDetailed) For 1.7+: item-level choice (mix allowed)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object