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 based on a Tuple which can optionally reference the
25 * indexed obj 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 ForwardIndexEntry<V,O> implements IndexEntry<V,O>
31 {
32 /** The underlying Tuple */
33 private final Tuple<V,Long> tuple = new Tuple<V,Long>();
34
35 /** The referenced obj if loaded from the store */
36 private O obj;
37
38
39 /**
40 * Sets the key value tuple represented by this ForwardIndexEntry 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 ForwardIndexEntry
45 * @param entry the resusitated obj if any
46 */
47 public void setTuple( Tuple<V,Long> tuple, O entry )
48 {
49 this.tuple.setKey( tuple.getKey() );
50 this.tuple.setValue( tuple.getValue() );
51 this.obj = entry;
52 }
53
54
55 public Long getId()
56 {
57 return tuple.getValue();
58 }
59
60
61 public V getValue()
62 {
63 return tuple.getKey();
64 }
65
66
67 public void setId( Long id )
68 {
69 tuple.setValue( id );
70 }
71
72
73 public void setValue( V value )
74 {
75 tuple.setKey( value );
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.getValue() );
114 tuple.setValue( entry.getId() );
115 }
116
117
118 public String toString()
119 {
120 StringBuilder buf = new StringBuilder();
121 buf.append( "ForwardIndexEntry[ " );
122 buf.append( tuple.getKey() );
123 buf.append( ", " );
124 buf.append( tuple.getValue() );
125 buf.append( " ]" );
126 return buf.toString();
127 }
128 }