Back to project page android-mvc-framework.
The source code is released under:
Apache License
If you think the Android project android-mvc-framework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.android_mvc.framework.controller.validation; //from ww w .j a v a2 s. co m import java.util.regex.Pattern; import com.android_mvc.framework.activities.IBaseActivity; /** * ????????????????????? * @author id:language_and_engineering * */ public class BaseValidationsUtil { // ????????????????????????? protected ActivityParams params; // ??????????? protected ValidationResult vres; /** * ????????????????????????????????????????????????????????? */ protected void initValidationOf(IBaseActivity activity) { params = activity.toParams(); vres = new ValidationResult(); } // ------------- assert????? /** * ????????????????????????????????? */ protected void assertNotEmpty(String key) { String s = (String)params.getValue(key); // 1????????????????? if( isEmpty( s ) ) { vres.err( params.getName(key) + "???????????????????????"); } } /** * ??????????????????????????????????????????????????????????? */ protected void assertValidInteger(String key) { String s = (String)params.getValue(key); if( isEmpty(s) ) return; // ?????????????????????????????????????????????????? if( ! isNumberCharSequence(s) ) { // ????????? vres.err( params.getName(key) + "????????????????????????????????????????"); } else if( ! validParsableAsInteger(s) ) { // ?????????????? vres.err( params.getName(key) + "??????????????????????????"); } } /** * ??????????????????????????????????????????????????? */ protected void assertNumberOperation(String key, NumberComparator nc) { String s = (String)params.getValue(key); if( ! validInteger(s) ) return; long target_value = Long.parseLong(s); // ????? if( "greaterThan".equals(nc.type_code) && ! (target_value > nc.value)) { vres.err( params.getName(key) + "??????" + nc.value + "????????????????????????????????"); } // TODO: ?????????? } /** * ??????????????????????????????????????????? */ protected void assertStringHead(String key, String headerTemplate) { String s = (String)params.getValue(key); if( isEmpty(s) ) return; // ??????????????????? if( s.indexOf(headerTemplate) != 0 ) { vres.err( params.getName(key) + "????" + headerTemplate +"???????????????????????????"); } } // ------------ ?????? /** * ??????????????????? */ protected NumberComparator greaterThan( long l ) { return new NumberComparator( l, "greaterThan" ); } /** * ???????????????????? */ protected ValidationResult getValidationResult() { return vres; } // ------------ ???? /** * ??????????????????????? */ private boolean isEmpty(String s) { return ( ( s == null ) || ( s.length() < 1 ) ); } /** * ???????????????????????????????? */ private boolean isNumberCharSequence(String s) { return ( Pattern.compile("^[0-9]+$").matcher(s).matches() ); } /** * ???????????????????????????? */ private boolean validParsableAsInteger( String s ) { // ????? Long long_value = Long.parseLong(s); // ?????????????????????????????????????0??????? return String.valueOf( long_value ).equals(s); } /** * ??????????????????? */ private boolean validInteger( String s ) { return ( ! isEmpty(s) ) && ( isNumberCharSequence(s) ) && validParsableAsInteger(s); } }