View Javadoc
1 /*** 2 * Copyright (c) 2002, CodeStreet LLC. All rights reserved.<p> 3 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following 4 * conditions are met:<p> 5 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 7 * in the documentation and/or other materials provided with the distribution. Neither the name of CodeStreet LLC. nor the 8 * names of its contributors may be used to endorse or promote products derived from this software without specific prior written 9 * permission.<p> 10 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 11 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 12 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 14 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 15 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<p> 16 */ 17 18 package com.codestreet.messageforge; 19 20 /*** 21 * Class to represent a constraint on a <tt>double</tt> numeric message field. 22 * @author Jawaid Hakim. 23 */ 24 public abstract class RFldConstraintF64 implements RFldConstraintNumeric 25 { 26 /*** 27 * Ctor. 28 */ 29 protected RFldConstraintF64() 30 { 31 } 32 33 /*** 34 * Check if a message field satisfies the constraint. 35 * @param fld Field to validate. 36 */ 37 public void validate(RFld fld) throws FieldValidationException 38 { 39 if (fld instanceof RFldF64) 40 { 41 RFldF64 numericFld = (RFldF64)fld; 42 if (! isValid(numericFld.getValue())) 43 throw new FieldValidationException(errDesc(fld.getName())); 44 } 45 else 46 throw new FieldValidationException("Invalid field type: " + fld.getName()); 47 } 48 49 /*** 50 * Check if a value satisfies the constraint. 51 * @param fld Field. 52 * @param val Value to validate. 53 */ 54 public void validate(RFld fld, double val) throws FieldValidationException 55 { 56 if (! isValid(val)) 57 throw new FieldValidationException(errDesc(fld.getName())); 58 } 59 60 /*** 61 * Check if a message field satisfies the constraint. 62 * @param fld Field to validate. 63 * @return <tt>true</tt> if the field satisfies the 64 * constraint. Otherwise, <tt>false</tt> is returned. 65 * @see RFld 66 */ 67 public boolean isValid(RFld fld) 68 { 69 if (fld instanceof RFldF64) 70 return isValid(((RFldF64)fld).getValue()); 71 else 72 return false; 73 } 74 75 /*** 76 * Check if a value satisfies the constraint. 77 * @param val Field value to validate. 78 * @return <tt>true</tt> if the field satisfies the 79 * constraint. Otherwise, <tt>false</tt> is returned. 80 * @see RFld 81 */ 82 public abstract boolean isValid(double val); 83 }

This page was automatically generated by Maven