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 * Base class of all numeric fields.
22 * @author Jawaid Hakim.
23 */
24 public abstract class RFldNumeric extends RFld
25 {
26 /***
27 * Default constructor.
28 */
29 protected RFldNumeric()
30 {
31 }
32
33 /***
34 * Constructor.
35 * @param name Field name.
36 * @param fieldId Field id. Field ids must be either <tt>0</tt>
37 * to indicate that there is no id on the field, or greater. In addition,
38 * field ids must be unique within a messages - no two fields are allowed
39 * to have the same field id.
40 */
41 protected RFldNumeric(String name, int fieldId)
42 {
43 super(name, fieldId);
44 }
45
46 /***
47 * Constructor.
48 * @param name Field name.
49 * @param fieldId Field id. Field ids must be either <tt>0</tt>
50 * to indicate that there is no id on the field, or greater. In addition,
51 * field ids must be unique within a messages - no two fields are allowed
52 * to have the same field id.
53 * @param desc Field description.
54 */
55 protected RFldNumeric(String name, int fieldId, String desc)
56 {
57 super(name, fieldId, desc);
58 }
59
60 /***
61 * Add a constraint.
62 * @param cons Constraint.
63 */
64 public void addConstraint(RFldConstraintNumeric cons) throws FieldValidationException
65 {
66 super.addConstraint(cons);
67 }
68
69 /***
70 * Check if a data type is a valid numeric type.
71 * @param type Data type.
72 * @return <tt>true</tt> if type is a valid numeric type.
73 * Otherwise, returns <tt>false</tt>.
74 */
75 protected boolean validType(short type)
76 {
77 return (type == RFldType.DECIMAL.shortValue() ||
78 type == RFldType.I32.shortValue() ||
79 type == RFldType.F64.shortValue() ||
80 type == RFldType.F32.shortValue() ||
81 type == RFldType.I8.shortValue() ||
82 type == RFldType.I16.shortValue() ||
83 type == RFldType.I64.shortValue()
84 );
85 }
86
87 static final long serialVersionUID = -3028034333655379141L;
88 }
This page was automatically generated by Maven