Skip to content

Commit 9314fa7

Browse files
bactgoneall
authored andcommitted
Javadoc: Add javadoc string to ListedLicenses
Signed-off-by: Arthit Suriyawongkul <[email protected]>
1 parent d4aa068 commit 9314fa7

File tree

1 file changed

+163
-56
lines changed

1 file changed

+163
-56
lines changed

src/main/java/org/spdx/library/ListedLicenses.java

Lines changed: 163 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,25 @@ private ListedLicenses() {
7373
"false"));
7474
initializeLicenseModelStore();
7575
}
76-
76+
77+
/**
78+
* Initializes the license model store for managing SPDX listed licenses and
79+
* exceptions
80+
* <p>
81+
* This method sets up the appropriate model store based on the configuration.
82+
* If the property
83+
* {@code org.spdx.useJARLicenseInfoOnly} is set to {@code true}, it uses the
84+
* locally cached licenses.
85+
* Otherwise, it attempts to fetch the most current listed licenses from the
86+
* SPDX website.
87+
* If the web store is unavailable, it falls back to the locally cached
88+
* licenses.
89+
* </p>
90+
* <p>
91+
* This method also initializes the SPDX version 2 and version 3 model stores
92+
* for compatibility.
93+
* </p>
94+
*/
7795
private void initializeLicenseModelStore() {
7896
listedLicenseModificationLock.writeLock().lock();
7997
try {
@@ -100,10 +118,18 @@ private void initializeLicenseModelStore() {
100118
}
101119
}
102120

103-
104-
121+
/**
122+
* Retrieve the singleton instance of the {@code ListedLicenses} class
123+
* <p>
124+
* This method ensures that only one instance of the {@code ListedLicenses}
125+
* class is created and shared
126+
* throughout the application. If the instance does not already exist, it
127+
* initializes it.
128+
* </p>
129+
*
130+
* @return The singleton instance of the {@code ListedLicenses} class.
131+
*/
105132
public static ListedLicenses getListedLicenses() {
106-
107133
ListedLicenses retval;
108134
listedLicenseModificationLock.readLock().lock();
109135
try {
@@ -124,12 +150,15 @@ public static ListedLicenses getListedLicenses() {
124150
}
125151
return retval;
126152
}
127-
153+
128154
/**
129-
* Resets all of the cached license information and reloads the license IDs
130-
* NOTE: This method should be used with caution, it will negatively impact
131-
* performance.
132-
* @return a new instance of this class
155+
* Reset all cached license information and reload the license IDs
156+
* <p>
157+
* NOTE: This method should be used with caution as it can negatively
158+
* impact performance due to the reloading process.
159+
* </p>
160+
*
161+
* @return A new instance of the {@code ListedLicenses} class.
133162
*/
134163
public static ListedLicenses resetListedLicenses() {
135164
listedLicenseModificationLock.writeLock().lock();
@@ -140,58 +169,86 @@ public static ListedLicenses resetListedLicenses() {
140169
listedLicenseModificationLock.writeLock().unlock();
141170
}
142171
}
143-
144172

145173
/**
146-
* @param licenseId case insensitive
147-
* @return true if the licenseId belongs to an SPDX listed license
174+
* Check whether the given license ID belongs to an SPDX listed license
175+
*
176+
* @param licenseId The case-insensitive SPDX license ID.
177+
* @return {@code true} if the license ID belongs to an SPDX listed license,
178+
* {@code false} otherwise.
148179
*/
149180
public boolean isSpdxListedLicenseId(String licenseId) {
150181
return baseModelStore.isSpdxListedLicenseId(SpdxConstantsCompatV2.LISTED_LICENSE_NAMESPACE_PREFIX, licenseId);
151182
}
152-
153-
/**
154-
* @param exceptionId case insensitive
155-
* @return true if the exceptionId belongs to an SPDX listed exception
156-
*/
183+
184+
/**
185+
* Check whether the given exception ID belongs to an SPDX listed exception
186+
*
187+
* @param exceptionId The case-insensitive SPDX exception ID to check.
188+
* @return {@code true} if the exception ID belongs to an SPDX listed exception,
189+
* {@code false} otherwise.
190+
*/
157191
public boolean isSpdxListedExceptionId(String exceptionId) {
158192
return this.baseModelStore.isSpdxListedExceptionId(SpdxConstantsCompatV2.LISTED_LICENSE_NAMESPACE_PREFIX, exceptionId);
159193
}
160-
194+
161195
/**
162-
* @param licenseId SPDX Listed License ID
163-
* @return an SPDX spec version 2 SPDX listed license or null if the ID is not in the SPDX license list
164-
* @throws InvalidSPDXAnalysisException on SPDX parsing error
196+
* Retrieve an SPDX listed license by its ID
197+
* for SPDX specification version 2 compatibility
198+
*
199+
* @param licenseId The SPDX Listed License ID.
200+
* @return The SPDX specification version 2 listed license, or {@code null} if
201+
* the ID is not in the SPDX License List.
202+
* @throws InvalidSPDXAnalysisException If an error occurs while retrieving the
203+
* license.
165204
*/
166205
public SpdxListedLicense getListedLicenseByIdCompatV2(String licenseId) throws InvalidSPDXAnalysisException {
167206
return getSpdxListedLicensesCompatV2().get(licenseId);
168207
}
169-
208+
170209
/**
171-
* @param exceptionId SPDX Listed License Exception ID
172-
* @return an SPDX spec version 2 SPDX listed license exception or null if the ID is not in the SPDX license list
173-
* @throws InvalidSPDXAnalysisException on SPDX parsing error
210+
* Retrieve an SPDX listed license exception by its ID
211+
* for SPDX specification version 2 compatibility
212+
*
213+
* @param exceptionId The SPDX Listed License Exception ID.
214+
* @return The SPDX specification version 2 listed license exception, or
215+
* {@code null} if the ID is not in the SPDX License List.
216+
* @throws InvalidSPDXAnalysisException If an error occurs while retrieving the
217+
* exception.
174218
*/
175-
public org.spdx.library.model.v2.license.ListedLicenseException getListedExceptionByIdCompatV2(String exceptionId) throws InvalidSPDXAnalysisException {
219+
public org.spdx.library.model.v2.license.ListedLicenseException getListedExceptionByIdCompatV2(String exceptionId)
220+
throws InvalidSPDXAnalysisException {
176221
return getSpdxListedLicenseExceptionsCompatV2().get(exceptionId);
177222
}
178-
223+
179224
/**
180-
* @param licenseId SPDX Listed License ID
181-
* @return SPDX listed license or null if the ID is not in the SPDX license list
182-
* @throws InvalidSPDXAnalysisException on SPDX parsing error
225+
* Retrieve an SPDX listed license by its ID
226+
*
227+
* @param licenseId The SPDX Listed License ID.
228+
* @return The SPDX listed license, or {@code null} if not in the SPDX License List.
229+
* @throws InvalidSPDXAnalysisException If an error occurs while retrieving the license.
183230
*/
184231
public ListedLicense getListedLicenseById(String licenseId) throws InvalidSPDXAnalysisException {
185232
return getSpdxListedLicenses().get(licenseId);
186233
}
187-
234+
235+
/**
236+
* Retrieve an SPDX listed license exception by its ID
237+
*
238+
* @param exceptionId The SPDX Listed License Exception ID.
239+
* @return The SPDX listed license exception, or {@code null} if not in the SPDX
240+
* License List.
241+
* @throws InvalidSPDXAnalysisException If an error occurs while retrieving the
242+
* exception.
243+
*/
188244
public ListedLicenseException getListedExceptionById(String exceptionId) throws InvalidSPDXAnalysisException {
189245
return getSpdxListedLicenseExceptions().get(exceptionId);
190-
191246
}
192-
247+
193248
/**
194-
* @return List of all SPDX listed license IDs
249+
* Retrieve a list of all SPDX listed license IDs
250+
*
251+
* @return A list of all SPDX Listed License IDs.
195252
*/
196253
public List<String> getSpdxListedLicenseIds() {
197254
listedLicenseModificationLock.readLock().lock();
@@ -203,8 +260,12 @@ public List<String> getSpdxListedLicenseIds() {
203260
}
204261

205262
/**
206-
* @return a map of SPDX listed license IDs to the SPDX listed license
207-
* @throws InvalidSPDXAnalysisException on errors fetching the licenses
263+
* Retrieve a map of SPDX Listed License IDs to their SPDX listed licenses
264+
*
265+
* @return A map where the keys are SPDX Listed License IDs and the values are
266+
* {@link ListedLicense} objects.
267+
* @throws InvalidSPDXAnalysisException If an error occurs while fetching the
268+
* licenses.
208269
*/
209270
public Map<String, ListedLicense> getSpdxListedLicenses() throws InvalidSPDXAnalysisException {
210271
listedLicenseModificationLock.readLock().lock();
@@ -233,8 +294,13 @@ public Map<String, ListedLicense> getSpdxListedLicenses() throws InvalidSPDXAnal
233294
}
234295

235296
/**
236-
* @return a map of SPDX listed license exception IDs to the SPDX listed license exception
237-
* @throws InvalidSPDXAnalysisException on errors fetching the license exceptions
297+
* Retrieve a map of SPDX Listed License Exception IDs to their SPDX listed
298+
* license exceptions
299+
*
300+
* @return A map where the keys are SPDX Listed License Exception IDs
301+
* and the values are {@link ListedLicenseException} objects.
302+
* @throws InvalidSPDXAnalysisException If an error occurs while fetching the
303+
* license exceptions.
238304
*/
239305
public Map<String, ListedLicenseException> getSpdxListedLicenseExceptions() throws InvalidSPDXAnalysisException {
240306
listedLicenseModificationLock.readLock().lock();
@@ -263,8 +329,13 @@ public Map<String, ListedLicenseException> getSpdxListedLicenseExceptions() thro
263329
}
264330

265331
/**
266-
* @return a map of SPDX listed license IDs to the SPDX Spec version 2 listed license
267-
* @throws InvalidSPDXAnalysisException on errors fetching the licenses
332+
* Retrieve a map of SPDX Listed License IDs to their SPDX listed licenses
333+
* for SPDX specification version 2 compatibility
334+
*
335+
* @return A map where the keys are SPDX Listed License IDs and the values are
336+
* {@link SpdxListedLicense} (SPDX spec version 2) objects.
337+
* @throws InvalidSPDXAnalysisException If an error occurs while fetching the
338+
* licenses.
268339
*/
269340
protected Map<String, SpdxListedLicense> getSpdxListedLicensesCompatV2() throws InvalidSPDXAnalysisException {
270341
listedLicenseModificationLock.readLock().lock();
@@ -294,8 +365,16 @@ protected Map<String, SpdxListedLicense> getSpdxListedLicensesCompatV2() throws
294365
}
295366

296367
/**
297-
* @return a map of SPDX listed license exception IDs to the SPDX listed license exception
298-
* @throws InvalidSPDXAnalysisException on errors fetching the license exceptions
368+
* Retrieve a map of SPDX Listed License Exception IDs to their SPDX listed
369+
* license exceptions
370+
* for SPDX specification version 2 compatibility
371+
*
372+
* @return A map where the keys are SPDX Listed License Exception IDs
373+
* and the values are
374+
* {@link org.spdx.library.model.v2.license.ListedLicenseException}
375+
* (SPDX spec version 2) objects.
376+
* @throws InvalidSPDXAnalysisException If an error occurs while fetching the
377+
* license exceptions.
299378
*/
300379
protected Map<String, org.spdx.library.model.v2.license.ListedLicenseException> getSpdxListedLicenseExceptionsCompatV2() throws InvalidSPDXAnalysisException {
301380
listedLicenseModificationLock.readLock().lock();
@@ -323,55 +402,83 @@ protected Map<String, org.spdx.library.model.v2.license.ListedLicenseException>
323402
listedLicenseModificationLock.writeLock().unlock();
324403
}
325404
}
326-
405+
327406
/**
328-
* @return The version of the loaded license list in the form M.N, where M is the major release and N is the minor release.
329-
* If no license list is loaded, returns the default license list version.
407+
* Retrieve the version of the loaded SPDX license list
408+
* <p>
409+
* The version is returned in the format "M.N", where M is the major release and N is the minor release.
410+
* If no license list is loaded, this method returns the default license list version.
411+
* </p>
412+
*
413+
* @return The version of the loaded SPDX license list, or the default version if no license list is loaded.
330414
*/
331415
public String getLicenseListVersion() {
332416
return this.baseModelStore.getLicenseListVersion();
333417
}
334418

335419
/**
336-
* @return list of SPDX exception IDs
420+
* Retrieve a list of all SPDX listed exception IDs
421+
*
422+
* @return A list of SPDX listed exception IDs.
337423
*/
338424
public List<String> getSpdxListedExceptionIds() {
339425
return this.baseModelStore.getSpdxListedExceptionIds();
340426
}
341427

342428
/**
343-
* @param licenseId case insensitive license ID
344-
* @return the case sensitive license ID
429+
* Retrieve the case-sensitive SPDX license ID for a given case-insensitive
430+
* license ID
431+
*
432+
* @param licenseId The case-insensitive SPDX license ID to look up.
433+
* @return An {@link Optional} containing the case-sensitive license ID if
434+
* found, or an empty {@link Optional} if not found.
345435
*/
346436
public Optional<String> listedLicenseIdCaseSensitive(String licenseId) {
347437
return this.baseModelStore.listedLicenseIdCaseSensitive(licenseId);
348438
}
349439

350440
/**
351-
* @param exceptionId case insensitive exception ID
352-
* @return case sensitive ID
441+
* Retrieve the case-sensitive SPDX exception ID for a given case-insensitive
442+
* exception ID
443+
*
444+
* @param exceptionId The case-insensitive SPDX exception ID to look up.
445+
* @return An {@link Optional} containing the case-sensitive exception ID if
446+
* found, or an empty {@link Optional} if not found.
353447
*/
354448
public Optional<String> listedExceptionIdCaseSensitive(String exceptionId) {
355449
return this.baseModelStore.listedExceptionIdCaseSensitive(exceptionId);
356450
}
357-
451+
358452
/**
359-
* @return model store for listed licenses using the version 3 SPDX model
453+
* Retrieve the model store for listed licenses using the SPDX version 3 model
454+
*
455+
* @return The {@link IModelStore} for SPDX version 3 listed licenses and
456+
* exceptions.
360457
*/
361458
public IModelStore getLicenseModelStore() {
362459
return this.licenseStoreV3;
363460
}
364-
461+
462+
/**
463+
* Retrieve the model store for listed licenses using the SPDX version 2 model
464+
*
465+
* @return The {@link IModelStore} for SPDX version 2 listed licenses and
466+
* exceptions.
467+
*/
365468
public IModelStore getLicenseModelStoreCompatV2() {
366469
return this.licenseStoreV2;
367470
}
368471

369472
/**
370-
* @return the CreationInfo used for all SPDX listed licenses and listed exceptions
371-
* @throws InvalidSPDXAnalysisException on error inflating the creation info
473+
* Retrieve the creation information for all SPDX listed licenses and exceptions
474+
*
475+
* @return The {@link CreationInfo} used for all SPDX listed licenses and
476+
* exceptions.
477+
* @throws InvalidSPDXAnalysisException If an error occurs while inflating the
478+
* creation information.
372479
*/
373480
public CreationInfo getListedLicenseCreationInfo() throws InvalidSPDXAnalysisException {
374481
return licenseStoreV3.getListedLicenseCreationInfo();
375482
}
376483

377-
}
484+
}

0 commit comments

Comments
 (0)