Skip to content

Commit d4aa068

Browse files
bactgoneall
authored andcommitted
Add "must not be null"
Signed-off-by: Arthit Suriyawongkul <[email protected]>
1 parent 541d1d5 commit d4aa068

File tree

1 file changed

+79
-52
lines changed

1 file changed

+79
-52
lines changed

src/main/java/org/spdx/storage/simple/StoredTypedItem.java

Lines changed: 79 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ public List<PropertyDescriptor> getPropertyValueDescriptors() {
9696
}
9797

9898
/**
99-
* Increment the reference count for this stored type item - the number of times this item is referenced
99+
* Increment the reference count for this stored type item - the number of times this item is
100+
* referenced
100101
*
101-
* @return new number of times this item is referenced
102+
* @return The new number of times this item is referenced.
102103
*/
103104
@SuppressWarnings("UnusedReturnValue")
104105
public int incReferenceCount() {
@@ -114,7 +115,7 @@ public int incReferenceCount() {
114115
/**
115116
* Decrement the reference count for this stored type item
116117
*
117-
* @return new number of times this item is referenced
118+
* @return The new number of times this item is referenced.
118119
* @throws SpdxInvalidTypeException on invalid type
119120
*/
120121
public int decReferenceCount() throws SpdxInvalidTypeException {
@@ -147,8 +148,8 @@ public int getReferenceCount() {
147148
/**
148149
* Set the value for the specified property descriptor
149150
*
150-
* @param propertyDescriptor Descriptor for the property
151-
* @param value Value to be set
151+
* @param propertyDescriptor The descriptor for the property. Must not be {@code null}.
152+
* @param value The value to be set. Must not be {@code null}.
152153
* @throws SpdxInvalidTypeException on invalid type
153154
*/
154155
public void setValue(PropertyDescriptor propertyDescriptor, Object value)
@@ -176,7 +177,7 @@ public void setValue(PropertyDescriptor propertyDescriptor, Object value)
176177
* Set the value list for the property to an empty list creating the propertyDescriptor if it
177178
* does not exist
178179
*
179-
* @param propertyDescriptor descriptor for the property
180+
* @param propertyDescriptor The descriptor for the property. Must not be {@code null}.
180181
* @throws SpdxInvalidTypeException on invalid type
181182
*/
182183
public void clearPropertyValueList(PropertyDescriptor propertyDescriptor)
@@ -198,8 +199,8 @@ public void clearPropertyValueList(PropertyDescriptor propertyDescriptor)
198199
* Add a value to a property list for a String or Boolean type of value creating the
199200
* propertyDescriptor if it does not exist
200201
*
201-
* @param propertyDescriptor Descriptor for the property
202-
* @param value Value to be set
202+
* @param propertyDescriptor The descriptor for the property. Must not be {@code null}.
203+
* @param value Th value to be set. Must not be {@code null}.
203204
* @throws SpdxInvalidTypeException on invalid type
204205
*/
205206
public boolean addValueToList(PropertyDescriptor propertyDescriptor, Object value)
@@ -253,8 +254,8 @@ public boolean addValueToList(PropertyDescriptor propertyDescriptor, Object valu
253254
/**
254255
* Remove a property from a property list if it exists
255256
*
256-
* @param propertyDescriptor descriptor for the property
257-
* @param value to be removed
257+
* @param propertyDescriptor The descriptor for the property.
258+
* @param value The value to be removed.
258259
* @return {@code true} if the value was removed, {@code false} if the value did not exist.
259260
* @throws SpdxInvalidTypeException for an invalid type
260261
*/
@@ -283,8 +284,8 @@ public boolean removeTypedValueFromList(PropertyDescriptor propertyDescriptor, T
283284
/**
284285
* Remove a property from a property list if it exists
285286
*
286-
* @param propertyDescriptor descriptor for the property
287-
* @param value value to remove
287+
* @param propertyDescriptor The descriptor for the property. Must not be {@code null}.
288+
* @param value The value to be removed. Must not be {@code null}.
288289
* @return {@code true} if the value was removed, {@code false} if the value did not exist.
289290
* @throws SpdxInvalidTypeException on invalid type
290291
*/
@@ -322,7 +323,7 @@ public boolean removeValueFromList(PropertyDescriptor propertyDescriptor, Object
322323
* Retrieve an iterator over the list of values associated with the specified property
323324
* descriptor
324325
*
325-
* @param propertyDescriptor Descriptor for the property
326+
* @param propertyDescriptor The descriptor for the property. Must not be {@code null}.
326327
* @return An {@link Iterator} over the list of values associated with the property descriptor.
327328
* If no values exist, an empty iterator is returned.
328329
* @throws SpdxInvalidTypeException If the property is not associated with a list or if the type
@@ -363,9 +364,9 @@ public Object getValue(PropertyDescriptor propertyDescriptor) {
363364
}
364365

365366
/**
366-
* Remove a property from the document for the given ID if the property exists.
367+
* Remove a property from the document for the given ID if the property exists
367368
* <p>
368-
* Does not raise any exception if the propertyDescriptor does not exist
369+
* Does not raise any exception if the propertyDescriptor does not exist.
369370
*
370371
* @param propertyDescriptor The descriptor for the property. Must not be {@code null}.
371372
*/
@@ -394,9 +395,15 @@ public void copyValuesFrom(IModelStore store) throws InvalidSPDXAnalysisExceptio
394395
}
395396

396397
/**
397-
* @param propertyDescriptor descriptor for the property
398-
* @return Size of the collection
399-
* @throws SpdxInvalidTypeException on invalid type
398+
* Retrieve the size of the collection associated with the specified property descriptor
399+
* <p>
400+
* This method calculates the total number of elements in the collection associated with the
401+
* given property descriptor.
402+
*
403+
* @param propertyDescriptor The descriptor for the property. Must not be {@code null}.
404+
* @return The size of the collection.
405+
* @throws SpdxInvalidTypeException If the type is invalid or if the property is not associated
406+
* with a collection.
400407
*/
401408
@SuppressWarnings("rawtypes")
402409
public int collectionSize(PropertyDescriptor propertyDescriptor) throws SpdxInvalidTypeException {
@@ -412,7 +419,7 @@ public int collectionSize(PropertyDescriptor propertyDescriptor) throws SpdxInva
412419
}
413420
if (map instanceof ConcurrentHashMap<?, ?>) {
414421
int count = 0;
415-
for (Object value:((ConcurrentHashMap<?, ?>)map).values()) {
422+
for (Object value : ((ConcurrentHashMap<?, ?>) map).values()) {
416423
if (value instanceof Collection) {
417424
count = count + ((Collection)value).size();
418425
} else {
@@ -426,16 +433,17 @@ public int collectionSize(PropertyDescriptor propertyDescriptor) throws SpdxInva
426433
}
427434

428435
/**
429-
* Check whether the specified value exists in the list associated with the given property descriptor.
430-
*
436+
* Check whether the specified value exists in the collection associated with the given property
437+
* descriptor
438+
* <p>
431439
* This method verifies if the provided value is present in the collection of values associated
432-
* with the specified property descriptor. If the property descriptor is not associated with a list,
433-
* an exception is thrown.
434-
*
440+
* with the specified property descriptor.
441+
*
435442
* @param propertyDescriptor The descriptor for the property. Must not be {@code null}.
436-
* @param value The value to be checked.
437-
* @return {@code true} if the value exists in the list associated with the property descriptor; {@code false} otherwise.
438-
* @throws SpdxInvalidTypeException If the property is not associated with a list or if the type is invalid.
443+
* @param value The value to be checked. Must not be {@code null}.
444+
* @return {@code true} if the value exists in the collection; {@code false} otherwise.
445+
* @throws SpdxInvalidTypeException If the type is invalid or if the property is not associated
446+
* with a collection.
439447
*/
440448
public boolean collectionContains(PropertyDescriptor propertyDescriptor, Object value)
441449
throws SpdxInvalidTypeException {
@@ -470,12 +478,17 @@ public boolean collectionContains(PropertyDescriptor propertyDescriptor, Object
470478
}
471479

472480
/**
473-
* @param propertyDescriptor descriptor for the property
474-
* @param clazz class to test against
475-
* @return true if the property with the propertyDescriptor can be assigned to clazz
476-
* @throws ModelRegistryException On registry exception - check that it is initialized
481+
* Check whether all members of the collection associated with the specified property descriptor
482+
* can be assigned to the specified class
483+
*
484+
* @param propertyDescriptor The descriptor for the property. Must not be {@code null}.
485+
* @param clazz The class to test against. Must not be {@code null}.
486+
* @return {@code true} if the property with the {@code propertyDescriptor} can be assigned to
487+
* {@code clazz}; {@code false} otherwise.
488+
* @throws ModelRegistryException If the model registry is not properly initialized.
477489
*/
478-
public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class<?> clazz) throws ModelRegistryException {
490+
public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor,
491+
Class<?> clazz) throws ModelRegistryException {
479492
Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null");
480493
Objects.requireNonNull(clazz, "Class can not be null");
481494
Object map = properties.get(propertyDescriptor);
@@ -488,24 +501,27 @@ public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescri
488501
}
489502
@SuppressWarnings("unchecked")
490503
ConcurrentHashMap<String, List<Object>> idValueMap = (ConcurrentHashMap<String, List<Object>>)map;
491-
for (List<Object> valueList:idValueMap.values()) {
492-
for (Object value:valueList) {
504+
for (List<Object> valueList : idValueMap.values()) {
505+
for (Object value : valueList) {
493506
if (!isAssignableTo(value, clazz, getSpecVersion())) {
494507
return false;
495508
}
496509
}
497510
}
498511
return true;
499512
}
500-
513+
501514
/**
502-
* @param value value to test
503-
* @param clazz class to see if the value can be assigned to
504-
* @param specVersion version of the spec
505-
* @return true if value can be assigned to clazz
506-
* @throws ModelRegistryException if the model registry is not property initialized
515+
* Check whether the given value can be assigned to the specified class
516+
*
517+
* @param value The value to test.
518+
* @param clazz The class to check if the value can be assigned to.
519+
* @param specVersion The SPDX specification version to use for type resolution.
520+
* @return {@code true} if the value can be assigned to {@code clazz}; {@code false} otherwise.
521+
* @throws ModelRegistryException If the model registry is not properly initialized.
507522
*/
508-
private boolean isAssignableTo(Object value, Class<?> clazz, String specVersion) throws ModelRegistryException {
523+
private boolean isAssignableTo(Object value, Class<?> clazz, String specVersion)
524+
throws ModelRegistryException {
509525
if (clazz.isAssignableFrom(value.getClass())) {
510526
return true;
511527
}
@@ -538,15 +554,20 @@ private boolean isAssignableTo(Object value, Class<?> clazz, String specVersion)
538554
return false;
539555
}
540556
}
541-
557+
542558
/**
543-
* @param propertyDescriptor descriptor for the property
544-
* @param clazz class to test against
545-
* @param specVersion Version of the spec to test for
546-
* @return true if the property can be assigned to type clazz for the latest SPDX spec version
547-
* @throws ModelRegistryException if the registry is not property initialized
559+
* Check whether the value associated with the specified property descriptor can be assigned to
560+
* the specified class
561+
*
562+
* @param propertyDescriptor The descriptor for the property. Must not be {@code null}.
563+
* @param clazz The class to test against. Must not be {@code null}.
564+
* @param specVersion The SPDX specification version to use for type resolution.
565+
* @return {@code true} if the property value can be assigned to type {@code clazz} for the
566+
* latest SPDX spec version; {@code false} otherwise.
567+
* @throws ModelRegistryException If the model registry is not properly initialized.
548568
*/
549-
public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor, Class<?> clazz, String specVersion) throws ModelRegistryException {
569+
public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor,
570+
Class<?> clazz, String specVersion) throws ModelRegistryException {
550571
Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null");
551572
Objects.requireNonNull(clazz, "Class can not be null");
552573
Object value = properties.get(propertyDescriptor);
@@ -557,8 +578,11 @@ public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor
557578
}
558579

559580
/**
560-
* @param propertyDescriptor property descriptor
561-
* @return true if there is a list associated with the property descriptor
581+
* Check whether the specified property descriptor is associated with a collection
582+
*
583+
* @param propertyDescriptor The property descriptor to check. Must not be {@code null}.
584+
* @return {@code true} if the property descriptor is associated with a collection;
585+
* {@code false} otherwise.
562586
*/
563587
public boolean isCollectionProperty(PropertyDescriptor propertyDescriptor) {
564588
Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null");
@@ -567,8 +591,11 @@ public boolean isCollectionProperty(PropertyDescriptor propertyDescriptor) {
567591
}
568592

569593
/**
570-
* @param elementId objectUri for the element to check
571-
* @return true if an element using the objectUri is used as a value in a collection
594+
* Check whether the specified element ID is used as a value in any collection or property
595+
*
596+
* @param elementId The object URI of the element to check.
597+
* @return {@code true} if the element using the object URI is used as a value in a collection;
598+
* {@code false} otherwise.
572599
*/
573600
public boolean usesId(String elementId) {
574601
if (Objects.isNull(elementId)) {

0 commit comments

Comments
 (0)