Skip to content

Commit ad7efcf

Browse files
committed
Add support for properties of type Double
Fixes #14
1 parent 0d9c2d9 commit ad7efcf

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/main/java/org/spdx/core/CoreModelObject.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,25 @@ public Optional<Integer> getIntegerPropertyValue(PropertyDescriptor propertyDesc
399399
}
400400
return retval;
401401
}
402+
403+
/**
404+
* @param propertyDescriptor Descriptor for a property
405+
* @return the Optional Double value associated with a property, null if no value is present
406+
* @throws InvalidSPDXAnalysisException on any SPDX related exception
407+
*/
408+
public Optional<Double> getDoublePropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException {
409+
Optional<Object> result = getObjectPropertyValue(propertyDescriptor, Double.class);
410+
Optional<Double> retval;
411+
if (result.isPresent()) {
412+
if (!(result.get() instanceof Double)) {
413+
throw new SpdxInvalidTypeException(PROPERTY_MSG+propertyDescriptor+" is not of type Double");
414+
}
415+
retval = Optional.of((Double)result.get());
416+
} else {
417+
retval = Optional.empty();
418+
}
419+
return retval;
420+
}
402421

403422
/**
404423
* @param propertyDescriptor descriptor for the property

src/main/java/org/spdx/core/ModelObjectHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ public static Object modelObjectToStoredObject(Object value, IModelStore modelSt
233233
} else {
234234
return mValue.toTypedValue();
235235
}
236-
} else if (value instanceof Integer || value instanceof String || value instanceof Boolean) {
236+
} else if (value instanceof Integer || value instanceof String ||
237+
value instanceof Boolean || value instanceof Double) {
237238
return value;
238239
} else if (Objects.isNull(value)) {
239240
throw new SpdxInvalidTypeException("Property value is null");

0 commit comments

Comments
 (0)