/** * Checks if the given value is a number with precision +/-1. * * @param quantityValue * @return */ protected boolean isPlusMinusOneValue(QuantityValue quantityValue) { BigDecimal valueSucc = quantityValue.getNumericValue().add( BigDecimal.ONE); BigDecimal valuePrec = quantityValue.getNumericValue().subtract( BigDecimal.ONE); return (quantityValue.getLowerBound().equals(valuePrec) && quantityValue.getUpperBound().equals(valueSucc) && "1" .equals(quantityValue.getUnit())); }
/** * Returns a human-readable string representation of the given object. * * @see java.lang.Object#toString() * @param o * the object to represent as string * @return a string representation of the object */ public static String toString(QuantityValue o) { String str = o.getNumericValue().toString(); if(o.getLowerBound() != null && o.getUpperBound() != null) { str += " [" + o.getLowerBound().toString() + " .. " + o.getUpperBound().toString() + "]"; } if(!"1".equals(o.getUnit())) { str += " " + o.getUnit(); } return str; }
/** * Returns a human-readable string representation of the given object. * * @see java.lang.Object#toString() * @param o * the object to represent as string * @return a string representation of the object */ public static String toString(QuantityValue o) { String str = o.getNumericValue().toString(); if(o.getLowerBound() != null && o.getUpperBound() != null) { str += " [" + o.getLowerBound().toString() + " .. " + o.getUpperBound().toString() + "]"; } if(!"1".equals(o.getUnit())) { str += " " + o.getUnit(); } return str; }
/** * Checks if the given value is a number with precision +/-1. * * @param quantityValue * @return */ protected boolean isPlusMinusOneValue(QuantityValue quantityValue) { BigDecimal valueSucc = quantityValue.getNumericValue().add( BigDecimal.ONE); BigDecimal valuePrec = quantityValue.getNumericValue().subtract( BigDecimal.ONE); return (quantityValue.getLowerBound().equals(valuePrec) && quantityValue.getUpperBound().equals(valueSucc) && "" .equals(quantityValue.getUnit())); }
public static String getQuantityValueUri(QuantityValue value) { md.reset(); updateMessageDigestWithInt(md, value.getNumericValue().hashCode()); if(value.getLowerBound() != null) { updateMessageDigestWithInt(md, value.getLowerBound().hashCode()); } if(value.getUpperBound() != null) { updateMessageDigestWithInt(md, value.getUpperBound().hashCode()); } updateMessageDigestWithInt(md, value.getUnit().hashCode()); return PREFIX_WIKIDATA_VALUE + bytesToHex(md.digest()); }
/** * Returns a hash code for the given object. * * @see java.lang.Object#hashCode() * @param o * the object to create a hash for * @return the hash code of the object */ public static int hashCode(QuantityValue o) { int result; result = o.getNumericValue().hashCode(); result = prime * result + o.getUnit().hashCode(); if(o.getLowerBound() != null) { result = prime * result + o.getLowerBound().hashCode(); } if(o.getUpperBound() != null) { result = prime * result + o.getUpperBound().hashCode(); } return result; }
/** * Returns a hash code for the given object. * * @see java.lang.Object#hashCode() * @param o * the object to create a hash for * @return the hash code of the object */ public static int hashCode(QuantityValue o) { int result; result = o.getNumericValue().hashCode(); result = prime * result + o.getUnit().hashCode(); if(o.getLowerBound() != null) { result = prime * result + o.getLowerBound().hashCode(); } if(o.getUpperBound() != null) { result = prime * result + o.getUpperBound().hashCode(); } return result; }
/** * Copies a {@link QuantityValue}. * * @param object * object to copy * @return copied object */ public QuantityValue copy(QuantityValue object) { return dataObjectFactory.getQuantityValue( object.getNumericValue(), object.getLowerBound(), object.getUpperBound(), object.getUnit()); }
@Override public void writeValue(QuantityValue value, Resource resource) throws RDFHandlerException { this.rdfWriter.writeTripleValueObject(resource, RdfWriter.RDF_TYPE, RdfWriter.WB_QUANTITY_VALUE); this.rdfWriter.writeTripleLiteralObject(resource, RdfWriter.WB_QUANTITY_AMOUNT, value.getNumericValue().toString(), RdfWriter.XSD_DECIMAL); if(value.getLowerBound() != null) { this.rdfWriter.writeTripleLiteralObject(resource, RdfWriter.WB_QUANTITY_LOWER_BOUND, value.getLowerBound().toString(), RdfWriter.XSD_DECIMAL); } if(value.getUpperBound() != null) { this.rdfWriter.writeTripleLiteralObject(resource, RdfWriter.WB_QUANTITY_UPPER_BOUND, value.getUpperBound().toString(), RdfWriter.XSD_DECIMAL); } String unitIri = ("1".equals(value.getUnit())) ? Vocabulary.WB_NO_UNIT : value.getUnit(); this.rdfWriter.writeTripleUriObject(resource, RdfWriter.WB_QUANTITY_UNIT, unitIri); }
/** * Copies a {@link QuantityValue}. * * @param object * object to copy * @return copied object */ public QuantityValue copy(QuantityValue object) { return dataObjectFactory.getQuantityValue( object.getNumericValue(), object.getLowerBound(), object.getUpperBound(), object.getUnit()); }
/** * Returns true if the parameters are two {@link QuantityValue} objects with * exactly the same data. It does not matter if they are different * implementations of the interface as long as their content is the same. * * @param o1 * the first object to compare * @param o2 * the second object to compare * @return true if both objects are equal */ public static boolean equalsQuantityValue(QuantityValue o1, Object o2) { if (o2 == null) { return false; } if (o2 == o1) { return true; } if (!(o2 instanceof QuantityValue)) { return false; } QuantityValue other = (QuantityValue) o2; return o1.getNumericValue().equals(other.getNumericValue()) && equalsNullable(o1.getLowerBound(), other.getLowerBound()) && equalsNullable(o1.getUpperBound(), other.getUpperBound()) && o1.getUnit().equals(other.getUnit()); }
/** * Returns true if the parameters are two {@link QuantityValue} objects with * exactly the same data. It does not matter if they are different * implementations of the interface as long as their content is the same. * * @param o1 * the first object to compare * @param o2 * the second object to compare * @return true if both objects are equal */ public static boolean equalsQuantityValue(QuantityValue o1, Object o2) { if (o2 == null) { return false; } if (o2 == o1) { return true; } if (!(o2 instanceof QuantityValue)) { return false; } QuantityValue other = (QuantityValue) o2; return o1.getNumericValue().equals(other.getNumericValue()) && equalsNullable(o1.getLowerBound(), other.getLowerBound()) && equalsNullable(o1.getUpperBound(), other.getUpperBound()) && o1.getUnit().equals(other.getUnit()); }