Skip to content

Commit

Permalink
add missing javadoc to class and main constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrasd authored Nov 5, 2020
1 parent b1548de commit 4d817d5
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,38 @@

import java.util.function.Supplier;

/**
* A lazily evaluated object.
*
* <p>Useful as a wrapper to hold values which are potentially expensive to
* calculate, but might sometimes not be requested.</p>
*
* @param <T> the (arbitrary) type of data to hold
*/
public class LazyEvaluatedObject<T> implements Supplier<T> {
private T value = null;
private boolean evaluated = false;
private Supplier<T> evaluator;

/**
* Constructs a {@link LazyEvaluatedObject} using a {@code evaluator} (supplier function) which
* returns a value of generic type {@code T}, when requested from this object.
*
* @param evaluator a {@link Supplier} function which returns the value of interest when executed
*/
public LazyEvaluatedObject(Supplier<T> evaluator) {
this.evaluator = evaluator;
}

/**
* Generic constructor for a {@link LazyEvaluatedObject} using a {@code value} of generic type
* {@code T}.
* Constructs a {@link LazyEvaluatedObject} using an already known {@code value} of generic
* type {@code T}.
*
* <p>This simply wraps the value with a supplier method, but can be useful in situations where
* sometimes an expensive to calculate value is already know, but one wants to use the lazy
* evaluated interface for the remaining cases.</p>
*
* @param value the value to store
*/
public LazyEvaluatedObject(T value) {
this.value = value;
Expand Down

0 comments on commit 4d817d5

Please sign in to comment.