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 * A key/value tuple for simple two column persistent Tables with sorted keys. 25 * 26 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 27 * @version $Rev: 640657 $ 28 */ 29 public class Tuple<K, V> 30 { 31 /** the key for this Tuple */ 32 private K key; 33 /** the value for this Tuple */ 34 private V value; 35 36 37 /** 38 * Do nothing default that has a null key and null value. 39 */ 40 public Tuple() 41 { 42 // does nothing! 43 } 44 45 46 /** 47 * Creates a Tuple using a key and a value. 48 * 49 * @param key the key to set 50 * @param value the value to set 51 */ 52 public Tuple( K key, V value ) 53 { 54 this.key = key; 55 this.value = value; 56 } 57 58 59 /** 60 * Gets the key for this Tuple. 61 * 62 * @return the Tuple's key 63 */ 64 public K getKey() 65 { 66 return key; 67 } 68 69 70 /** 71 * Sets the key for this Tuple. 72 * 73 * @param key the new key to set 74 * @return this Tuple itself to set and return 75 */ 76 public Tuple<K,V> setKey( K key ) 77 { 78 this.key = key; 79 return this; 80 } 81 82 83 /** 84 * Gets the value for this Tuple. 85 * 86 * @return the Tuple's value 87 */ 88 public V getValue() 89 { 90 return value; 91 } 92 93 94 /** 95 * Sets the value for this Tuple. 96 * 97 * @param value the new value to set 98 * @return this Tuple itself to set and return 99 */ 100 public Tuple<K,V> setValue( V value ) 101 { 102 this.value = value; 103 return this; 104 } 105 106 107 /** 108 * Sets both the key and the value for this Tuple in one call and returns 109 * this Tuple object. This is useful for setting the tuples key and value 110 * then returning it. 111 * 112 * @param key the new key to set 113 * @param value the new value to set 114 * @return this Tuple itself to set and return 115 */ 116 public Tuple<K,V> setBoth( K key, V value ) 117 { 118 this.key = key; 119 this.value = value; 120 return this; 121 } 122 123 124 125 126 /** 127 * Sets both the key and the value for this Tuple in one call and returns 128 * this Tuple object. This is useful for setting the tuples key and value 129 * then returning it. 130 * 131 * @param tupleToCopy the tuple to copy 132 * @return this Tuple itself to set and return 133 */ 134 public Tuple<K,V> setBoth( Tuple<K,V> tupleToCopy ) 135 { 136 this.key = tupleToCopy.key; 137 this.value = tupleToCopy.value; 138 return this; 139 } 140 141 142 public String toString() 143 { 144 StringBuilder buf = new StringBuilder(); 145 buf.append( "Tuple( '" ); 146 buf.append( key ); 147 buf.append( "', '" ); 148 buf.append( value ); 149 buf.append( "' )" ); 150 return buf.toString(); 151 } 152 }