1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * https://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20 package org.apache.directory.api.ldap.model.schema;
21
22
23 import java.io.Serializable;
24 import java.util.Comparator;
25
26 import org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer;
27
28
29 /**
30 * An class used for Comparator. It inherits from the general AbstractAdsSchemaObject class. It
31 * also implements the Comparator interface
32 *
33 * @param <T> The comparator type
34 *
35 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
36 */
37 public abstract class LdapComparator<T> extends LoadableSchemaObject implements Comparator<T>, Serializable
38 {
39 /** The serial version UID */
40 private static final long serialVersionUID = 2L;
41
42 /** A default normalizer*/
43 protected Normalizer normalizer = new NoOpNormalizer();
44
45
46 /**
47 * Create a new instance of a Comparator
48 * @param oid The associated OID
49 */
50 protected LdapComparator( String oid )
51 {
52 super( SchemaObjectType.COMPARATOR, oid );
53 }
54
55
56 /**
57 * Store the SchemaManager in this instance. It may be necessary for some
58 * comparator which needs to have access to the oidNormalizer Map.
59 *
60 * @param schemaManager the schemaManager to store
61 */
62 public void setSchemaManager( SchemaManager schemaManager )
63 {
64 // Do nothing (general case).
65 }
66
67
68 /**
69 * {@inheritDoc}
70 */
71 @Override
72 public int hashCode()
73 {
74 int hash = h;
75
76 if ( normalizer != null )
77 {
78 hash = hash * 17 + normalizer.hashCode();
79 }
80
81 return hash;
82 }
83
84
85 /**
86 * {@inheritDoc}
87 */
88 @Override
89 public boolean equals( Object o )
90 {
91 if ( !super.equals( o ) )
92 {
93 return false;
94 }
95
96 if ( !( o instanceof LdapComparator<?> ) )
97 {
98 return false;
99 }
100
101 LdapComparator<?> that = ( LdapComparator<?> ) o;
102
103 // Compare the normalizer
104 if ( normalizer != null )
105 {
106 return normalizer.equals( that.getNormalizer() );
107 }
108 else
109 {
110 return that.getNormalizer() == null;
111 }
112 }
113
114
115 /**
116 * @return The associated normalizer
117 */
118 public Normalizer getNormalizer()
119 {
120 return normalizer;
121 }
122
123
124 /**
125 * {@inheritDoc}
126 */
127 @Override
128 public String toString()
129 {
130 return objectType + " " + DescriptionUtils.getDescription( this );
131 }
132 }