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

fix AXIS2-6041 (totalDigits Facet of XSD type short incorrectly treat… #642

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -1289,9 +1289,14 @@ public static List toList(Object[] array) {
* @return 0 if equal , + value if greater than , - value if less than
*/
public static int compare(int intValue, String value) {
int other = Integer.parseInt(value);
return intValue < other ? -1 : (intValue == other ? 0 : 1);

int param;
try {
NumberFormat nf = NumberFormat.getInstance();
param = nf.parse(value).intValue();
} catch (Exception e) {
throw new ObjectConversionException(e);
}
return intValue < param ? -1 : (intValue == param ? 0 : 1);
}

/**
Expand Down Expand Up @@ -1319,7 +1324,14 @@ public static float compare(float floatValue, String value) {
* @return 0 if equal , + value if greater than , - value if less than
*/
public static long compare(long longValue, String value) {
return longValue - Long.parseLong(value);
long param;
try {
NumberFormat nf = NumberFormat.getInstance();
param = nf.parse(value).longValue();
} catch (Exception e) {
throw new ObjectConversionException(e);
}
return longValue - param;
}

/**
Expand All @@ -1328,7 +1340,14 @@ public static long compare(long longValue, String value) {
* @return 0 if equal , + value if greater than , - value if less than
*/
public static int compare(short shortValue, String value) {
return shortValue - Short.parseShort(value);
short param;
try {
NumberFormat nf = NumberFormat.getInstance();
param = nf.parse(value).shortValue();
} catch (Exception e) {
throw new ObjectConversionException(e);
}
return shortValue - param;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,4 +583,46 @@ public void testCompareBigIntegerValueIsGreaterThanOrEqualToTotalDigitsFacetRest
long result = ConverterUtil.compare(value, decimalNotationString);
assertThat(result).isGreaterThanOrEqualTo(0L);
}

public void testCompareLongIsLessThanTotalDigitsFacetRestriction() {
long value = 1L;
String totalDigitsFromXsd = "1";
String decimalNotationString = ConverterUtil.convertToStandardDecimalNotation(totalDigitsFromXsd).toPlainString();
assertThat(ConverterUtil.compare(value, decimalNotationString)).isLessThan(0L);
}

public void testCompareLongIsGreaterThanOrEqualToTotalDigitsFacetRestriction() {
long value = 10L;
String totalDigitsFromXsd = "1";
String decimalNotationString = ConverterUtil.convertToStandardDecimalNotation(totalDigitsFromXsd).toPlainString();
assertThat(ConverterUtil.compare(value, decimalNotationString)).isGreaterThanOrEqualTo(0L);
}

public void testCompareIntIsLessThanTotalDigitsFacetRestriction() {
int value = 1;
String totalDigitsFromXsd = "1";
String decimalNotationString = ConverterUtil.convertToStandardDecimalNotation(totalDigitsFromXsd).toPlainString();
assertThat(ConverterUtil.compare(value, decimalNotationString)).isLessThan(0);
}

public void testCompareIntIsGreaterThanOrEqualToTotalDigitsFacetRestriction() {
int value = 10;
String totalDigitsFromXsd = "1";
String decimalNotationString = ConverterUtil.convertToStandardDecimalNotation(totalDigitsFromXsd).toPlainString();
assertThat(ConverterUtil.compare(value, decimalNotationString)).isGreaterThanOrEqualTo(0);
}

public void testCompareShortIsLessThanTotalDigitsFacetRestriction() {
short value = 1;
String totalDigitsFromXsd = "1";
String decimalNotationString = ConverterUtil.convertToStandardDecimalNotation(totalDigitsFromXsd).toPlainString();
assertThat(ConverterUtil.compare(value, decimalNotationString)).isLessThan(0);
}

public void testCompareShortIsGreaterThanOrEqualToTotalDigitsFacetRestriction() {
short value = 10;
String totalDigitsFromXsd = "1";
String decimalNotationString = ConverterUtil.convertToStandardDecimalNotation(totalDigitsFromXsd).toPlainString();
assertThat(ConverterUtil.compare(value, decimalNotationString)).isGreaterThanOrEqualTo(0);
}
}