source: src/main/java/agents/org/apache/commons/lang/mutable/MutableObject.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 3.5 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package agents.org.apache.commons.lang.mutable;
19
20import java.io.Serializable;
21
22/**
23 * A mutable <code>Object</code> wrapper.
24 *
25 * @since 2.1
26 * @author Apache Software Foundation
27 * @version $Id: MutableObject.java 905636 2010-02-02 14:03:32Z niallp $
28 */
29public class MutableObject implements Mutable, Serializable {
30
31 /**
32 * Required for serialization support.
33 *
34 * @see java.io.Serializable
35 */
36 private static final long serialVersionUID = 86241875189L;
37
38 /** The mutable value. */
39 private Object value;
40
41 /**
42 * Constructs a new MutableObject with the default value of <code>null</code>.
43 */
44 public MutableObject() {
45 super();
46 }
47
48 /**
49 * Constructs a new MutableObject with the specified value.
50 *
51 * @param value the initial value to store
52 */
53 public MutableObject(Object value) {
54 super();
55 this.value = value;
56 }
57
58 //-----------------------------------------------------------------------
59 /**
60 * Gets the value.
61 *
62 * @return the value, may be null
63 */
64 public Object getValue() {
65 return this.value;
66 }
67
68 /**
69 * Sets the value.
70 *
71 * @param value the value to set
72 */
73 public void setValue(Object value) {
74 this.value = value;
75 }
76
77 //-----------------------------------------------------------------------
78 /**
79 * Compares this object against the specified object. The result is <code>true</code> if and only if the argument
80 * is not <code>null</code> and is a <code>MutableObject</code> object that contains the same <code>Object</code>
81 * value as this object.
82 *
83 * @param obj the object to compare with, null returns false
84 * @return <code>true</code> if the objects are the same; <code>false</code> otherwise.
85 */
86 public boolean equals(Object obj) {
87 if (obj instanceof MutableObject) {
88 Object other = ((MutableObject) obj).value;
89 return value == other || (value != null && value.equals(other));
90 }
91 return false;
92 }
93
94 /**
95 * Returns the value's hash code or <code>0</code> if the value is <code>null</code>.
96 *
97 * @return the value's hash code or <code>0</code> if the value is <code>null</code>.
98 */
99 public int hashCode() {
100 return value == null ? 0 : value.hashCode();
101 }
102
103 //-----------------------------------------------------------------------
104 /**
105 * Returns the String value of this mutable.
106 *
107 * @return the mutable value as a string
108 */
109 public String toString() {
110 return value == null ? "null" : value.toString();
111 }
112
113}
Note: See TracBrowser for help on using the repository browser.