1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.model.schema.comparators;
21
22
23
24 import org.apache.directory.api.i18n.I18n;
25 import org.apache.directory.api.ldap.model.exception.LdapException;
26 import org.apache.directory.api.ldap.model.schema.LdapComparator;
27 import org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31
32
33
34
35
36
37 public class NumericStringComparator extends LdapComparator<String>
38 {
39
40 private static final long serialVersionUID = 2L;
41
42
43 private static final Logger LOG = LoggerFactory.getLogger( NumericStringComparator.class );
44
45
46
47
48
49
50
51
52 public NumericStringComparator( String oid )
53 {
54 super( oid );
55 }
56
57
58
59
60
61 public int compare( String backendValue, String assertValue )
62 {
63 if ( LOG.isDebugEnabled() )
64 {
65 LOG.debug( I18n.msg( I18n.MSG_13754_COMPARING_NUMERIC_STRING_ORDERING, backendValue, assertValue ) );
66 }
67
68
69
70
71 if ( backendValue == assertValue )
72 {
73 return 0;
74 }
75
76
77
78
79 if ( ( backendValue == null ) || ( assertValue == null ) )
80 {
81 return backendValue == null ? -1 : 1;
82 }
83
84
85
86 NumericNormalizer normalizer = new NumericNormalizer();
87
88 try
89 {
90 backendValue = normalizer.normalize( backendValue );
91 }
92 catch ( LdapException le )
93 {
94 throw new IllegalArgumentException( I18n.err( I18n.ERR_13724_INVALID_VALUE, backendValue ), le );
95 }
96 try
97 {
98 assertValue = normalizer.normalize( assertValue );
99 }
100 catch ( LdapException le )
101 {
102 throw new IllegalArgumentException( I18n.err( I18n.ERR_13724_INVALID_VALUE, assertValue ), le );
103 }
104
105 return backendValue.compareTo( assertValue );
106 }
107 }