diff --git a/README.md b/README.md index 7780379..632319f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -50,7 +50,7 @@ Add the following dependency to your `pom.xml` file: com.github.glitchruk tinytools - 0.2.0 + 0.3.0 ``` @@ -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') } ``` @@ -71,14 +71,14 @@ A list of the components in this library. | Class | Description | |--------------------------------------------------------------------------------|------------------------------------------------------| -| [`Lazy`](src/main/java/com/github/glitchruk/tinytools/concurrent/Lazy.java) | A thread-safe utility class for lazy initialization. | +| [`Late`](src/main/java/com/github/glitchruk/tinytools/concurrent/Late.java) | A thread-safe utility class for late initialization. | | [`Memo`](src/main/java/com/github/glitchruk/tinytools/concurrent/Memo.java) | A thread-safe utility class for memoization. | -### Lazy\ +### Late\ -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 @@ -90,7 +90,7 @@ access, while ensuring thread safety and efficient access for subsequent reads. ```java public final class Person { - private final Lazy age = new Lazy<>(); + private final Late age = new Late<>(); public Person() { // Constructor does not set age; it will be set later @@ -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 } } ``` diff --git a/build.gradle b/build.gradle index 0574591..2f52676 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group = 'com.github.glitchruk' -version = '0.2.0' +version = '0.3.0' apply plugin: 'java' diff --git a/pom.xml b/pom.xml index e1b61cf..1f615f5 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.glitchruk tinytools - 0.2.0 + 0.3.0 21 diff --git a/src/main/java/com/github/glitchruk/tinytools/concurrent/Lazy.java b/src/main/java/com/github/glitchruk/tinytools/concurrent/Late.java similarity index 86% rename from src/main/java/com/github/glitchruk/tinytools/concurrent/Lazy.java rename to src/main/java/com/github/glitchruk/tinytools/concurrent/Late.java index 5a5ed84..83b28ab 100644 --- a/src/main/java/com/github/glitchruk/tinytools/concurrent/Lazy.java +++ b/src/main/java/com/github/glitchruk/tinytools/concurrent/Late.java @@ -18,13 +18,13 @@ */ /** - * A thread-safe utility class for lazy initialization. + * A thread-safe utility class for late initialization. *

- * 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. *

* *

Key Features:

@@ -54,7 +54,7 @@ *

Example Usage:

*
{@code
  * public final class Person {
- *     private final Lazy age = new Lazy<>();
+ *     private final Late age = new Late<>();
  *
  *     public Person() {
  *         // Constructor does not set age; it will be initialized later
@@ -79,16 +79,16 @@
  * }
  * }
* - * @param the type of the value to be lazily initialized + * @param the type of the value to be initialized late */ -public class Lazy { +public class Late { 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; } @@ -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; @@ -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; }