https://github.com/notjustanna/resources
Lazily-initialized resource loading and Holder-like patterns.
https://github.com/notjustanna/resources
Last synced: about 1 month ago
JSON representation
Lazily-initialized resource loading and Holder-like patterns.
- Host: GitHub
- URL: https://github.com/notjustanna/resources
- Owner: NotJustAnna
- License: mit
- Created: 2019-06-15T15:49:43.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-27T00:40:23.000Z (almost 3 years ago)
- Last Synced: 2025-01-02T03:46:16.463Z (over 1 year ago)
- Language: Java
- Size: 57.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Resources
Lazily-initialized resource loading and Holder-like patterns.
Licensed under the [MIT License](https://github.com/arudiscord/resources/blob/master/LICENSE).
### Installation

Using in Gradle:
```gradle
repositories {
jcenter()
}
dependencies {
compile 'net.notjustanna.libs:resources:LATEST' // replace LATEST with the version above
}
```
Using in Maven:
```xml
central
bintray
http://jcenter.bintray.com
net.notjustanna.libs
resources
LATEST
```
### Usage
- You can wrap already-available resources with ``Resource.of(T)``.
- You can create lazily-loadable resources with ``Resource.of(Callable)``. The lambda will be called on the first invocation.
- You can wrap resources coming from Futures with ``Resource.ofFuture(Future)``.
- You can create settable resources, which let you control the state with the Resource with ``Resource.settable()``.
- You can also make a unavailable resource with ``Resource.unavailable()``.
Expected usage is as follows:
```java
Resource res = Resource.of(() -> "I am".concat(" a computer-expensive").concat(" operation"));
if (res.load()) {
String computed = res.getValue();
} else {
System.out.println("Operation errored.");
}
```
### Support