001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020 package org.apache.directory.server.xdbm; 021 022 023 /** 024 * An index id value pair which can optionally reference the indexed obj 025 * if one has already been loaded. 026 * 027 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 028 * @version $Rev: 917312 $ 029 */ 030 public class ReverseIndexEntry<V, O, ID> implements IndexEntry<V, O, ID> 031 { 032 /** The underlying Tuple */ 033 private final Tuple<ID, V> tuple = new Tuple<ID, V>(); 034 035 /** The indexed object if loaded from the store */ 036 private O obj; 037 038 039 /** 040 * Sets the Tuple value represented by this ReverseIndexEntry optionally 041 * setting the obj associated with the id if one was loaded from the 042 * master table. 043 * 044 * @param tuple the tuple for the ReverseIndexEntry 045 * @param obj the resusitated object that is indexed if any 046 */ 047 public void setTuple( Tuple<ID, V> tuple, O obj ) 048 { 049 this.tuple.setKey( tuple.getKey() ); 050 this.tuple.setValue( tuple.getValue() ); 051 this.obj = obj; 052 } 053 054 055 public ID getId() 056 { 057 return tuple.getKey(); 058 } 059 060 061 public V getValue() 062 { 063 return tuple.getValue(); 064 } 065 066 067 public void setId( ID id ) 068 { 069 tuple.setKey( id ); 070 } 071 072 073 public void setValue( V key ) 074 { 075 tuple.setValue( key ); 076 } 077 078 079 public O getObject() 080 { 081 if ( obj == null ) 082 { 083 return null; 084 } 085 086 return obj; 087 } 088 089 090 public void setObject( O obj ) 091 { 092 this.obj = obj; 093 } 094 095 096 public Tuple<ID, V> getTuple() 097 { 098 return tuple; 099 } 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, ID> 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 }