001package org.hl7.fhir.instance.model; 002 003/* 004 Copyright (c) 2011+, HL7, Inc. 005 All rights reserved. 006 007 Redistribution and use in source and binary forms, with or without modification, 008 are permitted provided that the following conditions are met: 009 010 * Redistributions of source code must retain the above copyright notice, this 011 list of conditions and the following disclaimer. 012 * Redistributions in binary form must reproduce the above copyright notice, 013 this list of conditions and the following disclaimer in the documentation 014 and/or other materials provided with the distribution. 015 * Neither the name of HL7 nor the names of its contributors may be used to 016 endorse or promote products derived from this software without specific 017 prior written permission. 018 019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 022 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 023 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 024 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 025 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 026 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 027 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 028 POSSIBILITY OF SUCH DAMAGE. 029 030*/ 031 032// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2 033import java.util.List; 034 035import org.hl7.fhir.exceptions.FHIRException; 036import org.hl7.fhir.instance.model.api.ICompositeType; 037 038import ca.uhn.fhir.model.api.annotation.*; 039/** 040 * A relationship of two Quantity values - expressed as a numerator and a denominator. 041 */ 042@DatatypeDef(name="Ratio") 043public class Ratio extends Type implements ICompositeType { 044 045 /** 046 * The value of the numerator. 047 */ 048 @Child(name = "numerator", type = {Quantity.class}, order=0, min=0, max=1, modifier=false, summary=true) 049 @Description(shortDefinition="Numerator value", formalDefinition="The value of the numerator." ) 050 protected Quantity numerator; 051 052 /** 053 * The value of the denominator. 054 */ 055 @Child(name = "denominator", type = {Quantity.class}, order=1, min=0, max=1, modifier=false, summary=true) 056 @Description(shortDefinition="Denominator value", formalDefinition="The value of the denominator." ) 057 protected Quantity denominator; 058 059 private static final long serialVersionUID = 479922563L; 060 061 /* 062 * Constructor 063 */ 064 public Ratio() { 065 super(); 066 } 067 068 /** 069 * @return {@link #numerator} (The value of the numerator.) 070 */ 071 public Quantity getNumerator() { 072 if (this.numerator == null) 073 if (Configuration.errorOnAutoCreate()) 074 throw new Error("Attempt to auto-create Ratio.numerator"); 075 else if (Configuration.doAutoCreate()) 076 this.numerator = new Quantity(); // cc 077 return this.numerator; 078 } 079 080 public boolean hasNumerator() { 081 return this.numerator != null && !this.numerator.isEmpty(); 082 } 083 084 /** 085 * @param value {@link #numerator} (The value of the numerator.) 086 */ 087 public Ratio setNumerator(Quantity value) { 088 this.numerator = value; 089 return this; 090 } 091 092 /** 093 * @return {@link #denominator} (The value of the denominator.) 094 */ 095 public Quantity getDenominator() { 096 if (this.denominator == null) 097 if (Configuration.errorOnAutoCreate()) 098 throw new Error("Attempt to auto-create Ratio.denominator"); 099 else if (Configuration.doAutoCreate()) 100 this.denominator = new Quantity(); // cc 101 return this.denominator; 102 } 103 104 public boolean hasDenominator() { 105 return this.denominator != null && !this.denominator.isEmpty(); 106 } 107 108 /** 109 * @param value {@link #denominator} (The value of the denominator.) 110 */ 111 public Ratio setDenominator(Quantity value) { 112 this.denominator = value; 113 return this; 114 } 115 116 protected void listChildren(List<Property> childrenList) { 117 super.listChildren(childrenList); 118 childrenList.add(new Property("numerator", "Quantity", "The value of the numerator.", 0, java.lang.Integer.MAX_VALUE, numerator)); 119 childrenList.add(new Property("denominator", "Quantity", "The value of the denominator.", 0, java.lang.Integer.MAX_VALUE, denominator)); 120 } 121 122 @Override 123 public void setProperty(String name, Base value) throws FHIRException { 124 if (name.equals("numerator")) 125 this.numerator = castToQuantity(value); // Quantity 126 else if (name.equals("denominator")) 127 this.denominator = castToQuantity(value); // Quantity 128 else 129 super.setProperty(name, value); 130 } 131 132 @Override 133 public Base addChild(String name) throws FHIRException { 134 if (name.equals("numerator")) { 135 this.numerator = new Quantity(); 136 return this.numerator; 137 } 138 else if (name.equals("denominator")) { 139 this.denominator = new Quantity(); 140 return this.denominator; 141 } 142 else 143 return super.addChild(name); 144 } 145 146 public String fhirType() { 147 return "Ratio"; 148 149 } 150 151 public Ratio copy() { 152 Ratio dst = new Ratio(); 153 copyValues(dst); 154 dst.numerator = numerator == null ? null : numerator.copy(); 155 dst.denominator = denominator == null ? null : denominator.copy(); 156 return dst; 157 } 158 159 protected Ratio typedCopy() { 160 return copy(); 161 } 162 163 @Override 164 public boolean equalsDeep(Base other) { 165 if (!super.equalsDeep(other)) 166 return false; 167 if (!(other instanceof Ratio)) 168 return false; 169 Ratio o = (Ratio) other; 170 return compareDeep(numerator, o.numerator, true) && compareDeep(denominator, o.denominator, true) 171 ; 172 } 173 174 @Override 175 public boolean equalsShallow(Base other) { 176 if (!super.equalsShallow(other)) 177 return false; 178 if (!(other instanceof Ratio)) 179 return false; 180 Ratio o = (Ratio) other; 181 return true; 182 } 183 184 public boolean isEmpty() { 185 return super.isEmpty() && (numerator == null || numerator.isEmpty()) && (denominator == null || denominator.isEmpty()) 186 ; 187 } 188 189 190} 191