001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019:
020: package de.schlund.pfixcore.generator.postchecks;
021:
022: import java.util.StringTokenizer;
023:
024: import de.schlund.pfixcore.generator.IWrapperParamPostCheck;
025: import de.schlund.pfixcore.generator.SimpleCheck;
026: import de.schlund.util.statuscodes.StatusCode;
027: import de.schlund.util.statuscodes.StatusCodeLib;
028:
029: /**
030: * FloatRange.java
031: *
032: *
033: * Created: Thu Aug 16 17:18:57 2001
034: *
035: * @author <a href="mailto: "Jens Lautenbacher</a>
036: *
037: *
038: */
039:
040: public class FloatRange extends SimpleCheck implements
041: IWrapperParamPostCheck {
042: private boolean lower_inc = true;
043: private boolean upper_inc = true;
044: private StatusCode scode_small;
045: private StatusCode scode_big;
046: private float lower;
047: private float upper;
048:
049: public FloatRange() {
050: scode_small = StatusCodeLib.PFIXCORE_GENERATOR_POSTCHECK_FLOAT_TOO_SMALL;
051: scode_big = StatusCodeLib.PFIXCORE_GENERATOR_POSTCHECK_FLOAT_TOO_BIG;
052: }
053:
054: public void put_scode_too_small(String fqscode) {
055: scode_small = StatusCodeLib.getStatusCodeByName(fqscode);
056: }
057:
058: public void put_scode_too_big(String fqscode) {
059: scode_big = StatusCodeLib.getStatusCodeByName(fqscode);
060: }
061:
062: public void put_range(String param) {
063: param = param.trim();
064:
065: if (param.startsWith("(")) {
066: lower_inc = false;
067: }
068:
069: if (param.endsWith(")")) {
070: upper_inc = false;
071: }
072:
073: StringTokenizer tok = new StringTokenizer(param, "()[] :",
074: false);
075: if (tok.countTokens() == 2) {
076: Float thelower = new Float(tok.nextToken());
077: Float theupper = new Float(tok.nextToken());
078: lower = thelower.intValue();
079: upper = theupper.intValue();
080: } else {
081: throw new RuntimeException("Range spec '" + param
082: + "' isn't correct");
083: }
084: }
085:
086: public void check(Object[] obj) {
087: reset();
088: for (int i = 0; i < obj.length; i++) {
089: float value = ((Float) obj[i]).floatValue();
090: if ((lower_inc && (lower > value))
091: || (!lower_inc && (lower >= value))) {
092: addSCode(scode_small);
093: break;
094: } else if ((upper_inc && (upper < value))
095: || (!upper_inc && (upper <= value))) {
096: addSCode(scode_big);
097: break;
098: }
099: }
100: }
101:
102: }// FloatRange
|