MCPcopy Create free account
hub / github.com/e2wugui/zeze / isCompatible

Method isCompatible

ZezeJava/ZezeJava/src/main/java/Zeze/Schemas.java:483–572  ·  view source on GitHub ↗

var可能增加,也可能删除,所以兼容仅判断var.id相同的。 并且和谁比较谁没有关系。 @param other another Type @return true: compatible

(@NotNull String parent, @Nullable Type other, @NotNull Context context,
									@Nullable Consumer<Bean> update, @Nullable Consumer<Bean> updateVariable)

Source from the content-addressed store, hash-verified

481 * @return true: compatible
482 */
483 @Override
484 public boolean isCompatible(@NotNull String parent, @Nullable Type other, @NotNull Context context,
485 @Nullable Consumer<Bean> update, @Nullable Consumer<Bean> updateVariable) {
486// if (name.endsWith(".BTestSchemas")) {
487// logger.info("break");
488// }
489//
490 if (compatibleChecked)
491 return true;
492
493 if (other == null) {
494 logger.error("other is null. parent={}, bean={}", parent, getName());
495 return false;
496 }
497
498 if (!(other instanceof Bean)) {
499 logger.error("other is not Bean. parent={}, bean={}, other={}",
500 parent, getName(), other.getClass().getName());
501 return false;
502 }
503
504 Bean beanOther = (Bean)other;
505
506 var result = context.getCheckResult(beanOther, this);
507 if (result != null) {
508 result.addUpdate(update, updateVariable);
509 return true;
510 }
511 result = new CheckResult(); // result在后面可能被更新。
512 result.setBean(this);
513 context.addCheckResult(beanOther, this, result);
514
515 boolean res = true;
516
517 // 先检查是不是反悔
518 for (var vOldDeleted : beanOther.deletedVars.values()) {
519 var vThis = variables.get(vOldDeleted.id);
520 if (vThis != null) {
521 if (context.getConfig().getAllowSchemasReuseVariableIdWithSameType()
522 && vThis.isCompatible(getName(), vOldDeleted, context)) {
523 // 反悔
524 logger.info("Regret Success. Variable={}.{}", getName(), vThis.name);
525 continue;
526 }
527 logger.error("Not Compatible. Variable={}.{} Can Not Reuse Deleted Variable.Id",
528 getName(), vThis.name);
529 res = false;
530 } else {
531 deletedVars.put(vOldDeleted.id, vOldDeleted);
532 }
533 }
534 // 遍历当前变量,进行兼容检查。
535 for (var e : beanOther.variables.entrySet()) {
536 var vOther = e.getValue();
537 var vThis = variables.get(vOther.id);
538 if (vThis != null) {
539 if (!vThis.isCompatible(getName(), vOther, context)) {
540 // 正常比较。

Callers

nothing calls this directly

Calls 15

getNameMethod · 0.95
getKeyRefCountMethod · 0.95
getVariablesMethod · 0.95
getCheckResultMethod · 0.80
addUpdateMethod · 0.80
addCheckResultMethod · 0.80
getNameMethod · 0.65
valuesMethod · 0.65
getMethod · 0.65
putMethod · 0.65
getValueMethod · 0.65

Tested by

no test coverage detected