11/*
22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33 *
4- * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
4+ * Copyright (c) 2012-2015 Oracle and/or its affiliates. All rights reserved.
55 *
66 * The contents of this file are subject to the terms of either the GNU
77 * General Public License Version 2 only ("GPL") or the Common Development
4545 * @author Marek Potociar (marek.potociar at oracle.com)
4646 */
4747public final class Values {
48+
4849 private static final LazyValue EMPTY = new LazyValue () {
4950 @ Override
5051 public Object get () {
@@ -100,7 +101,7 @@ public static <T, E extends Throwable> UnsafeValue<T, E> emptyUnsafe() {
100101 /**
101102 * Get a new constant {@link Value value provider} whose {@link Value#get() get()}
102103 * method always returns the instance supplied to the {@code value} parameter.
103- *
104+ * <p/>
104105 * In case the supplied value constant is {@code null}, an {@link #empty() empty} value
105106 * provider is returned.
106107 *
@@ -113,6 +114,7 @@ public static <T> Value<T> of(final T value) {
113114 }
114115
115116 private static class InstanceValue <T > implements Value <T > {
117+
116118 private final T value ;
117119
118120 public InstanceValue (final T value ) {
@@ -125,9 +127,13 @@ public T get() {
125127 }
126128
127129 @ Override
128- public boolean equals (Object o ) {
129- if (this == o ) return true ;
130- if (o == null || getClass () != o .getClass ()) return false ;
130+ public boolean equals (final Object o ) {
131+ if (this == o ) {
132+ return true ;
133+ }
134+ if (o == null || getClass () != o .getClass ()) {
135+ return false ;
136+ }
131137
132138 return value .equals (((InstanceValue ) o ).value );
133139 }
@@ -146,7 +152,7 @@ public String toString() {
146152 /**
147153 * Get a new constant {@link UnsafeValue value provider} whose {@link UnsafeValue#get() get()}
148154 * method always returns the instance supplied to the {@code value} parameter.
149- *
155+ * <p/>
150156 * In case the supplied value constant is {@code null}, an {@link #emptyUnsafe() empty} value
151157 * provider is returned.
152158 *
@@ -159,6 +165,7 @@ public static <T, E extends Throwable> UnsafeValue<T, E> unsafe(final T value) {
159165 }
160166
161167 private static class InstanceUnsafeValue <T , E extends Throwable > implements UnsafeValue <T , E > {
168+
162169 private final T value ;
163170
164171 public InstanceUnsafeValue (final T value ) {
@@ -171,9 +178,13 @@ public T get() {
171178 }
172179
173180 @ Override
174- public boolean equals (Object o ) {
175- if (this == o ) return true ;
176- if (o == null || getClass () != o .getClass ()) return false ;
181+ public boolean equals (final Object o ) {
182+ if (this == o ) {
183+ return true ;
184+ }
185+ if (o == null || getClass () != o .getClass ()) {
186+ return false ;
187+ }
177188
178189 return value .equals (((InstanceUnsafeValue ) o ).value );
179190 }
@@ -192,11 +203,11 @@ public String toString() {
192203 /**
193204 * Get a new "throwing" {@link UnsafeValue unsafe value provider} whose {@link UnsafeValue#get() get()}
194205 * method always throws the exception supplied to the {@code throwable} parameter.
195- *
206+ * <p/>
196207 * In case the supplied throwable is {@code null}, an {@link NullPointerException} is thrown.
197208 *
198- * @param <T> value type.
199- * @param <E> exception type.
209+ * @param <T> value type.
210+ * @param <E> exception type.
200211 * @param throwable throwable instance to be thrown.
201212 * @return "throwing" unsafe value provider.
202213 * @throws NullPointerException in case the supplied throwable instance is {@code null}.
@@ -210,6 +221,7 @@ public static <T, E extends Throwable> UnsafeValue<T, E> throwing(final E throwa
210221 }
211222
212223 private static class ExceptionValue <T , E extends Throwable > implements UnsafeValue <T , E > {
224+
213225 private final E throwable ;
214226
215227 public ExceptionValue (final E throwable ) {
@@ -222,9 +234,13 @@ public T get() throws E {
222234 }
223235
224236 @ Override
225- public boolean equals (Object o ) {
226- if (this == o ) return true ;
227- if (o == null || getClass () != o .getClass ()) return false ;
237+ public boolean equals (final Object o ) {
238+ if (this == o ) {
239+ return true ;
240+ }
241+ if (o == null || getClass () != o .getClass ()) {
242+ return false ;
243+ }
228244
229245 return throwable .equals (((ExceptionValue ) o ).throwable );
230246 }
@@ -242,7 +258,7 @@ public String toString() {
242258
243259 /**
244260 * Get a new lazily initialized {@link Value value provider}.
245- *
261+ * <p/>
246262 * The value returned by its {@link Value#get() get()} method is lazily retrieved during a first
247263 * call to the method from the supplied {@code delegate} value provider and is then cached for
248264 * a subsequent retrieval.
@@ -267,7 +283,7 @@ public static <T> LazyValue<T> lazy(final Value<T> delegate) {
267283
268284 /**
269285 * Get a new eagerly initialized {@link Value value provider}.
270- *
286+ * <p/>
271287 * The value returned by its {@link Value#get() get()} method is eagerly computed from the supplied
272288 * {@code delegate} value provider and is then stored in a final field for a subsequent retrieval.
273289 * <p>
@@ -289,9 +305,10 @@ public static <T> Value<T> eager(final Value<T> delegate) {
289305 }
290306
291307 private static class EagerValue <T > implements Value <T > {
308+
292309 private final T result ;
293310
294- private EagerValue (Value <T > value ) {
311+ private EagerValue (final Value <T > value ) {
295312 this .result = value .get ();
296313 }
297314
@@ -302,6 +319,7 @@ public T get() {
302319 }
303320
304321 private static class LazyValueImpl <T > implements LazyValue <T > {
322+
305323 private final Object lock ;
306324 private final Value <T > delegate ;
307325
@@ -332,9 +350,13 @@ public boolean isInitialized() {
332350 }
333351
334352 @ Override
335- public boolean equals (Object o ) {
336- if (this == o ) return true ;
337- if (o == null || getClass () != o .getClass ()) return false ;
353+ public boolean equals (final Object o ) {
354+ if (this == o ) {
355+ return true ;
356+ }
357+ if (o == null || getClass () != o .getClass ()) {
358+ return false ;
359+ }
338360
339361 return delegate .equals (((LazyValueImpl ) o ).delegate );
340362 }
@@ -352,7 +374,7 @@ public String toString() {
352374
353375 /**
354376 * Get a new lazily initialized {@link UnsafeValue unsafe value provider}.
355- *
377+ * <p/>
356378 * The value returned by its {@link UnsafeValue#get() get()} method is lazily retrieved during a first
357379 * call to the method from the supplied {@code delegate} value provider and is then cached for
358380 * a subsequent retrieval.
@@ -380,6 +402,7 @@ public static <T, E extends Throwable> LazyUnsafeValue<T, E> lazy(final UnsafeVa
380402 }
381403
382404 private static class LazyUnsafeValueImpl <T , E extends Throwable > implements LazyUnsafeValue <T , E > {
405+
383406 private final Object lock ;
384407 private final UnsafeValue <T , E > delegate ;
385408
@@ -400,7 +423,7 @@ public T get() throws E {
400423 if (result == null ) {
401424 try {
402425 result = Values .unsafe (delegate .get ());
403- } catch (Throwable e ) {
426+ } catch (final Throwable e ) {
404427 //noinspection unchecked
405428 result = Values .throwing ((E ) e );
406429 }
@@ -417,9 +440,13 @@ public boolean isInitialized() {
417440 }
418441
419442 @ Override
420- public boolean equals (Object o ) {
421- if (this == o ) return true ;
422- if (o == null || getClass () != o .getClass ()) return false ;
443+ public boolean equals (final Object o ) {
444+ if (this == o ) {
445+ return true ;
446+ }
447+ if (o == null || getClass () != o .getClass ()) {
448+ return false ;
449+ }
423450
424451 return delegate .equals (((LazyUnsafeValueImpl ) o ).delegate );
425452 }
0 commit comments