Skip to content

Commit

Permalink
Rename Lazy<T> to Late<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
glitchruk committed Nov 15, 2024
1 parent bbf967d commit 74984c3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TinyTools

![Version](https://img.shields.io/badge/Version-0.2.0-blue)
![Version](https://img.shields.io/badge/Version-0.3.0-blue)
![License: LGPLv3](https://img.shields.io/badge/License-LGPLv3-blue.svg)

A collection of small, useful tools for Java development. TinyTools aims to provide lightweight utilities that simplify
Expand Down Expand Up @@ -50,7 +50,7 @@ Add the following dependency to your `pom.xml` file:
<dependency>
<groupId>com.github.glitchruk</groupId>
<artifactId>tinytools</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
</dependency>
```

Expand All @@ -61,7 +61,7 @@ Add the following dependency to your `pom.xml` file:

```groovy
dependencies {
implementation files('libs/tinytools-0.2.0.jar')
implementation files('libs/tinytools-0.3.0.jar')
}
```

Expand All @@ -71,14 +71,14 @@ A list of the components in this library.

| Class | Description |
|--------------------------------------------------------------------------------|------------------------------------------------------|
| [`Lazy<T>`](src/main/java/com/github/glitchruk/tinytools/concurrent/Lazy.java) | A thread-safe utility class for lazy initialization. |
| [`Late<T>`](src/main/java/com/github/glitchruk/tinytools/concurrent/Late.java) | A thread-safe utility class for late initialization. |
| [`Memo<T>`](src/main/java/com/github/glitchruk/tinytools/concurrent/Memo.java) | A thread-safe utility class for memoization. |

### Lazy\<T\>
### Late\<T\>

The `Lazy` class allows for deferred initialization of an object, where the value is only set once and accessed multiple
times. This is useful in cases where an expensive computation or initialization needs to be deferred until the first
access, while ensuring thread safety and efficient access for subsequent reads.
The `Late` class allows for deferred initialization of an object, where the value is only set once and accessed multiple
times. This is useful in cases where an expensive computation or initialization needs to only be performed once, while
ensuring thread safety and efficient access for subsequent reads.

#### Key Features

Expand All @@ -90,7 +90,7 @@ access, while ensuring thread safety and efficient access for subsequent reads.

```java
public final class Person {
private final Lazy<Integer> age = new Lazy<>();
private final Late<Integer> age = new Late<>();

public Person() {
// Constructor does not set age; it will be set later
Expand All @@ -109,8 +109,8 @@ public final class Person {
public class Main {
public static void main(String[] args) {
Person person = new Person();
person.initializeAge(25); // Deferred initialization
System.out.println("Age: " + person.getAge()); // Outputs: Age: 25
person.initializeAge(42); // Deferred initialization
System.out.println("Age: " + person.getAge()); // Outputs: Age: 42
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = 'com.github.glitchruk'
version = '0.2.0'
version = '0.3.0'

apply plugin: 'java'

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.glitchruk</groupId>
<artifactId>tinytools</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>

<properties>
<maven.compiler.source>21</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
*/

/**
* A thread-safe utility class for lazy initialization.
* A thread-safe utility class for late initialization.
* <p>
* The {@code Lazy} class provides a mechanism for deferred initialization
* The {@code Late} class provides a mechanism for deferred initialization
* of an object. The value is set only once and can then be accessed multiple times.
* This is particularly useful in scenarios where an expensive computation or
* initialization should be postponed until the first access, while maintaining
* thread safety and ensuring efficient subsequent reads.
* initialization should only be performed once, while maintaining thread safety
* and ensuring efficient subsequent reads.
* </p>
*
* <p><strong>Key Features:</strong></p>
Expand Down Expand Up @@ -54,7 +54,7 @@
* <p><strong>Example Usage:</strong></p>
* <pre>{@code
* public final class Person {
* private final Lazy<Integer> age = new Lazy<>();
* private final Late<Integer> age = new Late<>();
*
* public Person() {
* // Constructor does not set age; it will be initialized later
Expand All @@ -79,16 +79,16 @@
* }
* }</pre>
*
* @param <T> the type of the value to be lazily initialized
* @param <T> the type of the value to be initialized late
*/
public class Lazy<T> {
public class Late<T> {
private T value;
private boolean initialized;

/**
* Creates a new {@code Lazy} instance with no initial value.
* Creates a new {@code Late} instance with no initial value.
*/
public Lazy() {
public Late() {
this.value = null;
this.initialized = false;
}
Expand All @@ -101,7 +101,7 @@ public Lazy() {
*/
public synchronized void set(final T value) {
if (initialized) {
throw new IllegalStateException("Lazy value already initialized");
throw new IllegalStateException("Late value already initialized");
}
this.value = value;
this.initialized = true;
Expand All @@ -115,7 +115,7 @@ public synchronized void set(final T value) {
*/
public synchronized T get() {
if (!initialized) {
throw new IllegalStateException("Lazy value not initialized");
throw new IllegalStateException("Late value not initialized");
}
return value;
}
Expand Down

0 comments on commit 74984c3

Please sign in to comment.