Search in sources :

Example 6 with NumericNormalizer

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);
}
Also used : NumericNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 7 with NumericNormalizer

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"));
}
Also used : NumericNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer) NumericNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) Test(org.junit.Test)

Example 8 with NumericNormalizer

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  "));
}
Also used : NumericNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer) NumericNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) Test(org.junit.Test)

Example 9 with NumericNormalizer

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("      "));
}
Also used : NumericNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer) NumericNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) Test(org.junit.Test)

Example 10 with NumericNormalizer

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"));
}
Also used : NumericNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer) NumericNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) Test(org.junit.Test)

Aggregations

NumericNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer)11 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)9 Test (org.junit.Test)9 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 BigInteger (java.math.BigInteger)1