1. /*
  2. * Copyright 2003-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.collections.keyvalue;
  17. import org.apache.commons.collections.KeyValue;
  18. /**
  19. * Abstract pair class to assist with creating KeyValue and MapEntry implementations.
  20. *
  21. * @since Commons Collections 3.0
  22. * @version $Revision: 1.3 $ $Date: 2004/02/18 01:00:08 $
  23. *
  24. * @author James Strachan
  25. * @author Michael A. Smith
  26. * @author Neil O'Toole
  27. * @author Stephen Colebourne
  28. */
  29. public abstract class AbstractKeyValue implements KeyValue {
  30. /** The key */
  31. protected Object key;
  32. /** The value */
  33. protected Object value;
  34. /**
  35. * Constructs a new pair with the specified key and given value.
  36. *
  37. * @param key the key for the entry, may be null
  38. * @param value the value for the entry, may be null
  39. */
  40. protected AbstractKeyValue(Object key, Object value) {
  41. super();
  42. this.key = key;
  43. this.value = value;
  44. }
  45. /**
  46. * Gets the key from the pair.
  47. *
  48. * @return the key
  49. */
  50. public Object getKey() {
  51. return key;
  52. }
  53. /**
  54. * Gets the value from the pair.
  55. *
  56. * @return the value
  57. */
  58. public Object getValue() {
  59. return value;
  60. }
  61. /**
  62. * Gets a debugging String view of the pair.
  63. *
  64. * @return a String view of the entry
  65. */
  66. public String toString() {
  67. return new StringBuffer()
  68. .append(getKey())
  69. .append('=')
  70. .append(getValue())
  71. .toString();
  72. }
  73. }