<commit_before>/*
 * Copyright 2007-2107 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.ymate.platform.validation.validate;

import net.ymate.platform.core.i18n.I18N;
import net.ymate.platform.core.lang.BlurObject;
import net.ymate.platform.validation.IValidator;
import net.ymate.platform.validation.ValidateContext;
import net.ymate.platform.validation.ValidateResult;
import net.ymate.platform.validation.annotation.Validator;
import org.apache.commons.lang.StringUtils;

/**
 * 参数值比较验证
 *
 * @author 刘镇 (<EMAIL>) on 2013-4-17 下午9:57:16
 * @version 1.0
 */
@Validator(VCompare.class)
public class CompareValidator implements IValidator {

    private static String __COMPARE_VALIDATOR_NOT_EQ = "ymp.validation.compare_validator_not_eq";

    private static String __COMPARE_VALIDATOR_EQ = "ymp.validation.compare_validator_eq";

    public ValidateResult validate(ValidateContext context) {
        if (context.getParamValue() != null && !context.getParamValue().getClass().isArray()) {
            VCompare _vCompare = (VCompare) context.getAnnotation();
            boolean _matched = BlurObject.bind(context.getParamValue()).toStringValue()
                    .equals(BlurObject.bind(context.getParamValues().get(_vCompare.with())).toString());
            String _condStr = "equals";
            switch (_vCompare.cond()) {
                case NOT_EQ:
                    _matched = !_matched;
                    _condStr = "not equals";
                    break;
                case EQ:
            }
            if (!_matched) {
                String _msg = null;
                switch (_vCompare.cond()) {
                    case NOT_EQ:
                        _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, __COMPARE_VALIDATOR_NOT_EQ, context.getParamName(), _vCompare.with());
                        break;
                    case EQ:
                        _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, __COMPARE_VALIDATOR_EQ, context.getParamName(), _vCompare.with());
                }
                if (StringUtils.trimToNull(_msg) == null) {
                    _msg = I18N.formatMessage("{0} must be {1} {2}", context.getParamName(), _condStr, _vCompare.with());
                }
                return new ValidateResult(context.getParamName(), _msg);
            }
        }
        return null;
    }
}<commit_msg>优化I18N验证结果信息输出<commit_after>/*
 * Copyright 2007-2107 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.ymate.platform.validation.validate;

import net.ymate.platform.core.i18n.I18N;
import net.ymate.platform.core.lang.BlurObject;
import net.ymate.platform.validation.IValidator;
import net.ymate.platform.validation.ValidateContext;
import net.ymate.platform.validation.ValidateResult;
import net.ymate.platform.validation.annotation.Validator;
import org.apache.commons.lang.StringUtils;

/**
 * 参数值比较验证
 *
 * @author 刘镇 (<EMAIL>) on 2013-4-17 下午9:57:16
 * @version 1.0
 */
@Validator(VCompare.class)
public class CompareValidator implements IValidator {

    private static String __COMPARE_VALIDATOR_NOT_EQ = "ymp.validation.compare_validator_not_eq";

    private static String __COMPARE_VALIDATOR_EQ = "ymp.validation.compare_validator_eq";

    public ValidateResult validate(ValidateContext context) {
        if (context.getParamValue() != null && !context.getParamValue().getClass().isArray()) {
            VCompare _vCompare = (VCompare) context.getAnnotation();
            boolean _matched = BlurObject.bind(context.getParamValue()).toStringValue()
                    .equals(BlurObject.bind(context.getParamValues().get(_vCompare.with())).toString());
            String _condStr = "equals";
            switch (_vCompare.cond()) {
                case NOT_EQ:
                    _matched = !_matched;
                    _condStr = "not equals";
                    break;
                case EQ:
            }
            if (!_matched) {
                String _msg = null;
                switch (_vCompare.cond()) {
                    case NOT_EQ:
                        _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, __COMPARE_VALIDATOR_NOT_EQ, "{0} can not eq {1}.", context.getParamName(), _vCompare.with());
                        break;
                    case EQ:
                        _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, __COMPARE_VALIDATOR_EQ, "{0} must be eq {1}.", context.getParamName(), _vCompare.with());
                }
                if (StringUtils.trimToNull(_msg) == null) {
                    _msg = I18N.formatMessage("{0} must be {1} {2}", context.getParamName(), _condStr, _vCompare.with());
                }
                return new ValidateResult(context.getParamName(), _msg);
            }
        }
        return null;
    }
}
{'fraction_non_alphanumeric': 0.10222448633044659, 'fraction_numerical': 0.015622346748174563, 'mean_word_length': 2.5375375375375375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3962318', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1625, 'n_words': 406}