英文:
Validating strings with Java and NodeJS
问题
`vo.getResultFun()` 和 `cod` 返回 `'G'`
**Java 验证**
if (genericValidator.isBlankOrNull(vo.getResultFun()) ||
!("G".equalsIgnoreCase(vo.getResultFun()) || "B".equalsIgnoreCase(vo.getResultFun()))) {
throw new UCNaoCadastradaGerBenException();
}
**NodeJS**
if (Validator.isNullUndefinedEmpty(cod) ||
!(Validator.isEqual(cod, 'B', true) || Validator.isEqual(cod, 'G', true))) {
callback(Translate.__('K1.CH1', lang), null);
**isEqual**
static isEqual(str1: string, str2: string, ignoreCase: boolean = false): boolean {
let ret = false;
if (ignoreCase) {
ret =
(str1 === undefined && str2 === undefined) ||
(str1 === null && str2 === null) ||
(str1 != null && str2 != null && typeof str1 === 'string' && typeof str2 === 'string' && str1.toUpperCase() === str2.toUpperCase());
} else {
ret =
(str1 === undefined && str2 === undefined) ||
(str1 === null && str2 === null) ||
(str1 != null && str2 != null && typeof str1 === 'string' && typeof str2 === 'string' && str1 === str2);
}
return ret;
}
为什么 NodeJS 返回回调而 Java 不抛出异常?
英文:
vo.getResultFun()
and cod
returns 'G'
Java validation
if ( genericValidator.isBlankOrNull(vo.getResultFun()) ||
!("G".equalsIgnoreCase(vo.getResultFun()) || "B".equalsIgnoreCase(vo.getResultFun()))) {
throw new UCNaoCadastradaGerBenException();
}
NodeJS
if (Validator.isNullUndefinedEmpty(cod) ||
!(Validator.isEqual(cod, 'B', true) || Validator.isEqual(cod, 'G', true))) {
callback(Translate.__('K1.CH1', lang), null);
isEqual
static isEqual(str1: string, str2: string, ignoreCase: boolean = false): boolean {
let ret = false;
if (ignoreCase) {
ret =
(str1 === undefined && str2 === undefined) ||
(str1 === null && str2 === null) ||
(str1 != null && str2 != null && typeof str1 === 'string' && typeof str2 === 'string' && str1.toUpperCase() === str2.toUpperCase());
} else {
ret =
(str1 === undefined && str2 === undefined) ||
(str1 === null && str2 === null) ||
(str1 != null && str2 != null && typeof str1 === 'string' && typeof str2 === 'string' && str1 === str2);
}
return ret;
}
Why NodeJS return the callback and Java don't throws the exception?
答案1
得分: 1
以下是翻译好的内容:
这段 JavaScript 代码的结果:
!(Validator.isEqual(cod, 'B', true) || Validator.isEqual(cod, 'G', true))
与这段 Java 代码的结果相同:
!("G".equalsIgnoreCase(vo.getResultFun()) || "B".equalsIgnoreCase(vo.getResultFun()))
因此有几个可能的选项:
Validator.isNullUndefinedEmpty
不起作用cod
不严格等于 'G'- 回调函数未被调用
英文:
The result of this js part :
!(Validator.isEqual(cod, 'B', true) || Validator.isEqual(cod, 'G', true))
is false
as the result of this java part:
!("G".equalsIgnoreCase(vo.getResultFun()) || "B".equalsIgnoreCase(vo.getResultFun()))
So there are several options :
Validator.isNullUndefinedEmpty
doesn't workscod
is not strictly equals to 'G'- The callback function is not called
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论