| 1 19 package org.openharmonise.vfs.metadata.range; 20 21 import org.openharmonise.commons.xml.*; 22 import org.openharmonise.vfs.metadata.*; 23 import org.openharmonise.vfs.metadata.value.*; 24 import org.w3c.dom.Element ; 25 import org.w3c.dom.Node ; 26 import org.w3c.dom.NodeList ; 27 import org.w3c.dom.Text ; 28 29 30 37 public class FloatRange extends AbstractRange implements Range { 38 39 42 private Float m_fMinInclusive = null; 43 44 47 private Float m_fMaxInclusive = null; 48 49 52 private Float m_fMinExclusive = null; 53 54 57 private Float m_fMaxExclusive = null; 58 59 62 public FloatRange() { 63 super(); 64 } 65 66 72 public Float getMinimum() { 73 if(this.m_fMinInclusive!=null) { 74 return this.m_fMinInclusive; 75 } else { 76 return this.m_fMinExclusive; 77 } 78 } 79 80 86 public Float getMaximum() { 87 if(this.m_fMaxInclusive!=null) { 88 return this.m_fMaxInclusive; 89 } else { 90 return this.m_fMaxExclusive; 91 } 92 } 93 94 99 public void setMinimum(Float fl) { 100 this.m_fMinInclusive = fl; 101 } 102 103 108 public void setMinimum(float fl) { 109 this.m_fMinInclusive = new Float (fl); 110 } 111 112 117 public void setMaximum(Float fl) { 118 this.m_fMaxInclusive = fl; 119 } 120 121 126 public void setMaximum(float fl) { 127 this.m_fMaxInclusive = new Float (fl); 128 } 129 130 131 134 public ValidationResult validate(ValueInstance value) { 135 float fVal = ((FloatValue)value).getValue(); 136 boolean bIsValid = true; 137 138 if(m_fMinInclusive != null) { 139 bIsValid = m_fMinInclusive.floatValue() <= fVal; 140 } else if(m_fMinExclusive != null) { 141 bIsValid = m_fMinExclusive.floatValue() < fVal; 142 } 143 144 if(bIsValid == true) { 145 if(m_fMaxInclusive != null) { 146 bIsValid = m_fMaxInclusive.floatValue() >= fVal; 147 } else if(m_fMaxExclusive != null) { 148 bIsValid = m_fMaxExclusive.floatValue() > fVal; 149 } 150 } 151 152 return new ValidationResult(bIsValid,""); 153 } 154 155 158 public void instantiate(Element elRange) { 159 Element elRestriction = XMLUtils.getFirstElementChild(elRange); 160 NodeList nl = elRestriction.getChildNodes(); 161 for(int i=0; i<nl.getLength();i++) { 162 Node node = nl.item(i); 163 if(node.getNodeType()==Node.ELEMENT_NODE) { 164 Element element = (Element )node; 165 if(element.getLocalName().equalsIgnoreCase("minInclusive")) { 166 Node node2 = element.getFirstChild(); 167 if( node2.getNodeType()==Node.TEXT_NODE) { 168 this.m_fMinInclusive = Float.valueOf( ((Text )node2).getNodeValue() ); 169 } 170 } else if(element.getLocalName().equalsIgnoreCase("maxInclusive")) { 171 Node node2 = element.getFirstChild(); 172 if( node2.getNodeType()==Node.TEXT_NODE) { 173 this.m_fMaxInclusive = Float.valueOf( ((Text )node2).getNodeValue() ); 174 } 175 } else if(element.getLocalName().equalsIgnoreCase("minExclusive")) { 176 Node node2 = element.getFirstChild(); 177 if( node2.getNodeType()==Node.TEXT_NODE) { 178 this.m_fMinExclusive = Float.valueOf( ((Text )node2).getNodeValue() ); 179 } 180 } else if(element.getLocalName().equalsIgnoreCase("maxExclusive")) { 181 Node node2 = element.getFirstChild(); 182 if( node2.getNodeType()==Node.TEXT_NODE) { 183 this.m_fMaxExclusive = Float.valueOf( ((Text )node2).getNodeValue() ); 184 } 185 } 186 } 187 } 188 } 189 190 public String toString() { 191 StringBuffer sBuff = new StringBuffer (); 192 193 sBuff.append("FloatRange:\n"); 194 if(this.m_fMinInclusive!=null) { 195 sBuff.append("minInclusive: ").append(this.m_fMinInclusive).append("\n"); 196 } 197 if(this.m_fMaxInclusive!=null) { 198 sBuff.append("maxInclusive: ").append(this.m_fMaxInclusive).append("\n"); 199 } 200 if(this.m_fMinExclusive!=null) { 201 sBuff.append("minExclusive: ").append(this.m_fMinExclusive).append("\n"); 202 } 203 if(this.m_fMaxExclusive!=null) { 204 sBuff.append("maxExclusive: ").append(this.m_fMaxExclusive).append("\n"); 205 } 206 207 return sBuff.toString(); 208 } 209 210 } 211 | Popular Tags |