001/******************************************************************************* 002 * Crown Copyright (c) 2006 - 2014, Copyright (c) 2006 - 2014 Kestral Computing P/L. 003 * All rights reserved. This program and the accompanying materials 004 * are made available under the terms of the Eclipse Public License v1.0 005 * which accompanies this distribution, and is available at 006 * http://www.eclipse.org/legal/epl-v10.html 007 * 008 * Contributors: 009 * Kestral Computing P/L - initial implementation 010 *******************************************************************************/ 011 012package org.hl7.fhir.utilities.ucum; 013 014import java.util.ArrayList; 015import java.util.List; 016 017import org.hl7.fhir.exceptions.UcumException; 018 019 020public class Canonical { 021 022 public static class CanonicalUnit { 023 private BaseUnit base; 024 private int exponent; 025 protected CanonicalUnit(BaseUnit base, int exponent) { 026 super(); 027 this.base = base; 028 this.exponent = exponent; 029 } 030 public BaseUnit getBase() { 031 return base; 032 } 033 public int getExponent() { 034 return exponent; 035 } 036 public void setExponent(int exponent) { 037 this.exponent = exponent; 038 } 039 040 041 } 042 043 private Decimal value; 044 private List<CanonicalUnit> units = new ArrayList<CanonicalUnit>(); 045 046 /** 047 * @param value 048 * @param unit 049 */ 050 public Canonical(Decimal value) { 051 super(); 052 this.value = value; 053 } 054 055 /** 056 * @return the value 057 */ 058 public Decimal getValue() { 059 return value; 060 } 061 062 /** 063 * @return the unit 064 */ 065 public List<CanonicalUnit> getUnits() { 066 return units; 067 } 068 069 /** 070 * @param value the value to set 071 */ 072 public void setValue(Decimal value) { 073 this.value = value; 074 } 075 076 public void multiplyValue(Decimal multiplicand) { 077 value = value.multiply(multiplicand); 078 } 079 080 public void multiplyValue(int multiplicand) { 081 value = value.multiply(new Decimal(multiplicand)); 082 } 083 084 085 public void divideValue(Decimal divisor) throws UcumException { 086 value = value.divide(divisor); 087 } 088 089 public void divideValue(int divisor) throws UcumException { 090 value = value.divide(new Decimal(divisor)); 091 } 092 093 094}