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 an enumeration constraint on a <tt>short</tt> message field.
22 * @author Jawaid Hakim.
23 */
24 public class RFldConstraintI16Enum extends RFldConstraintI16
25 {
26 /***
27 * Constructor.
28 * @param fldName Field name.
29 * @param enums Enumeration of allowed values.
30 */
31 public RFldConstraintI16Enum(String fldName, short[] enums) throws FieldValidationException
32 {
33 if (enums == null)
34 throw new FieldValidationException("NULL enums: " + fldName);
35 enums_ = enums;
36 }
37
38 /***
39 * Constructor.
40 * @param enums Enumeration of allowed values.
41 */
42 public RFldConstraintI16Enum(String[] enums) throws FieldValidationException
43 {
44 if (enums == null)
45 throw new FieldValidationException("NULL enums");
46 short[] shortEnums = new short[enums.length];
47 for (int i = shortEnums.length - 1; i >= 0 ; --i)
48 shortEnums[i] = Short.parseShort(enums[i]);
49 enums_ = shortEnums;
50 }
51
52 /***
53 * Get error description.
54 * @param fldName Field name.
55 * @return Error description.
56 */
57 public String errDesc(String fldName)
58 {
59 return "Field value not in enumeration: " + fldName;
60 }
61
62 /***
63 * Check if a value satisfies the constraint.
64 * @param val Value.
65 * @return <tt>true</tt> if the field satisfied the
66 * constraint. Otherwise, <tt>false</tt> is returned.
67 */
68 public boolean isValid(short val)
69 {
70 if (enums_ == null)
71 return true;
72
73 for (int i = enums_.length - 1; i >= 0 ; --i)
74 {
75 if (val == enums_[i])
76 return true;
77 }
78
79 return false;
80 }
81
82 /***
83 * Enumeration of allowed values.
84 */
85 protected short[] enums_;
86 }
This page was automatically generated by Maven