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 * http://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.server.xdbm;
21
22
23 /**
24 * An index id value pair which can optionally reference the indexed obj
25 * if one has already been loaded.
26 *
27 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
28 * @version $Rev: 642800 $
29 */
30 public class ReverseIndexEntry<V,O> implements IndexEntry<V,O>
31 {
32 /** The underlying Tuple */
33 private final Tuple<Long,V> tuple = new Tuple<Long,V>();
34
35 /** The indexed object if loaded from the store */
36 private O obj;
37
38
39 /**
40 * Sets the Tuple value represented by this ReverseIndexEntry optionally
41 * setting the obj associated with the id if one was loaded from the
42 * master table.
43 *
44 * @param tuple the tuple for the ReverseIndexEntry
45 * @param obj the resusitated object that is indexed if any
46 */
47 public void setTuple( Tuple<Long,V> tuple, O obj )
48 {
49 this.tuple.setKey( tuple.getKey() );
50 this.tuple.setValue( tuple.getValue() );
51 this.obj = obj;
52 }
53
54
55 public Long getId()
56 {
57 return tuple.getKey();
58 }
59
60
61 public V getValue()
62 {
63 return tuple.getValue();
64 }
65
66
67 public void setId( Long id )
68 {
69 tuple.setKey( id );
70 }
71
72
73 public void setValue( V key )
74 {
75 tuple.setValue( key );
76 }
77
78
79 public O getObject()
80 {
81 if ( obj == null )
82 {
83 return null;
84 }
85
86 return obj;
87 }
88
89
90 public void setObject( O obj )
91 {
92 this.obj = obj;
93 }
94
95
96 public Tuple getTuple()
97 {
98 return tuple;
99 }
100
101
102 public void clear()
103 {
104 obj = null;
105 tuple.setKey( null );
106 tuple.setValue( null );
107 }
108
109
110 public void copy( IndexEntry<V, O> entry )
111 {
112 this.obj = entry.getObject();
113 tuple.setKey( entry.getId() );
114 tuple.setValue( entry.getValue() );
115 }
116
117
118 public String toString()
119 {
120 StringBuilder buf = new StringBuilder();
121 buf.append( "ReverseIndexEntry[ " );
122 buf.append( tuple.getValue() );
123 buf.append( ", " );
124 buf.append( tuple.getKey() );
125 buf.append( " ]" );
126 return buf.toString();
127 }
128 }