Search in sources :

Example 1 with NumericNormalizer

use of org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer in project directory-ldap-api by apache.

the class NumericNormalizerTest method testNumericNormalizerNull.

@Test
public void testNumericNormalizerNull() throws LdapException {
    Normalizer normalizer = new NumericNormalizer();
    assertEquals(null, normalizer.normalize((String) null));
}
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 2 with NumericNormalizer

use of org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer in project directory-ldap-api by apache.

the class NumericNormalizerTest method testNumericNormalizerTwoSpaces.

@Test
public void testNumericNormalizerTwoSpaces() 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 3 with NumericNormalizer

use of org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer in project directory-ldap-api by apache.

the class NumericNormalizerTest method testNumericNormalizerOneSpace.

@Test
public void testNumericNormalizerOneSpace() 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 4 with NumericNormalizer

use of org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer in project directory-ldap-api by apache.

the class NumericNormalizerTest method testInsignifiantSpacesStringTwoChars.

@Test
public void testInsignifiantSpacesStringTwoChars() throws LdapException {
    Normalizer normalizer = new NumericNormalizer();
    assertEquals("11", normalizer.normalize("11"));
}
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 5 with NumericNormalizer

use of org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer in project directory-ldap-api by apache.

the class IntegerComparator method compare.

/**
 * Implementation of the Compare method
 */
private int compare(String backendValue, String assertValue) {
    LOG.debug("comparing Integer 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);
    }
    BigInteger b1 = new BigInteger(backendValue);
    BigInteger b2 = new BigInteger(assertValue);
    return b1.compareTo(b2);
}
Also used : NumericNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer) BigInteger(java.math.BigInteger) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

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