Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

Commit

Permalink
version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmonkey123 committed Feb 26, 2018
1 parent fc47b48 commit 98b5ffa
Show file tree
Hide file tree
Showing 29 changed files with 219 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ch/awae/utils/Lazy.java
Expand Up @@ -11,7 +11,7 @@
* therefore.
*
* @author Andreas Wälchli
* @version 1.2, 2015-05-09
* @since awaeUtils 1.0.0
*
* @param <T>
* The Content type
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ch/awae/utils/Shutdown.java
Expand Up @@ -9,6 +9,7 @@
* added option to define the shutdown order.
*
* @author Andreas Wälchli
* @since awaeUtils 1.0.0
*/
public final class Shutdown {

Expand Down Expand Up @@ -107,7 +108,7 @@ public boolean add(Runnable r) {
/**
* @throws NullPointerException
* if the {@code r} argument is {@code null}
* @since 1.3
* 1.3
*/
public void add(Runnable r, double priority) {
Objects.requireNonNull(r, "no null runnable allowed");
Expand Down
Expand Up @@ -11,7 +11,7 @@
* synchronisation.
*
* @author Andreas Wälchli
* @version 1.2, 2015-05-10
* @since awaeUtils 1.0.0
*
* @param <E>
* the element type for this queue
Expand Down
Expand Up @@ -15,7 +15,7 @@
* max-queue it is the element with the highest priority value
*
* @author Andreas Wälchli
* @version 1.2, 2015-05-10
* @since awaeUtils 1.0.0
*
* @param <E>
* the element type
Expand Down Expand Up @@ -56,7 +56,7 @@ public int hashCode() {
* @param <T>
* the type of the queue
* @return the created queue
* @since 1.2
* 1.2
*/
public static <T> PriorityQueue<T> maxQueue() {
return new PriorityQueue<>(false);
Expand All @@ -68,7 +68,7 @@ public static <T> PriorityQueue<T> maxQueue() {
* @param <T>
* the type of the queue
* @return the created queue
* @since 1.2
* 1.2
*/
public static <T> PriorityQueue<T> minQueue() {
return new PriorityQueue<>(true);
Expand Down Expand Up @@ -142,7 +142,7 @@ public boolean isEmpty() {
* indicates if the queue has a max-queue configuration
*
* @return {@code true} iff the queue is a max-queue
* @since 1.2
* 1.2
*/
public boolean isMaxQueue() {
return !this.isMinQueue;
Expand All @@ -152,7 +152,7 @@ public boolean isMaxQueue() {
* indicates if the queue has a min-queue configuration
*
* @return {@code true} iff the queue is a min-queue
* @since 1.2
* 1.2
*/
public boolean isMinQueue() {
return this.isMinQueue;
Expand Down
Expand Up @@ -11,7 +11,7 @@
* termination.
*
* @author Andreas Wälchli
* @version 1.2, 2015-05-10
* @since awaeUtils 1.0.0
*/
public abstract class IterativeRunner implements Runnable {

Expand Down
@@ -1,8 +1,15 @@
package ch.awae.utils.functional;

/**
* Similar to {@link java.util.function.Supplier} but able to throw any
* arbitrary exception.
*
* @author Andreas Wälchli
* @since awaeUtils 1.0.0
*/
@FunctionalInterface
public interface FailableFunction0<T> {

T apply() throws Throwable;

}
7 changes: 7 additions & 0 deletions src/main/java/ch/awae/utils/functional/FailableFunction1.java
@@ -1,5 +1,12 @@
package ch.awae.utils.functional;

/**
* Similar to {@link java.util.function.Function} but able to throw any
* arbitrary exception.
*
* @author Andreas Wälchli
* @since awaeUtils 1.0.0
*/
@FunctionalInterface
public interface FailableFunction1<A, B> {

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ch/awae/utils/functional/FailableRunnable.java
@@ -1,5 +1,12 @@
package ch.awae.utils.functional;

/**
* Similar to {@link java.lang.Runnable} but able to throw any arbitrary
* exception.
*
* @author Andreas Wälchli
* @since awaeUtils 1.0.0
*/
@FunctionalInterface
public interface FailableRunnable {

Expand Down

This file was deleted.

15 changes: 15 additions & 0 deletions src/main/java/ch/awae/utils/functional/InterruptibleRunnable.java
@@ -0,0 +1,15 @@
package ch.awae.utils.functional;

/**
* Similar to {@link java.lang.Runnable} but with the ability to be interrupted.
* This can be used instead of {@link FailableRunnable} if only
* {@link InterruptedException} should be allowed.
*
* @author Andreas Wälchli
* @since awaeUtils 0.0.6
*/
public interface InterruptibleRunnable {

void run() throws InterruptedException;

}
2 changes: 1 addition & 1 deletion src/main/java/ch/awae/utils/functional/Result.java
Expand Up @@ -22,7 +22,7 @@
* further processing using a functional code style.
*
* @author Andreas Wälchli
* @version 1.1, 2015-05-11
* @since awaeUtils 1.0.0
*
* @param <T>
* the result type
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/awae/utils/functional/T2.java
Expand Up @@ -6,7 +6,7 @@
* Immutable generic 2-Tuple
*
* @author Andreas Wälchli
* @version 1.1, 2015-05-09
* @since awaeUtils 1.0.0
*
* @param <A>
* the type of the first element
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/ch/awae/utils/functional/Try.java
Expand Up @@ -2,6 +2,18 @@

import java.util.function.Function;

/**
* Implementation of a Try monad.
*
* The Try monad indicates in the return type that an operation might fail.
* Instead of throwing an exception the exception can be returned and handled
* gracefully through this monad.
*
* @author Andreas Wälchli
* @since awaeUtils 1.0.0
*
* @param <T>
*/
public interface Try<T> {

boolean isSuccess();
Expand Down
Expand Up @@ -16,7 +16,7 @@
* object equality
*
* @author Andreas Wälchli
* @version 1.1, 2015-05-09
* @since awaeUtils 1.0.0
*
* @param <V>
* the vertex type of the pathfinder
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/awae/utils/pathfinding/Pathfinder.java
Expand Up @@ -6,7 +6,7 @@
* Base Interface for pathfinding algorithm implementations
*
* @author Andreas Wälchli
* @version 1.1, 2015-05-09
* @since awaeUtils 1.0.0
*
* @param <V>
* the vertex type supported by the pathfinder
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/awae/utils/pathfinding/Vertex.java
Expand Up @@ -6,7 +6,7 @@
* Base interface for pathfinding graph vertices
*
* @author Andreas Wälchli
* @version 1.1, 2015-05-09
* @since awaeUtils 1.0.0
*
* @param <T>
* the edge type
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/ch/awae/utils/sequence/IRootSequenceBuilder.java
@@ -1,13 +1,33 @@
package ch.awae.utils.sequence;

import ch.awae.utils.functional.InterruptableRunnable;
import ch.awae.utils.functional.InterruptibleRunnable;

/**
* Sequence Builder for the root sequence.
*
* The root sequence is the main sequence. Sub-sequences can be created by
* adding loops.
*
* @author Andreas Wälchli
* @since awaeUtils 0.0.6
*/
public interface IRootSequenceBuilder extends ISequenceBuilder<IRootSequenceBuilder> {

/**
* Start an infinite loop
*
* @return subsequence builder
*/
ISubSequenceBuilder<IRootSequenceBuilder> loop();

InterruptableRunnable compileRaw();
/**
* compile the sequence into a raw interruptible runnable
*/
InterruptibleRunnable compileRaw();

/**
* compile the constructed sequence into a full {@link Sequence} instance
*/
default Sequence compile() {
return new Sequence(compileRaw());
}
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/ch/awae/utils/sequence/ISequenceBuilder.java
@@ -1,15 +1,39 @@
package ch.awae.utils.sequence;

import ch.awae.utils.functional.InterruptableRunnable;
import ch.awae.utils.functional.InterruptibleRunnable;

/**
* Base interface for all sequence builders
*
* @author Andreas Wälchli
* @since awaeUtils 0.0.6
*/
public interface ISequenceBuilder<T extends ISequenceBuilder<T>> {

T step(InterruptableRunnable step);
/**
* adds a step to the sequence
*
* @return the builder itself. for chaining
*/
T step(InterruptibleRunnable step);

/**
* adds a step that sleeps for a given number of milliseconds. The step
* makes a call to {@link Thread#sleep(long)} internally
*
* @return the builder itself for chaining
*/
default T sleep(long millis) {
return step(() -> Thread.sleep(millis));
}

/**
* start a finite loop with a given number of iterations
*
* @param iterations
* the number of times the loop should be repeated
* @return the bbuilder itself for chaining
*/
ISubSequenceBuilder<T> loop(int iterations);

}
14 changes: 13 additions & 1 deletion src/main/java/ch/awae/utils/sequence/ISubSequenceBuilder.java
@@ -1,7 +1,19 @@
package ch.awae.utils.sequence;

/**
* sequence builder for sub-sequences. Subsequences are created by starting
* loops
*
* @author Andreas Wälchli
* @since awaeUtils 0.0.6
*/
public interface ISubSequenceBuilder<T extends ISequenceBuilder<T>> extends ISequenceBuilder<ISubSequenceBuilder<T>> {

/**
* end the loop represented by this sub-sequence
*
* @return the parent sequence builder
*/
T end();

}
14 changes: 7 additions & 7 deletions src/main/java/ch/awae/utils/sequence/RootSequenceBuilder.java
@@ -1,25 +1,25 @@
package ch.awae.utils.sequence;

import ch.awae.utils.functional.InterruptableRunnable;
import ch.awae.utils.functional.InterruptibleRunnable;

final class RootSequenceBuilder implements IRootSequenceBuilder {

private InterruptableRunnable[] elements;
private InterruptibleRunnable[] elements;

RootSequenceBuilder(InterruptableRunnable... els) {
RootSequenceBuilder(InterruptibleRunnable... els) {
elements = els;
}

public RootSequenceBuilder step(InterruptableRunnable r) {
InterruptableRunnable[] next = new InterruptableRunnable[elements.length + 1];
public RootSequenceBuilder step(InterruptibleRunnable r) {
InterruptibleRunnable[] next = new InterruptibleRunnable[elements.length + 1];
System.arraycopy(elements, 0, next, 0, elements.length);
next[elements.length] = r;
return new RootSequenceBuilder(next);
}

public InterruptableRunnable compileRaw() {
public InterruptibleRunnable compileRaw() {
return () -> {
for (InterruptableRunnable r : elements) {
for (InterruptibleRunnable r : elements) {
if (Thread.interrupted()) {
throw new InterruptedException();
}
Expand Down

0 comments on commit 98b5ffa

Please sign in to comment.