JavaSingleValue

Java objects that represent singe value.

Лицензия

Лицензия

Группа

Группа

com.levelrin
Идентификатор

Идентификатор

javasinglevalue
Последняя версия

Последняя версия

1.0.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

JavaSingleValue
Java objects that represent singe value.
Ссылка на сайт

Ссылка на сайт

https://github.com/levelrin/JavaSingleValue
Система контроля версий

Система контроля версий

https://github.com/levelrin/JavaSingleValue

Скачать javasinglevalue

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.levelrin/javasinglevalue/ -->
<dependency>
    <groupId>com.levelrin</groupId>
    <artifactId>javasinglevalue</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.levelrin/javasinglevalue/
implementation 'com.levelrin:javasinglevalue:1.0.0'
// https://jarcasting.com/artifacts/com.levelrin/javasinglevalue/
implementation ("com.levelrin:javasinglevalue:1.0.0")
'com.levelrin:javasinglevalue:jar:1.0.0'
<dependency org="com.levelrin" name="javasinglevalue" rev="1.0.0">
  <artifact name="javasinglevalue" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.levelrin', module='javasinglevalue', version='1.0.0')
)
libraryDependencies += "com.levelrin" % "javasinglevalue" % "1.0.0"
[com.levelrin/javasinglevalue "1.0.0"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

Build Status Test Coverage Maven Central License

JavaSingleValue

Java objects that represent singe value. Using normal variable to store data and manipulating them is no fun. Why not let objects maintain the data for you? Check out the examples below.

Caching and Lazy-loading

Let's say we have User object, and we can ask him to give us his description. He may need to put some effort to compute his description. We want him to do computation only when we ask his description (lazy-loading). Lastly, we want him to cache his description instead of computing every time we ask him. Most likely, this is how we may implement the User object in tedious way:

public class User {

    private String content;
    private boolean cached;

    /**
     * The description will be computed.
     * We execute the logic here, not in the constructor (lazy-loading).
     * We also cache the computed value.
     * @return User description.
     */
    public String description() {
        if (!this.cached) {
            // Imagine we do some computation.
            // For example, fetching data from server, or getting data from database.
            // After the computation, we assign the value to the instance variable.
            this.content = "Some description of the user.";
            this.cached = true;
        }
        return this.content;
    }

}

And this is how we may implement the User object with CachedValue object, which is from this library :)

public class User {

    /**
     * We give the computation logic to this object.
     * It will execute the logic only once and cache the value for us.
     */
    private final CachedValue<String> description = new CachedValue<>(() -> {
        // Imagine we do some computation.
        // For example, fetching data from server, or getting data from database.
        // After the computation, we assign the value to the instance variable.
        return "Some description of the user.";
    });

    /**
     * The description will be computed.
     * We execute the logic here, not in the constructor (lazy-loading).
     * We also cache the computed value.
     * @return User description.
     */
    public String description() {
        return this.description.get();
    }

}

How to use?

You just need to add the dependency like so:

Gradle:

dependencies {
    implementation 'com.levelrin:javasinglevalue:1.0.0'
}

Maven:

<dependency>
  <groupId>com.levelrin</groupId>
  <artifactId>javasinglevalue</artifactId>
  <version>1.0.0</version>
</dependency>

Requirements:

  1. JDK 1.8+

How to contribute?

As of now, just fork this repository and send us a pull request. The detailed guideline will be created soon.

Версии библиотеки

Версия
1.0.0