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 import java.text.ParseException;
25
26 import org.apache.directory.api.i18n.I18n;
27 import org.apache.directory.api.ldap.model.schema.LdapComparator;
28 import org.apache.directory.api.ldap.model.schema.PrepareString;
29 import org.apache.directory.api.util.GeneralizedTime;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34
35
36
37
38
39 public class GeneralizedTimeComparator extends LdapComparator<String>
40 {
41
42 private static final long serialVersionUID = 2L;
43
44
45 private static final Logger LOG = LoggerFactory.getLogger( GeneralizedTimeComparator.class );
46
47
48
49
50
51
52 public GeneralizedTimeComparator( String oid )
53 {
54 super( oid );
55 }
56
57
58
59
60
61 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "ES_COMPARING_PARAMETER_STRING_WITH_EQ",
62 justification = "false positive")
63 public int compare( String backendValue, String assertValue )
64 {
65 LOG.debug( "comparing generalizedTimeOrdering objects '{}' with '{}'", backendValue, assertValue );
66
67
68
69
70 if ( backendValue == assertValue )
71 {
72 return 0;
73 }
74
75
76
77
78 if ( ( backendValue == null ) || ( assertValue == null ) )
79 {
80 return ( backendValue == null ? -1 : 1 );
81 }
82
83
84
85 GeneralizedTime backendTime;
86 try
87 {
88 String prepared = PrepareString.normalize( backendValue, PrepareString.StringType.DIRECTORY_STRING );
89 backendTime = new GeneralizedTime( prepared );
90 }
91 catch ( IOException ioe )
92 {
93 throw new IllegalArgumentException( I18n.err( I18n.ERR_04224, backendValue ) );
94 }
95 catch ( ParseException pe )
96 {
97 throw new IllegalArgumentException( I18n.err( I18n.ERR_04224, backendValue ) );
98 }
99
100 GeneralizedTime assertTime;
101 try
102 {
103 String prepared = PrepareString.normalize( assertValue, PrepareString.StringType.DIRECTORY_STRING );
104 assertTime = new GeneralizedTime( prepared );
105 }
106 catch ( IOException ioe )
107 {
108 throw new IllegalArgumentException( I18n.err( I18n.ERR_04224, assertValue ) );
109 }
110 catch ( ParseException pe )
111 {
112 throw new IllegalArgumentException( I18n.err( I18n.ERR_04224, assertValue ) );
113 }
114
115 return backendTime.compareTo( assertTime );
116 }
117 }