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 org.apache.directory.api.i18n.I18n;
24 import org.apache.directory.api.ldap.model.entry.Value;
25 import org.apache.directory.api.ldap.model.schema.LdapComparator;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class CsnComparator extends LdapComparator<Object>
42 {
43
44 private static final long serialVersionUID = 2L;
45
46
47 private static final Logger LOG = LoggerFactory.getLogger( CsnComparator.class );
48
49
50
51
52
53
54
55
56 public CsnComparator( String oid )
57 {
58 super( oid );
59 }
60
61
62
63
64
65 @Override
66 public int compare( Object csnObj1, Object csnObj2 )
67 {
68 if ( LOG.isDebugEnabled() )
69 {
70 LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) );
71 }
72
73 if ( csnObj1 == csnObj2 )
74 {
75 return 0;
76 }
77
78
79
80
81 if ( csnObj1 == null )
82 {
83 return -1;
84 }
85
86 if ( csnObj2 == null )
87 {
88 return 1;
89 }
90
91 String csnStr1;
92 String csnStr2;
93
94 if ( csnObj1 instanceof Value )
95 {
96 csnStr1 = ( ( Value ) csnObj1 ).getString();
97 }
98 else
99 {
100 csnStr1 = csnObj1.toString();
101 }
102
103 if ( csnObj2 instanceof Value )
104 {
105 csnStr2 = ( ( Value ) csnObj2 ).getString();
106 }
107 else
108 {
109 csnStr2 = csnObj2.toString();
110 }
111
112 return csnStr1.compareTo( csnStr2 );
113 }
114 }