Class LicenseChoice
java.lang.Object
org.cyclonedx.model.LicenseChoice
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExpression(Expression expression) Convenience method to add an ExpressionvoidaddExpressionDetailed(ExpressionDetailed expressionDetailed) Convenience method to add an ExpressionDetailedvoidaddItem(LicenseItem item) Adds a license item to the choicevoidaddLicense(License license) Convenience method to add a LicensebooleanDeprecated.Returns the first ExpressionDetailed item.getItems()Gets the list of license items.Deprecated.UsegetItems()and filter by type instead.inthashCode()booleanisValidForVersion(Version version) Validates whether this choice conforms to a specific version's constraints.voidsetExpression(Expression expression) Deprecated.UsesetItems(List)with LicenseItem.ofExpression() instead.voidsetExpressionDetailed(ExpressionDetailed expressionDetailed) Sets a single detailed expression, clearing all other items.voidsetItems(List<LicenseItem> items) voidsetLicenses(List<License> licenses) Deprecated.UsesetItems(List)with LicenseItem.ofLicense() instead.
-
Constructor Details
-
LicenseChoice
public LicenseChoice()
-
-
Method Details
-
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
-
addItem
Adds a license item to the choice -
addLicense
Convenience method to add a License -
addExpression
Convenience method to add an Expression -
addExpressionDetailed
Convenience method to add an ExpressionDetailed -
getLicenses
Deprecated.UsegetItems()and filter by type instead. Returns only License items for backward compatibility with pre-1.7 API. -
setLicenses
Deprecated.UsesetItems(List)with LicenseItem.ofLicense() instead. Sets licenses, clearing all other items. For backward compatibility with pre-1.7 API. -
getExpression
Deprecated.UsegetItems()and filter by type instead. Returns the first Expression item for backward compatibility with pre-1.7 API. -
setExpression
Deprecated.UsesetItems(List)with LicenseItem.ofExpression() instead. Sets a single expression, clearing all other items. For backward compatibility with pre-1.7 API. -
getExpressionDetailed
Returns the first ExpressionDetailed item. Note: This is part of the 1.7 API, not deprecated. -
setExpressionDetailed
Sets a single detailed expression, clearing all other items. Note: This is part of the 1.7 API, not deprecated. -
isValidForVersion
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
-
hashCode
-
getItems()and filter by type instead.