use of org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer in project directory-ldap-api by apache.
the class NumericStringComparator method compare.
/**
* {@inheritDoc}
*/
public int compare(String backendValue, String assertValue) {
LOG.debug("comparing numericStringOrdering objects '{}' with '{}'", backendValue, assertValue);
// reference the same object
if (backendValue == assertValue) {
return 0;
}
// have been caught by the previous test
if ((backendValue == null) || (assertValue == null)) {
return backendValue == null ? -1 : 1;
}
// Both objects must be stored as String for numeric.
// But we need to normalize the values first.
NumericNormalizer normalizer = new NumericNormalizer();
try {
backendValue = normalizer.normalize(backendValue);
} catch (LdapException le) {
throw new IllegalArgumentException(I18n.err(I18n.ERR_13724_INVALID_VALUE, backendValue), le);
}
try {
assertValue = normalizer.normalize(assertValue);
} catch (LdapException le) {
throw new IllegalArgumentException(I18n.err(I18n.ERR_13724_INVALID_VALUE, assertValue), le);
}
return backendValue.compareTo(assertValue);
}
use of org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer in project directory-ldap-api by apache.
the class NumericNormalizerTest method testInsignifiantSpacesStringOneChar.
@Test
public void testInsignifiantSpacesStringOneChar() throws LdapException {
Normalizer normalizer = new NumericNormalizer();
assertEquals("1", normalizer.normalize("1"));
}
use of org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer in project directory-ldap-api by apache.
the class NumericNormalizerTest method testInsignifiantNumericCharsSpaces.
@Test
public void testInsignifiantNumericCharsSpaces() throws LdapException {
Normalizer normalizer = new NumericNormalizer();
assertEquals("1", normalizer.normalize(" 1"));
assertEquals("1", normalizer.normalize("1 "));
assertEquals("1", normalizer.normalize(" 1 "));
assertEquals("11", normalizer.normalize("1 1"));
assertEquals("11", normalizer.normalize(" 1 1"));
assertEquals("11", normalizer.normalize("1 1 "));
assertEquals("11", normalizer.normalize("1 1"));
assertEquals("11", normalizer.normalize(" 1 1 "));
assertEquals("123456789", normalizer.normalize(" 123 456 789 "));
}
use of org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer in project directory-ldap-api by apache.
the class NumericNormalizerTest method testNumericNormalizerNSpaces.
@Test
public void testNumericNormalizerNSpaces() throws LdapException {
Normalizer normalizer = new NumericNormalizer();
assertEquals("", normalizer.normalize(" "));
}
use of org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer in project directory-ldap-api by apache.
the class NumericNormalizerTest method testInsignifiantSpacesStringNChars.
@Test
public void testInsignifiantSpacesStringNChars() throws LdapException {
Normalizer normalizer = new NumericNormalizer();
assertEquals("123456", normalizer.normalize("123456"));
}
Aggregations