-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lazy vals for complicated calculations
- Loading branch information
1 parent
c7895cd
commit 5ff6d62
Showing
3 changed files
with
43 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.jetbrains.bsp.bazel.commons; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
||
public abstract class Lazy<T> { | ||
private Optional<Optional<T>> value = Optional.empty(); | ||
|
||
protected abstract Supplier<Optional<T>> calculateValue(); | ||
|
||
public Optional<T> getValue() { | ||
if (value.isEmpty()) { | ||
value = Optional.of(calculateValue().get()); | ||
} | ||
|
||
return value.get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters