Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions unchained-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,20 @@

<name>Unchained: API</name>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>unchained-commons</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
</dependency>
</dependencies>

</project>
23 changes: 23 additions & 0 deletions unchained-api/src/main/java/unchained/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package unchained;

/**
* TODO: doc
*
* @param <L>
* @param <C>
* @param <I>
* @param <O>
* @param <S>
* @param <A>
*/
public interface Application<L extends ChainLifecycle, C extends ChainContext<L, C>, I extends Input<L, C>,
O extends Output<L, C, I>, S extends Selector<I, ?>, A extends Application<L, C, I, O, S, A>>
extends CompositeMiddleware<L, C, I, O, S, A, Void> {

/**
* TODO: doc
* @return
*/
ApplicationContext context();

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public interface ApplicationLifecycle extends Lifecycle {

/**
* TODO
* TODO: doc
*/
void start();

Expand Down
5 changes: 1 addition & 4 deletions unchained-api/src/main/java/unchained/ChainContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
* @param <L> the lifecycle type.
* @param <C> the context type.
*/
public interface ChainContext<
C extends ChainContext<C, L>,
L extends ChainLifecycle
> extends Context<L> {
public interface ChainContext<L extends ChainLifecycle, C extends ChainContext<L, C>> extends Context<L> {

/**
* Sets the property to the given value.
Expand Down
34 changes: 18 additions & 16 deletions unchained-api/src/main/java/unchained/CompositeMiddleware.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,37 @@
/**
* TODO: doc
*
* @param <W>
* @param <L>
* @param <C>
* @param <I>
* @param <O>
* @param <M>
* @param <Q>
* @param <H>
* @param <S>
* @param <W>
* @param <K>
*/
public interface CompositeMiddleware<
W extends CompositeMiddleware<W, L, C, I, O, M, Q, H>,
L extends ChainLifecycle,
C extends ChainContext<C, L>,
I extends Input<L, C>,
O extends Output<L, C, I>,
M extends Matcher<C, I, H>,
Q,
H> extends Middleware<L, C, I, O, Q> {
public interface CompositeMiddleware<L extends ChainLifecycle, C extends ChainContext<L, C>, I extends Input<L, C>,
O extends Output<L, C, I>, S extends Selector<I, ?>, W extends CompositeMiddleware<L, C, I, O, S, W, K>, K>
extends Middleware<L, C, I, O, K> {

/**
* TODO: doc
*
* @param first
* @param rest
* @param <N>
* @return
*/
<N extends Middleware<L, C, I, O, ?>> W use(N first, N... rest);

/**
* TODO: doc
*
* @param matcher
* @param selector
* @param first
* @param rest
* @param <N>
* @return
*/
@SuppressWarnings("unchecked")
<N extends Middleware<L, C, I, O, ?>> W use(M matcher, N first, N... rest);
<N extends Middleware<L, C, I, O, ?>> W use(S selector, N first, N... rest);

}
8 changes: 4 additions & 4 deletions unchained-api/src/main/java/unchained/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ default boolean disabled(Option<?> option) {
* @param <E> the type.
* @return the value or {@code null} if it was never configured.
*/
default <E> E get(String key) {
return get(key, null);
}
<E> E get(String key);

/**
* <p>Returns the value of the given option, or the corresponding default value for this option if it was never
Expand All @@ -143,6 +141,8 @@ default <E> E get(Option<E> option) {
* @param <E> the type.
* @return the configured value or the provided default.
*/
<E> E get(String key, E defaultValue);
default <E> E get(String key, E defaultValue) {
return has(key) ? get(key) : defaultValue;
}

}
4 changes: 1 addition & 3 deletions unchained-api/src/main/java/unchained/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
* @param <L> the lifecycle type.
* @param <C> the context type.
*/
public interface Input<
L extends ChainLifecycle,
C extends ChainContext<C, L>> {
public interface Input<L extends ChainLifecycle, C extends ChainContext<L, C>> {

/**
* Gives access to the context associated with this input.
Expand Down
57 changes: 0 additions & 57 deletions unchained-api/src/main/java/unchained/Matcher.java

This file was deleted.

12 changes: 4 additions & 8 deletions unchained-api/src/main/java/unchained/Middleware.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@
* @param <C> the type of context bound to this middleware's input.
* @param <I> the type of input this middleware works with.
* @param <O> the type of output this middleware can deal with.
* @param <Q> the type of output for this middleware.
* @param <K> the type of outcome for this middleware.
*/
public interface Middleware<
L extends ChainLifecycle,
C extends ChainContext<C, L>,
I extends Input<L, C>,
O extends Output<L, C, I>,
Q> {
public interface Middleware<L extends ChainLifecycle, C extends ChainContext<L, C>, I extends Input<L, C>,
O extends Output<L, C, I>, K> {

/**
* Handles the incoming input and works on the input and output. This is a very generic method which will be called
Expand All @@ -30,6 +26,6 @@ public interface Middleware<
* @return a future whose completion represents the completion of the middleware itself.
* @throws Exception in case the underlying logic causes an error.
*/
CompletableFuture<Q> execute(I input, O output) throws Exception;
CompletableFuture<K> execute(I input, O output) throws Exception;

}
23 changes: 15 additions & 8 deletions unchained-api/src/main/java/unchained/MutableConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
/**
* Mutable configuration.
*
* @param <M>
*/
public interface MutableConfiguration<M extends MutableConfiguration> extends Configuration {
public interface MutableConfiguration extends Configuration {

/**
* Enables the provided key by setting it to {@code true}.
*
* @param key the key to enable.
* @return the configuration itself to use for chaining method calls.
*/
default M enable(String key) {
default MutableConfiguration enable(String key) {
return set(key, true);
}

Expand All @@ -23,7 +22,7 @@ default M enable(String key) {
* @param option the option to enable.
* @return the configuration itself to use for chaining method calls.
*/
default M enable(Option<Boolean> option) {
default MutableConfiguration enable(Option<Boolean> option) {
return set(option, true);
}

Expand All @@ -33,7 +32,7 @@ default M enable(Option<Boolean> option) {
* @param key the key to disable.
* @return the configuration itself to use for chaining method calls.
*/
default M disable(String key) {
default MutableConfiguration disable(String key) {
return set(key, false);
}

Expand All @@ -43,7 +42,7 @@ default M disable(String key) {
* @param option the option to disable.
* @return the configuration itself to use for chaining method calls.
*/
default M disable(Option<Boolean> option) {
default MutableConfiguration disable(Option<Boolean> option) {
return set(option, false);
}

Expand All @@ -54,7 +53,7 @@ default M disable(Option<Boolean> option) {
* @param value the value.
* @return the configuration itself to use for chaining method calls.
*/
<E> M set(String key, E value);
<E> MutableConfiguration set(String key, E value);

/**
* Sets the value of the provided option to the given value.
Expand All @@ -64,7 +63,7 @@ default M disable(Option<Boolean> option) {
* @param <E> the type of the value.
* @return the configuration itself to use for chaining method calls.
*/
default <E> M set(Option<E> option, E value) {
default <E> MutableConfiguration set(Option<E> option, E value) {
return set(option.key(), value);
}

Expand Down Expand Up @@ -92,4 +91,12 @@ default <E> E unset(Option<?> option) {
return unset(option.key());
}

/**
* Snapshots this configuration object and returns an immutable copy of it. Further changes to this object do not
* reflect in the returned copy.
*
* @return A immutable snapshot of this configuration.
*/
Configuration snapshot();

}
5 changes: 1 addition & 4 deletions unchained-api/src/main/java/unchained/Output.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
* @param <C> the context type.
* @param <I> the input type.
*/
public interface Output<
L extends ChainLifecycle,
C extends ChainContext<C, L>,
I extends Input<L, C>> {
public interface Output<L extends ChainLifecycle, C extends ChainContext<L, C>, I extends Input<L, C>> {

/**
* Gives access to the input associated with this output.
Expand Down
54 changes: 54 additions & 0 deletions unchained-api/src/main/java/unchained/Selector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package unchained;

/**
* TODO: doc
*
* @param <I>
* @param <M>
*/
public interface Selector<I extends Input<? extends ChainLifecycle, ? extends ChainContext>, M> {

/**
* TODO: doc
*
* @param <S>
*/
interface Compiler<S extends Selector<? extends Input<? extends ChainLifecycle, ? extends ChainContext>, ?>> {

/**
* TODO: doc
*
* @param expressions
* @return
*/
S compile(String... expressions);

}

interface Hit<M> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to Selection


/**
* TODO: doc
*
* @return
*/
boolean matched();

/**
* TODO: doc
*
* @return
*/
M value();

}

/**
* TODO: doc
*
* @param input
* @return
*/
Hit<M> test(I input);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to select().


}
Loading