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.schema.LdapComparator;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28
29
30
31
32
33
34
35
36 public class CsnSidComparator extends LdapComparator<String>
37 {
38
39 private static final long serialVersionUID = 2L;
40
41
42 private static final Logger LOG = LoggerFactory.getLogger( CsnSidComparator.class );
43
44
45
46
47
48
49
50
51 public CsnSidComparator( String oid )
52 {
53 super( oid );
54 }
55
56
57
58
59
60 public int compare( String sidStr1, String sidStr2 )
61 {
62 if ( LOG.isDebugEnabled() )
63 {
64 LOG.debug( I18n.msg( I18n.MSG_13744_COMPARING_CSN_SID, sidStr1, sidStr2 ) );
65 }
66
67
68
69
70 if ( sidStr1 == null )
71 {
72 return ( sidStr2 == null ) ? 0 : -1;
73 }
74
75 if ( sidStr2 == null )
76 {
77 return 1;
78 }
79
80 int sid1 = 0;
81 int sid2;
82
83 try
84 {
85 sid1 = Integer.parseInt( sidStr1, 16 );
86 }
87 catch ( NumberFormatException nfe )
88 {
89 return -1;
90 }
91
92 try
93 {
94 sid2 = Integer.parseInt( sidStr2, 16 );
95 }
96 catch ( NumberFormatException nfe )
97 {
98 return 1;
99 }
100
101 if ( sid1 > sid2 )
102 {
103 return 1;
104 }
105 else if ( sid2 > sid1 )
106 {
107 return -1;
108 }
109
110 return 0;
111 }
112 }