https://github.com/crissnamon/aide
Fast reflection, extended optionals and conditionals
https://github.com/crissnamon/aide
collaborate communityexchange conditional framework github github-pages java jetbrains jvm lambda library optional reflection utils
Last synced: 4 months ago
JSON representation
Fast reflection, extended optionals and conditionals
- Host: GitHub
- URL: https://github.com/crissnamon/aide
- Owner: CrissNamon
- License: apache-2.0
- Created: 2023-02-01T18:48:11.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-07T10:59:15.000Z (over 2 years ago)
- Last Synced: 2023-03-05T23:13:32.371Z (over 2 years ago)
- Topics: collaborate, communityexchange, conditional, framework, github, github-pages, java, jetbrains, jvm, lambda, library, optional, reflection, utils
- Language: Java
- Homepage: https://hiddenproject.tech/p/aide
- Size: 98.6 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
## About
[](https://github.com/CrissNamon/aide/actions/workflows/maven.yml)
[](https://github.com/CrissNamon/aide/releases)
[](https://central.sonatype.com/artifact/tech.hiddenproject/aide/1.2)Aide is a set of useful utils for fast reflection, extended optionals and conditionals. It can help you with development
of some service or your own framework.## Content
#### Reflection
Aide reflection contains utils for reflection such as fast method invocation with lambda wrapping, annotation processing
and other useful methods.Reflective method calls with Aide are simple:
```java
// Get LambdaWrapperHolder isntance with default LambdaWrapper interface loaded
LambdaWrapperHolder lambdaWrapperHolder = LambdaWrapperHolder.DEFAULT;
// Find static method
Method staticMethod = ReflectionUtil.getMethod(TestClass.class, "staticMethod", String.class);
// Wrap static method
// LambdaWrapper - default wrapper interface from Aide
// Void - caller class. In case of static method caller is not needed, so Void
// Integer - return type
MethodHolder staticHolder = lambdaWrapperHolder.wrapSafe(staticMethod);
// Invoke static method without caller
int staticResult = staticHolder.invokeStatic("Hello");
```#### Optional
Aide optional contains extended optional classes for String, Boolean types, IfTrue and When conditionals, Object utils.
Extended optionals provides new methods for some types:
```java
BooleanOptional.of(Modifier.isPublic(executable.getModifiers()))
.ifFalseThrow(() -> ReflectionException.format("Wrapping is supported for PUBLIC methods only!"));
```With conditionals you can make your code more functional. Thats how Aide reflection uses them:
```java
AbstractSignature signature = IfTrueConditional.create()
.ifTrue(exact).then(() -> ExactMethodSignature.from(method))
.ifTrue(!exact).then(() -> MethodSignature.from(method))
.orElseThrow(() -> ReflectionException.format("%s undefined!", exact));
```Or WhenConditional:
```java
WhenConditional.create()
.when(someObj, Objects::nonNull).then(MyClass::nonNull)
.when(someObj, Objects::isNull).then(MyClass::isNull)
.orDoNothing();
```SwitchConditional too:
```java
Status status = Status.BAD_REQUEST;
String message = SwitchConditional.on(status)
.caseOn(Status.BAD_REQUEST::equals).thenGet("Error: Bad request")
.caseOn(Status.INTERNAL_ERROR::equals).thenGet("Error: Internal error")
.orElse("");
assert message.equals("Error: Bad request");
SwitchConditional.on(status)
// false = no break;, so all branches below will be executed
.caseOn(Status.BAD_REQUEST::equals, false).thenDo(this::action)
.caseOn(Status.INTERNAL_ERROR::equals).thenDo(this::action)
.orElseDo(() -> System.out.println("No action"));
```## Use
Artifact ids:
- `tech.hiddenproject:aide-all` - all components
- `tech.hiddenproject:aide-optional` - optionals and conditionals
- `tech.hiddenproject:aide-reflection` - reflection utils### Maven
```xml
tech.hiddenproject
aide-all
1.3```
### Gradle
```groovy
implementation 'tech:hiddenproject:aide-all:1.3'
```## Resources
___
* Learn more at Aide [Wiki](https://github.com/CrissNamon/aide/wiki)
* Look at some examples
in [example](https://github.com/CrissNamon/aide/tree/main/aide-all/src/main/java/tech/hiddenproject/aide/example)
package## Dependencies and source
___
Aide has no dependencies and use only Java 8.
## Repository info
___
* The main branch contains stable release
* Development branch contains WIP code
* Aide is released under version 2.0 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0)## Authors
___
* [Danila Rassokhin](https://gihub.com/crissnamon) [](https://twitter.com/kpekepsalt_en)