Skip to content

Commit 2ca3123

Browse files
CopilotCopilot
andcommitted
Add JavaDoc comments to ValueHolder public methods and constructors
Added JavaDoc with Example Usage sections to all 9 non-private methods and constructors in ValueHolder.java: - Default and parameterized constructors - getValue(), setValue(), reset() - equals(), hashCode(), toString() - Static factory method of() Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 64fad9c commit 2ca3123

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

microsphere-java-core/src/main/java/io/microsphere/util/ValueHolder.java

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,100 @@ public class ValueHolder<V> {
4848

4949
private V value;
5050

51+
/**
52+
* Constructs an empty {@link ValueHolder} with a {@code null} initial value.
53+
*
54+
* <h3>Example Usage</h3>
55+
* <pre>{@code
56+
* ValueHolder<String> holder = new ValueHolder<>();
57+
* System.out.println(holder.getValue()); // Output: null
58+
* }</pre>
59+
*
60+
* @since 1.0.0
61+
*/
5162
public ValueHolder() {
5263
}
5364

65+
/**
66+
* Constructs a {@link ValueHolder} with the specified initial value.
67+
*
68+
* <h3>Example Usage</h3>
69+
* <pre>{@code
70+
* ValueHolder<Integer> holder = new ValueHolder<>(42);
71+
* System.out.println(holder.getValue()); // Output: 42
72+
* }</pre>
73+
*
74+
* @param value the initial value to hold, may be {@code null}
75+
* @since 1.0.0
76+
*/
5477
public ValueHolder(V value) {
5578
this.value = value;
5679
}
5780

81+
/**
82+
* Returns the currently held value.
83+
*
84+
* <h3>Example Usage</h3>
85+
* <pre>{@code
86+
* ValueHolder<String> holder = ValueHolder.of("Hello");
87+
* String value = holder.getValue(); // "Hello"
88+
* }</pre>
89+
*
90+
* @return the held value, or {@code null} if no value has been set
91+
* @since 1.0.0
92+
*/
5893
public V getValue() {
5994
return value;
6095
}
6196

97+
/**
98+
* Sets the held value to the specified value.
99+
*
100+
* <h3>Example Usage</h3>
101+
* <pre>{@code
102+
* ValueHolder<Double> holder = new ValueHolder<>();
103+
* holder.setValue(3.14);
104+
* System.out.println(holder.getValue()); // Output: 3.14
105+
* }</pre>
106+
*
107+
* @param value the value to hold, may be {@code null}
108+
* @since 1.0.0
109+
*/
62110
public void setValue(V value) {
63111
this.value = value;
64112
}
65113

114+
/**
115+
* Resets the held value to {@code null}.
116+
*
117+
* <h3>Example Usage</h3>
118+
* <pre>{@code
119+
* ValueHolder<String> holder = ValueHolder.of("data");
120+
* holder.reset();
121+
* System.out.println(holder.getValue()); // Output: null
122+
* }</pre>
123+
*
124+
* @since 1.0.0
125+
*/
66126
public void reset() {
67127
setValue(null);
68128
}
69129

130+
/**
131+
* Checks whether this {@link ValueHolder} is equal to another object. Two {@link ValueHolder}
132+
* instances are considered equal if they hold equal values as determined by {@link Objects#equals(Object, Object)}.
133+
*
134+
* <h3>Example Usage</h3>
135+
* <pre>{@code
136+
* ValueHolder<Integer> holder1 = ValueHolder.of(100);
137+
* ValueHolder<Integer> holder2 = ValueHolder.of(100);
138+
* System.out.println(holder1.equals(holder2)); // Output: true
139+
* }</pre>
140+
*
141+
* @param o the object to compare with
142+
* @return {@code true} if the other object is a {@link ValueHolder} holding an equal value, {@code false} otherwise
143+
* @since 1.0.0
144+
*/
70145
@Override
71146
public boolean equals(Object o) {
72147
if (this == o) {
@@ -79,18 +154,57 @@ public boolean equals(Object o) {
79154
return Objects.equals(value, that.value);
80155
}
81156

157+
/**
158+
* Returns the hash code of the held value using {@link Objects#hashCode(Object)}.
159+
*
160+
* <h3>Example Usage</h3>
161+
* <pre>{@code
162+
* ValueHolder<String> holder = ValueHolder.of("key");
163+
* int hash = holder.hashCode(); // hash code of "key"
164+
* }</pre>
165+
*
166+
* @return the hash code of the held value, or {@code 0} if the value is {@code null}
167+
* @since 1.0.0
168+
*/
82169
@Override
83170
public int hashCode() {
84171
return Objects.hashCode(value);
85172
}
86173

174+
/**
175+
* Returns a string representation of this {@link ValueHolder} in the format
176+
* {@code ValueHolder{value=...}}.
177+
*
178+
* <h3>Example Usage</h3>
179+
* <pre>{@code
180+
* ValueHolder<String> holder = ValueHolder.of("test");
181+
* System.out.println(holder.toString()); // Output: ValueHolder{value=test}
182+
* }</pre>
183+
*
184+
* @return a string representation of this holder and its value
185+
* @since 1.0.0
186+
*/
87187
@Override
88188
public String toString() {
89189
return "ValueHolder{" +
90190
"value=" + value +
91191
'}';
92192
}
93193

194+
/**
195+
* Creates a new {@link ValueHolder} containing the specified value.
196+
*
197+
* <h3>Example Usage</h3>
198+
* <pre>{@code
199+
* ValueHolder<String> holder = ValueHolder.of("Hello World");
200+
* System.out.println(holder.getValue()); // Output: Hello World
201+
* }</pre>
202+
*
203+
* @param value the value to hold, may be {@code null}
204+
* @param <V> the type of the value
205+
* @return a new {@link ValueHolder} containing the given value
206+
* @since 1.0.0
207+
*/
94208
public static <V> ValueHolder<V> of(V value) {
95209
return new ValueHolder<>(value);
96210
}

0 commit comments

Comments
 (0)