feat(REQ-5865) - 调整 MQ 事件实现算 boolean 的逻辑

This commit is contained in:
wangli 2025-11-25 10:10:01 +08:00
parent a9a90ab46d
commit 167298881b

View File

@ -81,19 +81,30 @@ public class ImplementationReadyChecker implements ApplicationListener<Applicati
}
/**
* 自适应转换value 15 时返回 4 位数组否则返回最小所需位数数组
*/
public static boolean[] toBooleansAdaptive(int value) {
if (value < 0) throw new IllegalArgumentException("adaptive mode only for non-negative");
if (value == 0) return new boolean[]{false};
int bits = 32 - Integer.numberOfLeadingZeros(value);
if (value < 0) {
throw new IllegalArgumentException("adaptive mode only for non-negative");
}
// 核心修改value 15 强制用 4 否则计算最小所需位数
int bits = (value <= 15) ? 4 : (32 - Integer.numberOfLeadingZeros(value));
return toBooleans(value, bits);
}
// 高位在前index=0 是最高位
/**
* value 转换为指定位数的 boolean 数组高位在前
*/
public static boolean[] toBooleans(int value, int bits) {
if (bits <= 0 || bits > 32) throw new IllegalArgumentException("bits must be 1~32");
if (bits <= 0 || bits > 32) {
throw new IllegalArgumentException("bits must be 1~32");
}
boolean[] arr = new boolean[bits];
for (int i = 0; i < bits; i++) {
int shift = bits - 1 - i;
int shift = bits - 1 - i; // 从高位到低位遍历
arr[i] = ((value >>> shift) & 1) == 1;
}
return arr;