Repository: Wikidata/Wikidata-Toolkit
Pull request #497 (2020-05-25 04:33:38)

Creation of QuantityValues: use ItemIdValue instead of String for unit 

coveralls: 
[![Coverage Status](https://coveralls.io/builds/31005143/badge)](https://coveralls.io/builds/31005143)

Coverage increased (+0.006%) to 84.82% when pulling **5ad0e4d46dc8799edde10b314cabac9ba4836fa5 on kanikasaini:issue459** into **507fdafd2ca8bb991f6e131736a705c231b24780 on Wikidata:master**.

kanikasaini: Thank you for the correction. I have made changes, please see if it is alright now. 

Patch:
diff --git a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/Datamodel.java b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/Datamodel.java
index 91d1c177..84594258 100644
--- a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/Datamodel.java
+++ b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/helpers/Datamodel.java
@@ -380,13 +380,34 @@ public class Datamodel {
 	 * @param unit
 	 *            the unit identifier to use for this quantity
 	 * @return a {@link QuantityValue} corresponding to the input
+	 * @deprecated Use {@link #makeQuantityValue(BigDecimal, BigDecimal, BigDecimal, ItemIdValue)}
 	 */
+	@Deprecated
 	public static QuantityValue makeQuantityValue(BigDecimal numericValue,
 			BigDecimal lowerBound, BigDecimal upperBound, String unit) {
 		return factory.getQuantityValue(numericValue, lowerBound, upperBound,
 				unit);
 	}
 
+	/**
+	 * Creates a {@link QuantityValue}.
+	 *
+	 * @param numericValue
+	 *            the numeric value of this quantity
+	 * @param lowerBound
+	 *            the lower bound of the numeric value of this quantity
+	 * @param upperBound
+	 *            the upper bound of the numeric value of this quantity
+	 * @param unit
+	 *            the unit identifier to use for this quantity
+	 * @return a {@link QuantityValue} corresponding to the input
+	 */
+	public static QuantityValue makeQuantityValue(BigDecimal numericValue,
+			BigDecimal lowerBound, BigDecimal upperBound, ItemIdValue unit) {
+		return factory.getQuantityValue(numericValue, lowerBound, upperBound,
+				unit.getIri());
+	}
+
 	/**
 	 * Creates a {@link QuantityValue} without bounds.
 	 *
@@ -395,11 +416,26 @@ public class Datamodel {
 	 * @param unit
 	 *            the unit identifier to use for this quantity
 	 * @return a {@link QuantityValue} corresponding to the input
+	 * @deprecated Use {@link #makeQuantityValue(BigDecimal, ItemIdValue)}
 	 */
+	@Deprecated
 	public static QuantityValue makeQuantityValue(BigDecimal numericValue, String unit) {
 		return factory.getQuantityValue(numericValue, unit);
 	}
 
+	/**
+	 * Creates a {@link QuantityValue} without bounds.
+	 *
+	 * @param numericValue
+	 *            the numeric value of this quantity
+	 * @param unit
+	 *            the unit identifier to use for this quantity
+	 * @return a {@link QuantityValue} corresponding to the input
+	 */
+	public static QuantityValue makeQuantityValue(BigDecimal numericValue, ItemIdValue unit) {
+		return factory.getQuantityValue(numericValue, unit.getIri());
+	}
+
 	/**
 	 * Creates a {@link QuantityValue} with an empty unit.
 	 *


Test patch:
diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelTest.java
index 9218b16b..76ff7d32 100644
--- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelTest.java
+++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelTest.java
@@ -27,6 +27,7 @@ import java.util.Collections;
 
 import org.junit.Test;
 import org.wikidata.wdtk.datamodel.implementation.DataObjectFactoryImpl;
+import org.wikidata.wdtk.datamodel.implementation.ItemIdValueImpl;
 import org.wikidata.wdtk.datamodel.interfaces.*;
 
 public class DatamodelTest {
@@ -203,6 +204,21 @@ public class DatamodelTest {
 		assertEquals(o1, o2);
 	}
 
+	@Test
+	public final void testGetQuantityValueItemIdValue() {
+		BigDecimal nv = new BigDecimal(
+				"0.123456789012345678901234567890123456789");
+		BigDecimal lb = new BigDecimal(
+				"0.123456789012345678901234567890123456788");
+		BigDecimal ub = new BigDecimal(
+				"0.123456789012345678901234567890123456790");
+		
+		ItemIdValue unit = factory.getItemIdValue("Q1", "http://www.wikidata.org/entity/");
+		QuantityValue o1 = Datamodel.makeQuantityValue(nv, lb, ub, unit);
+		QuantityValue o2 = factory.getQuantityValue(nv, lb, ub, unit.getIri());
+		assertEquals(o1, o2);
+	}
+
 	@Test
 	public final void testGetQuantityValueNoUnit() {
 		BigDecimal nv = new BigDecimal(
@@ -225,6 +241,16 @@ public class DatamodelTest {
 		assertEquals(o1, o2);
 	}
 
+	@Test
+	public final void testGetQuantityValueNoBoundsItemIdValue() {
+		BigDecimal nv = new BigDecimal(
+				"0.123456789012345678901234567890123456789");
+		ItemIdValue unit = factory.getItemIdValue("Q1", "http://www.wikidata.org/entity/");
+		QuantityValue o1 = Datamodel.makeQuantityValue(nv, unit);
+		QuantityValue o2 = factory.getQuantityValue(nv, unit.getIri());
+		assertEquals(o1, o2);
+	}
+
 	@Test
 	public final void testGetQuantityValueNoBoundsAndUnits() {
 		BigDecimal nv = new BigDecimal(