Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] fix extract double and unit error when unit is Ki #2099

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public final class CollectUtil {
private static final String CRYING_PLACEHOLDER_REX = "\\^o\\^";
private static final String CRYING_PLACEHOLDER_REGEX = "(\\^o\\^)(\\w|-|$|\\.)+(\\^o\\^)";
private static final Pattern CRYING_PLACEHOLDER_REGEX_PATTERN = Pattern.compile(CRYING_PLACEHOLDER_REGEX);
private static final List<String> UNIT_SYMBOLS = Arrays.asList("%", "G", "g", "M", "m", "K", "k", "B", "b");
private static final List<String> UNIT_SYMBOLS = Arrays.asList("%", "G", "g", "M", "m", "K", "k", "B", "b", "Ki", "Mi", "Gi");

/**
* private constructor, not allow to create instance.
Expand Down Expand Up @@ -104,7 +104,7 @@ public static DoubleAndUnit extractDoubleAndUnitFromStr(String str) {
log.debug(e.getMessage());
}

if (!str.matches(DOUBLE_AND_UNIT_CHECK_REGEX)){
if (!str.matches(DOUBLE_AND_UNIT_CHECK_REGEX)) {
return doubleAndUnit;
}
// extract unit from str value, eg: 23.43GB, 33KB, 44.22G
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ void extractDoubleAndUnitFromStr() {
assertNull(res4.getValue());
assertNull(res4.getUnit());

CollectUtil.DoubleAndUnit res5 = CollectUtil.extractDoubleAndUnitFromStr("200Ki");
assertEquals(200, res5.getValue());
assertEquals("Ki", res5.getUnit());
CollectUtil.DoubleAndUnit res6 = CollectUtil.extractDoubleAndUnitFromStr("200Mi");
assertEquals(200, res6.getValue());
assertEquals("Mi", res6.getUnit());
CollectUtil.DoubleAndUnit res7 = CollectUtil.extractDoubleAndUnitFromStr("200Gi");
assertEquals(200, res7.getValue());
assertEquals("Gi", res7.getUnit());
}


Expand Down
Loading