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 import java.io.IOException;
24
25 import org.apache.directory.api.i18n.I18n;
26 import org.apache.directory.api.ldap.model.schema.LdapComparator;
27 import org.apache.directory.api.ldap.model.schema.PrepareString;
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 public NumericStringComparator( String oid )
51 {
52 super( oid );
53 }
54
55
56
57
58
59 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "ES_COMPARING_PARAMETER_STRING_WITH_EQ",
60 justification = "false positive")
61 public int compare( String backendValue, String assertValue )
62 {
63 LOG.debug( "comparing numericStringOrdering objects '{}' with '{}'", backendValue, assertValue );
64
65
66
67
68 if ( backendValue == assertValue )
69 {
70 return 0;
71 }
72
73
74
75
76 if ( ( backendValue == null ) || ( assertValue == null ) )
77 {
78 return ( backendValue == null ? -1 : 1 );
79 }
80
81
82
83 try
84 {
85 backendValue = PrepareString.normalize( backendValue, PrepareString.StringType.NUMERIC_STRING );
86 }
87 catch ( IOException e )
88 {
89 throw new IllegalArgumentException( I18n.err( I18n.ERR_04224, backendValue ) );
90 }
91 try
92 {
93 assertValue = PrepareString.normalize( assertValue, PrepareString.StringType.NUMERIC_STRING );
94 }
95 catch ( IOException e )
96 {
97 throw new IllegalArgumentException( I18n.err( I18n.ERR_04224, assertValue ) );
98 }
99
100 return backendValue.compareTo( assertValue );
101 }
102 }