Skip to content

Commit

Permalink
Functions added to make quantity values using ItemIdValue instead of …
Browse files Browse the repository at this point in the history
…String
  • Loading branch information
kanikasaini committed May 24, 2020
1 parent 507fdaf commit 5ad0e4d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Expand Up @@ -380,13 +380,34 @@ public static MonolingualTextValue makeMonolingualTextValue(String text,
* @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.getId());
}

/**
* Creates a {@link QuantityValue} without bounds.
*
Expand All @@ -395,11 +416,26 @@ public static QuantityValue makeQuantityValue(BigDecimal numericValue,
* @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.getId());
}

/**
* Creates a {@link QuantityValue} with an empty unit.
*
Expand Down
Expand Up @@ -27,6 +27,7 @@

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 {
Expand Down Expand Up @@ -203,6 +204,21 @@ public final void testGetQuantityValue() {
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", "foo");
QuantityValue o1 = Datamodel.makeQuantityValue(nv, lb, ub, unit);
QuantityValue o2 = factory.getQuantityValue(nv, lb, ub, unit.getId());
assertEquals(o1, o2);
}

@Test
public final void testGetQuantityValueNoUnit() {
BigDecimal nv = new BigDecimal(
Expand All @@ -225,6 +241,16 @@ public final void testGetQuantityValueNoBounds() {
assertEquals(o1, o2);
}

@Test
public final void testGetQuantityValueNoBoundsItemIdValue() {
BigDecimal nv = new BigDecimal(
"0.123456789012345678901234567890123456789");
ItemIdValue unit = factory.getItemIdValue("Q1", "foo");
QuantityValue o1 = Datamodel.makeQuantityValue(nv, unit);
QuantityValue o2 = factory.getQuantityValue(nv, unit.getId());
assertEquals(o1, o2);
}

@Test
public final void testGetQuantityValueNoBoundsAndUnits() {
BigDecimal nv = new BigDecimal(
Expand Down

0 comments on commit 5ad0e4d

Please sign in to comment.