`

PrecisionValidator

阅读更多
public class PrecisionValidator extends BaseValidator {
    
    private PrecisionValidator() {
        
    }
    
    public static final int ORACLE_NUMBER_PRECISION_RANGE_MIN = 1;
    public static final int ORACLE_NUMBER_PRECISION_RANGE_MAX = 38;
    public static final int ORACLE_NUMBER_SCALE_RANGE_MIN = -84;
    public static final int ORACLE_NUMBER_SCALE_RANGE_MAX = 127;
    
    
    /**
     * Validation Rule: A number can be stored in an oracle NUMBER column by specified precision and scale
     * @param precision          The total number of digits
     * @param scale              The number of digits to the right of the decimal point
     * @param inputText          Input string text
     * @return boolean           Return true when input string is valid number can be stored in an oracle NUMBER column 
     *                           by specified precision and scale, otherwise return false.                        
     */
    public static boolean validateNumberPrecision(int precision, int scale, String inputText) {
        boolean isValid = false;
        
        if (Util.isEmpty(inputText)) {
            isValid = true;
        }
        
        if (!Util.isEmpty(inputText) && NumericValidator.isNumeric(inputText)) {

            if (precision > PrecisionValidator.ORACLE_NUMBER_PRECISION_RANGE_MAX) {
                precision = PrecisionValidator.ORACLE_NUMBER_PRECISION_RANGE_MAX;
            }
            
            if (precision < PrecisionValidator.ORACLE_NUMBER_PRECISION_RANGE_MIN) {
                precision = PrecisionValidator.ORACLE_NUMBER_PRECISION_RANGE_MIN;
            }
            
            if (scale > PrecisionValidator.ORACLE_NUMBER_SCALE_RANGE_MAX) {
                scale = PrecisionValidator.ORACLE_NUMBER_SCALE_RANGE_MAX;
            }
            
            if (scale < PrecisionValidator.ORACLE_NUMBER_SCALE_RANGE_MIN) {
                scale = PrecisionValidator.ORACLE_NUMBER_SCALE_RANGE_MIN;
            }
            
            int lastDecimalIndex = inputText.lastIndexOf('.');
            int currentPrecision = 0;
            int currentScale = 0;
            boolean isValidPrecision = false;
            boolean isValidScale = false;
            
            if (lastDecimalIndex > 0) {
                currentPrecision = lastDecimalIndex;
                currentScale = inputText.length() - lastDecimalIndex - 1;
            } else {
                currentPrecision = inputText.length();
                currentScale = 0;
            }
            
            if (currentPrecision <= precision) {
                isValidPrecision = true;
            }
            
            if (scale >= 0 && currentScale <= scale) {
                isValidScale = true;
            }
            
            if (scale < 0) {
                isValidScale = true;
            }
            
            if (isValidPrecision && isValidScale) {
                isValid = true;
            }
        }
        
        return isValid;
    }
    
    /**
     * Validation Rule: A number can be stored in an oracle NUMBER column by specified precision and scale
     * @param precision          The total number of digits
     * @param scale              The number of digits to the right of the decimal point
     * @param inputText          Input string text
     * @param fieldErrorParam    Field error tag parameter
     * @param fieldErrorMessage  Field error message
     * @return boolean           Return true when input string is valid number can be stored in an oracle NUMBER column 
     *                           by specified precision and scale, otherwise return false.                        
     */
    public static boolean validateNumberPrecision(int precision, int scale, String inputText, String fieldErrorParam, String fieldErrorMessage) {
        boolean isValid = PrecisionValidator.validateNumberPrecision(precision, scale, inputText);
        
        if (!isValid) {
            addFieldErrorMessage(fieldErrorParam, fieldErrorMessage);
        }
        
        return isValid;
    }
    
    /**
     * Validation Rule: A number can be stored in an oracle NUMBER column by specified precision and scale
     * @param precision          The total number of digits
     * @param scale              The number of digits to the right of the decimal point
     * @param inputText          Input string text
     * @param fieldErrorParam    Field error tag parameter
     * @param bundle             Language property file id
     * @param key                Message key
     * @param defaultMessage     Default message
     * @param arguments          The arguments of message
     * @return boolean           Return true when input string is valid number can be stored in an oracle NUMBER column 
     *                           by specified precision and scale, otherwise return false.                        
     */
    public static boolean validateNumberPrecision(int precision, int scale, String inputText, String fieldErrorParam, 
            String bundle, String key, String defaultMessage, String[] arguments) {
        boolean isValid = PrecisionValidator.validateNumberPrecision(precision, scale, inputText);
        
        if (!isValid) {
            String fieldErrorMessage = MessageUtil.getText(bundle, key, defaultMessage, arguments);
            addFieldErrorMessage(fieldErrorParam, fieldErrorMessage);
        }
        
        return isValid;
    }
    
    
    /**
     * Validation Rule: A number is integer and the value is between -2147483648 and 2147483647
     * @param inputText          Input string text
     * @return boolean           Return true when input string is an integer and the value is between -2147483648 and 2147483647,
     *                           otherwise return false.                        
     */
    public static boolean validateIntegerPrecision(String inputText) {
        boolean isValid = false;
        
        if (Util.isEmpty(inputText)) {
            isValid = true;
        }
        
        if (!Util.isEmpty(inputText) && IntegerValidator.isInteger(inputText)) {
            try {
                Integer.parseInt(inputText);
                isValid = true;
            } catch (Exception e) {
                isValid = false;
            }
        }
        
        return isValid;
    }
    
    /**
     * Validation Rule: A number is integer and the value is between -2147483648 and 2147483647
     * @param inputText          Input string text
     * @param fieldErrorParam    Field error tag parameter
     * @param fieldErrorMessage  Field error message
     * @return boolean           Return true when input string is an integer and the value is between -2147483648 and 2147483647,
     *                           otherwise return false.                        
     */
    public static boolean validateIntegerPrecision(String inputText, String fieldErrorParam, String fieldErrorMessage) {
        boolean isValid = PrecisionValidator.validateIntegerPrecision(inputText);
        
        if (!isValid) {
            addFieldErrorMessage(fieldErrorParam, fieldErrorMessage);
        }
        
        return isValid;
    }
    
    /**
     * Validation Rule: A number is integer and the value is between -2147483648 and 2147483647
     * @param inputText          Input string text
     * @param fieldErrorParam    Field error tag parameter
     * @param bundle             Language property file id
     * @param key                Message key
     * @param defaultMessage     Default message
     * @param arguments          The arguments of message
     * @return boolean           Return true when input string is an integer and the value is between -2147483648 and 2147483647,
     *                           otherwise return false.                        
     */
    public static boolean validateIntegerPrecision(String inputText, String fieldErrorParam, 
            String bundle, String key, String defaultMessage, String[] arguments) {
        boolean isValid = PrecisionValidator.validateIntegerPrecision(inputText);
        
        if (!isValid) {
            String fieldErrorMessage = MessageUtil.getText(bundle, key, defaultMessage, arguments);
            addFieldErrorMessage(fieldErrorParam, fieldErrorMessage);
        }
        
        return isValid;
    }
    
    
    /**
     * Validation Rule: A number is type long and the value is between -9223372036854775808L and 9223372036854775807L
     * @param inputText          Input string text
     * @return boolean           Return true when input string is type long number and the value is between -9223372036854775808L and 9223372036854775807L,
     *                           otherwise return false.                        
     */
    public static boolean validateLongPrecision(String inputText) {
        boolean isValid = false;
        
        if (Util.isEmpty(inputText)) {
            isValid = true;
        }
        
        if (!Util.isEmpty(inputText) && IntegerValidator.isInteger(inputText)) {
            try {
                Long.parseLong(inputText);
                isValid = true;
            } catch (Exception e) {
                isValid = false;
            }
        }
        
        return isValid;
    }
    
    /**
     * Validation Rule: A number is type long and the value is between -9223372036854775808L and 9223372036854775807L
     * @param inputText          Input string text
     * @param fieldErrorParam    Field error tag parameter
     * @param fieldErrorMessage  Field error message
     * @return boolean           Return true when input string is type long number and the value is between -9223372036854775808L and 9223372036854775807L,
     *                           otherwise return false.                        
     */
    public static boolean validateLongPrecision(String inputText, String fieldErrorParam, String fieldErrorMessage) {
        boolean isValid = PrecisionValidator.validateLongPrecision(inputText);
        
        if (!isValid) {
            addFieldErrorMessage(fieldErrorParam, fieldErrorMessage);
        }
        
        return isValid;
    }
    
    /**
     * Validation Rule: A number is type long and the value is between -9223372036854775808L and 9223372036854775807L
     * @param inputText          Input string text
     * @param fieldErrorParam    Field error tag parameter
     * @param bundle             Language property file id
     * @param key                Message key
     * @param defaultMessage     Default message
     * @param arguments          The arguments of message
     * @return boolean           Return true when input string is type long number and the value is between -9223372036854775808L and 9223372036854775807L,
     *                           otherwise return false.                        
     */
    public static boolean validateLongPrecision(String inputText, String fieldErrorParam, 
            String bundle, String key, String defaultMessage, String[] arguments) {
        boolean isValid = PrecisionValidator.validateLongPrecision(inputText);
        
        if (!isValid) {
            String fieldErrorMessage = MessageUtil.getText(bundle, key, defaultMessage, arguments);
            addFieldErrorMessage(fieldErrorParam, fieldErrorMessage);
        }
        
        return isValid;
    }
    
    
    /**
     * Validation Rule: A number is type float and the value is between 1.401298464324817E-45f and 3.4028234663852886E38f
     * @param inputText          Input string text
     * @return boolean           Return true when input string is type float number and the value is between 1.401298464324817E-45f and 3.4028234663852886E38f,
     *                           otherwise return false.                        
     */
    public static boolean validateFloatPrecision(String inputText) {
        boolean isValid = false;
        
        if (Util.isEmpty(inputText)) {
            isValid = true;
        }
        
        if (!Util.isEmpty(inputText) && NumericValidator.isNumeric(inputText)) {
            try {
                Float.parseFloat(inputText);
                isValid = true;
            } catch (Exception e) {
                isValid = false;
            }
        }
        
        return isValid;
    }
    
    /**
     * Validation Rule: A number is type float and the value is between 1.401298464324817E-45f and 3.4028234663852886E38f
     * @param inputText          Input string text
     * @param fieldErrorParam    Field error tag parameter
     * @param fieldErrorMessage  Field error message
     * @return boolean           Return true when input string is type float number and the value is between 1.401298464324817E-45f and 3.4028234663852886E38f,
     *                           otherwise return false.                        
     */
    public static boolean validateFloatPrecision(String inputText, String fieldErrorParam, String fieldErrorMessage) {
        boolean isValid = PrecisionValidator.validateFloatPrecision(inputText);
        
        if (!isValid) {
            addFieldErrorMessage(fieldErrorParam, fieldErrorMessage);
        }
        
        return isValid;
    }
    
    /**
     * Validation Rule: A number is type float and the value is between 1.401298464324817E-45f and 3.4028234663852886E38f
     * @param inputText          Input string text
     * @param fieldErrorParam    Field error tag parameter
     * @param bundle             Language property file id
     * @param key                Message key
     * @param defaultMessage     Default message
     * @param arguments          The arguments of message
     * @return boolean           Return true when input string is type float number and the value is between 1.401298464324817E-45f and 3.4028234663852886E38f,
     *                           otherwise return false.                        
     */
    public static boolean validateFloatPrecision(String inputText, String fieldErrorParam, 
            String bundle, String key, String defaultMessage, String[] arguments) {
        boolean isValid = PrecisionValidator.validateFloatPrecision(inputText);
        
        if (!isValid) {
            String fieldErrorMessage = MessageUtil.getText(bundle, key, defaultMessage, arguments);
            addFieldErrorMessage(fieldErrorParam, fieldErrorMessage);
        }
        
        return isValid;
    }
    
    
    /**
     * Validation Rule: A number is type double and the value is between 4.9E-324 and 1.7976931348623157E308
     * @param inputText          Input string text
     * @return boolean           Return true when input string is type double number and the value is between 4.9E-324 and 1.7976931348623157E308,
     *                           otherwise return false.                        
     */
    public static boolean validateDoublePrecision(String inputText) {
        boolean isValid = false;
        
        if (Util.isEmpty(inputText)) {
            isValid = true;
        }
        
        if (!Util.isEmpty(inputText) && NumericValidator.isNumeric(inputText)) {
            try {
                Double.parseDouble(inputText);
                isValid = true;
            } catch (Exception e) {
                isValid = false;
            }
        }
        
        return isValid;
    }
    
    /**
     * Validation Rule: A number is type double and the value is between 4.9E-324 and 1.7976931348623157E308
     * @param inputText          Input string text
     * @param fieldErrorParam    Field error tag parameter
     * @param fieldErrorMessage  Field error message
     * @return boolean           Return true when input string is type double number and the value is between 4.9E-324 and 1.7976931348623157E308,
     *                           otherwise return false.                        
     */
    public static boolean validateDoublePrecision(String inputText, String fieldErrorParam, String fieldErrorMessage) {
        boolean isValid = PrecisionValidator.validateDoublePrecision(inputText);
        
        if (!isValid) {
            addFieldErrorMessage(fieldErrorParam, fieldErrorMessage);
        }
        
        return isValid;
    }
    
    /**
     * Validation Rule: A number is type double and the value is between 4.9E-324 and 1.7976931348623157E308
     * @param inputText          Input string text
     * @param fieldErrorParam    Field error tag parameter
     * @param bundle             Language property file id
     * @param key                Message key
     * @param defaultMessage     Default message
     * @param arguments          The arguments of message
     * @return boolean           Return true when input string is type double number and the value is between 4.9E-324 and 1.7976931348623157E308,
     *                           otherwise return false.                        
     */
    public static boolean validateDoublePrecision(String inputText, String fieldErrorParam, 
            String bundle, String key, String defaultMessage, String[] arguments) {
        boolean isValid = PrecisionValidator.validateDoublePrecision(inputText);
        
        if (!isValid) {
            String fieldErrorMessage = MessageUtil.getText(bundle, key, defaultMessage, arguments);
            addFieldErrorMessage(fieldErrorParam, fieldErrorMessage);
        }
        
        return isValid;
    }

}

 

分享到:
评论

相关推荐

    android手机应用源码Imsdroid语音视频通话源码.rar

    android手机应用源码Imsdroid语音视频通话源码.rar

    营销计划汇报PPT,市场品牌 推广渠道 产品 营销策略tbb.pptx

    营销计划汇报PPT,市场品牌 推广渠道 产品 营销策略tbb.pptx

    JavaScript_超过100种语言的纯Javascript OCR.zip

    JavaScript

    JavaScript_跨平台React UI包.zip

    JavaScript

    node-v16.17.0-headers.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    520表白代码.rar

    520表白html5爱心代码

    一个简单的HTML5和CSS代码示例,用于创建一个动态的爱心形状,并在网页上展示一个类似520表白的消息 这个示例使用了CSS的

    520表白html5爱心代码 一个简单的HTML5和CSS代码示例,用于创建一个动态的爱心形状,并在网页上展示一个类似520表白的消息。这个示例使用了CSS的动画效果和HTML的结构。

    智慧养老社区方案.pdf

    智慧养老社区方案.pdf

    node-v14.11.0-headers.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    JavaScript_美观和可访问的拖放列表与React.zip

    JavaScript

    codeviz 1.0.12

    codeviz 1.0.12

    JavaScript_高级用户LLM前端.zip

    JavaScript

    javascript koans是一个交互式学习环境,它使用失败测试按逻辑顺序向学生介绍javascript的各个方面.zip

    JavaScript

    JavaScript_巴勒斯坦和巴以冲突资源的策划列表.zip

    JavaScript

    JavaScript_手工制作的弗里达例子.zip

    JavaScript

    node-v17.4.0-headers.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    移动应用Android 实现QQ好友列表源码.rar

    移动应用Android 实现QQ好友列表源码.rar

    DC平台蛋白质分子匹配预测.zip

    蛋白质是生物体中普遍存在的一类重要生物大分子,由天然氨基酸通过肽键连接而成。它具有复杂的分子结构和特定的生物功能,是表达生物遗传性状的一类主要物质。 蛋白质的结构可分为四级:一级结构是组成蛋白质多肽链的线性氨基酸序列;二级结构是依靠不同氨基酸之间的C=O和N-H基团间的氢键形成的稳定结构,主要为α螺旋和β折叠;三级结构是通过多个二级结构元素在三维空间的排列所形成的一个蛋白质分子的三维结构;四级结构用于描述由不同多肽链(亚基)间相互作用形成具有功能的蛋白质复合物分子。 蛋白质在生物体内具有多种功能,包括提供能量、维持电解质平衡、信息交流、构成人的身体以及免疫等。例如,蛋白质分解可以为人体提供能量,每克蛋白质能产生4千卡的热能;血液里的蛋白质能帮助维持体内的酸碱平衡和血液的渗透压;蛋白质是组成人体器官组织的重要物质,可以修复受损的器官功能,以及维持细胞的生长和更新;蛋白质也是构成多种生理活性的物质,如免疫球蛋白,具有维持机体正常免疫功能的作用。 蛋白质的合成是指生物按照从脱氧核糖核酸(DNA)转录得到的信使核糖核酸(mRNA)上的遗传信息合成蛋白质的过程。这个过程包括氨基酸的活化、多肽链合成的起始、肽链的延长、肽链的终止和释放以及蛋白质合成后的加工修饰等步骤。 蛋白质降解是指食物中的蛋白质经过蛋白质降解酶的作用降解为多肽和氨基酸然后被人体吸收的过程。这个过程在细胞的生理活动中发挥着极其重要的作用,例如将蛋白质降解后成为小分子的氨基酸,并被循环利用;处理错误折叠的蛋白质以及多余组分,使之降解,以防机体产生错误应答。 总的来说,蛋白质是生物体内不可或缺的一类重要物质,对于维持生物体的正常生理功能具有至关重要的作用。

    二叉树的遍历代码实现.rar

    二叉树的遍历

    JavaScript_Kener是一个现代自我托管状态页电池包括在内.zip

    JavaScript

Global site tag (gtag.js) - Google Analytics