Skip to content

Commit 541d1d5

Browse files
bactgoneall
authored andcommitted
Add javadoc to StoredTypedItem
Signed-off-by: Arthit Suriyawongkul <[email protected]>
1 parent 392f6d5 commit 541d1d5

File tree

1 file changed

+103
-44
lines changed

1 file changed

+103
-44
lines changed

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

Lines changed: 103 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,32 @@ public class StoredTypedItem extends TypedValue {
5858
private int referenceCount = 0;
5959

6060
private final ReadWriteLock countLock = new ReentrantReadWriteLock();
61-
61+
62+
/**
63+
* Construct a new {@link StoredTypedItem} with the specified object URI, type, and
64+
* specification version
65+
* <p>
66+
* This constructor initializes a stored typed item, which represents an individual item to be
67+
* stored in memory with its associated properties and metadata.
68+
*
69+
* @param objectUri The unique URI identifying this stored item.
70+
* @param type The type of the stored item.
71+
* @param specVersion The version of the SPDX specification associated with this item.
72+
* @throws InvalidSPDXAnalysisException If the provided parameters are invalid or violate SPDX
73+
* constraints.
74+
*/
6275
public StoredTypedItem(String objectUri, String type, String specVersion) throws InvalidSPDXAnalysisException {
6376
super(objectUri, type, specVersion);
6477
}
65-
78+
6679
/**
67-
* @return property descriptors for all properties having a value
80+
* Retrieve the property descriptors for all properties that have a value
81+
* <p>
82+
* This method iterates through the stored properties and collects the descriptors
83+
* for all properties that currently have an associated value.
84+
*
85+
* @return An unmodifiable {@link List} of {@link PropertyDescriptor} objects representing
86+
* the properties that have values.
6887
*/
6988
public List<PropertyDescriptor> getPropertyValueDescriptors() {
7089
Iterator<Entry<PropertyDescriptor, Object>> iter = this.properties.entrySet().iterator();
@@ -75,9 +94,10 @@ public List<PropertyDescriptor> getPropertyValueDescriptors() {
7594
}
7695
return Collections.unmodifiableList(retval);
7796
}
78-
97+
7998
/**
8099
* Increment the reference count for this stored type item - the number of times this item is referenced
100+
*
81101
* @return new number of times this item is referenced
82102
*/
83103
@SuppressWarnings("UnusedReturnValue")
@@ -93,6 +113,7 @@ public int incReferenceCount() {
93113

94114
/**
95115
* Decrement the reference count for this stored type item
116+
*
96117
* @return new number of times this item is referenced
97118
* @throws SpdxInvalidTypeException on invalid type
98119
*/
@@ -108,9 +129,11 @@ public int decReferenceCount() throws SpdxInvalidTypeException {
108129
countLock.writeLock().unlock();
109130
}
110131
}
111-
112-
/**
113-
* @return new number of times this item is referenced
132+
133+
/**
134+
* Retrieve the current reference count for this stored item
135+
*
136+
* @return The current number of times this item is referenced.
114137
*/
115138
public int getReferenceCount() {
116139
countLock.readLock().lock();
@@ -120,13 +143,16 @@ public int getReferenceCount() {
120143
countLock.readLock().unlock();
121144
}
122145
}
123-
146+
124147
/**
148+
* Set the value for the specified property descriptor
149+
*
125150
* @param propertyDescriptor Descriptor for the property
126151
* @param value Value to be set
127152
* @throws SpdxInvalidTypeException on invalid type
128153
*/
129-
public void setValue(PropertyDescriptor propertyDescriptor, Object value) throws SpdxInvalidTypeException {
154+
public void setValue(PropertyDescriptor propertyDescriptor, Object value)
155+
throws SpdxInvalidTypeException {
130156
Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null");
131157
Objects.requireNonNull(value, "Value can not be null");
132158
if (value instanceof CoreModelObject) {
@@ -145,14 +171,17 @@ public void setValue(PropertyDescriptor propertyDescriptor, Object value) throws
145171
}
146172
properties.put(propertyDescriptor, value);
147173
}
148-
174+
149175
/**
150-
* Sets the value list for the property to an empty list creating the propertyDescriptor if it does not exist
176+
* Set the value list for the property to an empty list creating the propertyDescriptor if it
177+
* does not exist
178+
*
151179
* @param propertyDescriptor descriptor for the property
152180
* @throws SpdxInvalidTypeException on invalid type
153181
*/
154-
public void clearPropertyValueList(PropertyDescriptor propertyDescriptor) throws SpdxInvalidTypeException {
155-
Objects.requireNonNull(propertyDescriptor, "property descriptor can not be null");
182+
public void clearPropertyValueList(PropertyDescriptor propertyDescriptor)
183+
throws SpdxInvalidTypeException {
184+
Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null");
156185
Object value = properties.get(propertyDescriptor);
157186
if (value == null) {
158187
return;
@@ -166,12 +195,15 @@ public void clearPropertyValueList(PropertyDescriptor propertyDescriptor) throws
166195
}
167196

168197
/**
169-
* Adds a value to a property list for a String or Boolean type of value creating the propertyDescriptor if it does not exist
198+
* Add a value to a property list for a String or Boolean type of value creating the
199+
* propertyDescriptor if it does not exist
200+
*
170201
* @param propertyDescriptor Descriptor for the property
171202
* @param value Value to be set
172203
* @throws SpdxInvalidTypeException on invalid type
173204
*/
174-
public boolean addValueToList(PropertyDescriptor propertyDescriptor, Object value) throws SpdxInvalidTypeException {
205+
public boolean addValueToList(PropertyDescriptor propertyDescriptor, Object value)
206+
throws SpdxInvalidTypeException {
175207
Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null");
176208
Objects.requireNonNull(value, "Value can not be null");
177209
if (value instanceof CoreModelObject) {
@@ -217,15 +249,17 @@ public boolean addValueToList(PropertyDescriptor propertyDescriptor, Object valu
217249
throw new SpdxInvalidTypeException("Invalid list type for "+propertyDescriptor);
218250
}
219251
}
220-
221252

222253
/**
254+
* Remove a property from a property list if it exists
255+
*
223256
* @param propertyDescriptor descriptor for the property
224257
* @param value to be removed
225-
* @return true if the value was removed, false if the value did not exist
258+
* @return {@code true} if the value was removed, {@code false} if the value did not exist.
226259
* @throws SpdxInvalidTypeException for an invalid type
227260
*/
228-
public boolean removeTypedValueFromList(PropertyDescriptor propertyDescriptor, TypedValue value) throws SpdxInvalidTypeException {
261+
public boolean removeTypedValueFromList(PropertyDescriptor propertyDescriptor, TypedValue value)
262+
throws SpdxInvalidTypeException {
229263
Object map = properties.get(propertyDescriptor);
230264
if (map == null) {
231265
return false;
@@ -247,13 +281,16 @@ public boolean removeTypedValueFromList(PropertyDescriptor propertyDescriptor, T
247281
}
248282

249283
/**
250-
* Removes a property from a list if it exists
284+
* Remove a property from a property list if it exists
285+
*
251286
* @param propertyDescriptor descriptor for the property
252287
* @param value value to remove
288+
* @return {@code true} if the value was removed, {@code false} if the value did not exist.
253289
* @throws SpdxInvalidTypeException on invalid type
254290
*/
255-
public boolean removeValueFromList(PropertyDescriptor propertyDescriptor, Object value) throws SpdxInvalidTypeException {
256-
Objects.requireNonNull(propertyDescriptor, "property descriptor can not be null");
291+
public boolean removeValueFromList(PropertyDescriptor propertyDescriptor, Object value)
292+
throws SpdxInvalidTypeException {
293+
Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null");
257294
Objects.requireNonNull(value, "Value can not be null");
258295
Object map = properties.get(propertyDescriptor);
259296
if (map == null) {
@@ -280,14 +317,20 @@ public boolean removeValueFromList(PropertyDescriptor propertyDescriptor, Object
280317
throw new SpdxInvalidTypeException("Invalid list type for "+propertyDescriptor);
281318
}
282319
}
283-
320+
284321
/**
322+
* Retrieve an iterator over the list of values associated with the specified property
323+
* descriptor
324+
*
285325
* @param propertyDescriptor Descriptor for the property
286-
* @return List of values associated with the objectUri, propertyDescriptor and document
287-
* @throws SpdxInvalidTypeException on invalid type
326+
* @return An {@link Iterator} over the list of values associated with the property descriptor.
327+
* If no values exist, an empty iterator is returned.
328+
* @throws SpdxInvalidTypeException If the property is not associated with a list or if the type
329+
* is invalid.
288330
*/
289-
public Iterator<Object> getValueList(PropertyDescriptor propertyDescriptor) throws SpdxInvalidTypeException {
290-
Objects.requireNonNull(propertyDescriptor, "property descriptor can not be null");
331+
public Iterator<Object> getValueList(PropertyDescriptor propertyDescriptor)
332+
throws SpdxInvalidTypeException {
333+
Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null");
291334
Object list = properties.get(propertyDescriptor);
292335
if (list == null) {
293336
return Collections.emptyIterator();
@@ -306,29 +349,38 @@ public Iterator<Object> getValueList(PropertyDescriptor propertyDescriptor) thro
306349
throw new SpdxInvalidTypeException("Trying to get a list for non list type for property "+propertyDescriptor);
307350
}
308351
}
309-
352+
310353
/**
311-
* @param propertyDescriptor Descriptor for the property
312-
* @return the single value associated with the objectUri, propertyDescriptor and document
354+
* Retrieve the value associated with the specified property descriptor
355+
*
356+
* @param propertyDescriptor The descriptor for the property. Must not be {@code null}.
357+
* @return The single value associated with the specified property descriptor, or {@code null}
358+
* if no value exists.
313359
*/
314360
public Object getValue(PropertyDescriptor propertyDescriptor) {
315-
Objects.requireNonNull(propertyDescriptor, "property descriptor can not be null");
361+
Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null");
316362
return properties.get(propertyDescriptor);
317363
}
318364

319365
/**
320-
* Removes a property from the document for the given ID if the property exists. Does not raise any exception if the propertyDescriptor does not exist
321-
* @param propertyDescriptor Descriptor for the property
366+
* Remove a property from the document for the given ID if the property exists.
367+
* <p>
368+
* Does not raise any exception if the propertyDescriptor does not exist
369+
*
370+
* @param propertyDescriptor The descriptor for the property. Must not be {@code null}.
322371
*/
323372
public void removeProperty(PropertyDescriptor propertyDescriptor) {
324-
Objects.requireNonNull(propertyDescriptor, "property descriptor can not be null");
373+
Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null");
325374
properties.remove(propertyDescriptor);
326375
}
327376

328377
/**
329-
* Copy all values for this item from another store
330-
* @param store model store to copy from
331-
* @throws InvalidSPDXAnalysisException on invalid type
378+
* Copy all values for this item from another model store
379+
*
380+
* @param store The {@link IModelStore} from which to copy values. Must not be {@code null}.
381+
* @throws InvalidSPDXAnalysisException If an invalid type is encountered during the copy
382+
* process. This can occur if the values in the source store are not compatible with
383+
* this item's properties.
332384
*/
333385
public void copyValuesFrom(IModelStore store) throws InvalidSPDXAnalysisException {
334386
Objects.requireNonNull(store, "Store can not be null");
@@ -348,7 +400,7 @@ public void copyValuesFrom(IModelStore store) throws InvalidSPDXAnalysisExceptio
348400
*/
349401
@SuppressWarnings("rawtypes")
350402
public int collectionSize(PropertyDescriptor propertyDescriptor) throws SpdxInvalidTypeException {
351-
Objects.requireNonNull(propertyDescriptor, "property descriptor can not be null");
403+
Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null");
352404
Object map = properties.get(propertyDescriptor);
353405
if (map == null) {
354406
properties.putIfAbsent(propertyDescriptor, new ConcurrentHashMap<String, List<Object>>());
@@ -374,13 +426,20 @@ public int collectionSize(PropertyDescriptor propertyDescriptor) throws SpdxInva
374426
}
375427

376428
/**
377-
* @param propertyDescriptor descriptor for the property
378-
* @param value value to be checked
379-
* @return true if value is in the list associated with the property descriptor
380-
* @throws SpdxInvalidTypeException on invalid type
429+
* Check whether the specified value exists in the list associated with the given property descriptor.
430+
*
431+
* 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+
*
435+
* @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.
381439
*/
382-
public boolean collectionContains(PropertyDescriptor propertyDescriptor, Object value) throws SpdxInvalidTypeException {
383-
Objects.requireNonNull(propertyDescriptor, "property descriptor can not be null");
440+
public boolean collectionContains(PropertyDescriptor propertyDescriptor, Object value)
441+
throws SpdxInvalidTypeException {
442+
Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null");
384443
Objects.requireNonNull(value, "Value can not be null");
385444
Object map = properties.get(propertyDescriptor);
386445
if (map == null) {
@@ -530,4 +589,4 @@ public boolean usesId(String elementId) {
530589
}
531590
return false;
532591
}
533-
}
592+
}

0 commit comments

Comments
 (0)