This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from milosmns/master
Merge for 1.1.0
- Loading branch information
Showing
236 changed files
with
12,741 additions
and
3,550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ on: | |
branches: [ master ] | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,4 +203,5 @@ $RECYCLE.BIN/ | |
# Custom rules | ||
.gradle | ||
kssm/build | ||
demo/build | ||
local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Simple State Machines in Kotlin (KSSM) | ||
|
||
![Workflow Status](https://img.shields.io/github/workflow/status/milosmns/kssm/Pre-release%20check) | ||
![Code Size](https://img.shields.io/github/languages/code-size/milosmns/kssm) | ||
![License](https://img.shields.io/github/license/milosmns/kssm) | ||
![Download](https://img.shields.io/bintray/v/milosmns/maven/kssm?color=green) | ||
![Latest Release](https://img.shields.io/github/v/release/milosmns/kssm?include_prereleases) | ||
![Codacy Grade](https://img.shields.io/codacy/grade/0ed57b0d78ef467daa0f534736d6def8) | ||
|
||
## What is this? | ||
|
||
**KSSM** (reordered: _Kotlin - Simple State Machines_) provides an easy and simple DSL _(Domain Specific Language)_ for setting up [finite-state machines](https://en.wikipedia.org/wiki/Finite-state_machine), and opens a clean API with built-in threading and conflation mechanisms for manipulating states. | ||
This library **does not** solve all state machine problems, **nor** does it aim to address all possible use-cases related to state machines. | ||
It currently works only in the JVM environment. | ||
|
||
KSSM is based on the [Flow API](https://kotlinlang.org/docs/reference/coroutines/flow.html#flows) from Kotlin's coroutine package, | ||
more precisely on [State Flow](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/). | ||
|
||
## Quick Intro | ||
|
||
Here's a short introduction on how KSSM works. | ||
[Click here](https://github.com/milosmns/kssm/blob/master/docs/Intro.pptx?raw=true) to go at your own pace in presentation mode. | ||
|
||
![Intro](https://github.com/milosmns/kssm/blob/master/docs/Intro.gif?raw=true) | ||
|
||
KSSM DSL looks like this (assuming actions and states are defined): | ||
|
||
```kotlin | ||
val sm = stateMachine { | ||
mappings( | ||
Heat moves Ice to Liquid, | ||
Chill moves Steam to Liquid, | ||
Drink moves Liquid to Empty, | ||
Fill moves Empty to Liquid | ||
) | ||
|
||
transitionsDispatcher = Dispatchers.Main // optional | ||
|
||
initialState = Empty // optional | ||
|
||
transitionHandler { println("Detected change: $it\n") } // optional | ||
errorHandler { err.println("Invalid request: $it\n") } // optional | ||
|
||
// other config... | ||
} | ||
|
||
// send inputs/actions to that instance | ||
val job = sm.transition(Fill) | ||
job.join() // or job.cancel(), or simply ignore | ||
``` | ||
|
||
## Wiki | ||
|
||
If you prefer longer documentation, check out the [longer version of the docs](https://milosmns.github.io/kssm/kssm/me.angrybyte.kssm.api). | ||
|
||
You want more? There are code samples [in the demo directory](https://github.com/milosmns/kssm/tree/master/demo/src/main/kotlin) | ||
that showcase the most interesting features of this library. | ||
|
||
## How to install KSSM? | ||
|
||
It's hosted on JCenter and MavenCentral, and thus easy to depend upon with Gradle: | ||
|
||
```gradle | ||
dependencies { | ||
// find the latest `$kssm_version` on the top of this page | ||
implementation "me.angrybyte:kssm:$kssm_version" | ||
} | ||
``` | ||
|
||
## Contributing & Code of Conduct | ||
|
||
Please open [a new issue](https://github.com/milosmns/kssm/issues/new) with any requests, issues, complaints or any other type of communication. | ||
For sensitive or security-related topics, don't hesitate to reach out to any maintainer directly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
plugins { | ||
id 'org.jetbrains.kotlin.jvm' version '1.4.0' | ||
} | ||
|
||
group 'me.angrybyte' | ||
version '1.0' | ||
|
||
repositories { | ||
jcenter() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" | ||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.0" | ||
|
||
implementation "me.angrybyte:kssm:1.1.0" | ||
} | ||
|
||
compileKotlin { | ||
kotlinOptions.jvmTarget = "1.8" | ||
} | ||
|
||
compileTestKotlin { | ||
kotlinOptions.jvmTarget = "1.8" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
kotlin.code.style=official |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
#!/usr/bin/env sh | ||
|
||
# | ||
# Copyright 2015 the original author or authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
############################################################################## | ||
## | ||
## Gradle start up script for UN*X | ||
## | ||
############################################################################## | ||
|
||
# Attempt to set APP_HOME | ||
# Resolve links: $0 may be a link | ||
PRG="$0" | ||
# Need this for relative symlinks. | ||
while [ -h "$PRG" ] ; do | ||
ls=`ls -ld "$PRG"` | ||
link=`expr "$ls" : '.*-> \(.*\)$'` | ||
if expr "$link" : '/.*' > /dev/null; then | ||
PRG="$link" | ||
else | ||
PRG=`dirname "$PRG"`"/$link" | ||
fi | ||
done | ||
SAVED="`pwd`" | ||
cd "`dirname \"$PRG\"`/" >/dev/null | ||
APP_HOME="`pwd -P`" | ||
cd "$SAVED" >/dev/null | ||
|
||
APP_NAME="Gradle" | ||
APP_BASE_NAME=`basename "$0"` | ||
|
||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | ||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' | ||
|
||
# Use the maximum available, or set MAX_FD != -1 to use that value. | ||
MAX_FD="maximum" | ||
|
||
warn () { | ||
echo "$*" | ||
} | ||
|
||
die () { | ||
echo | ||
echo "$*" | ||
echo | ||
exit 1 | ||
} | ||
|
||
# OS specific support (must be 'true' or 'false'). | ||
cygwin=false | ||
msys=false | ||
darwin=false | ||
nonstop=false | ||
case "`uname`" in | ||
CYGWIN* ) | ||
cygwin=true | ||
;; | ||
Darwin* ) | ||
darwin=true | ||
;; | ||
MINGW* ) | ||
msys=true | ||
;; | ||
NONSTOP* ) | ||
nonstop=true | ||
;; | ||
esac | ||
|
||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar | ||
|
||
|
||
# Determine the Java command to use to start the JVM. | ||
if [ -n "$JAVA_HOME" ] ; then | ||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then | ||
# IBM's JDK on AIX uses strange locations for the executables | ||
JAVACMD="$JAVA_HOME/jre/sh/java" | ||
else | ||
JAVACMD="$JAVA_HOME/bin/java" | ||
fi | ||
if [ ! -x "$JAVACMD" ] ; then | ||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME | ||
Please set the JAVA_HOME variable in your environment to match the | ||
location of your Java installation." | ||
fi | ||
else | ||
JAVACMD="java" | ||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | ||
Please set the JAVA_HOME variable in your environment to match the | ||
location of your Java installation." | ||
fi | ||
|
||
# Increase the maximum file descriptors if we can. | ||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then | ||
MAX_FD_LIMIT=`ulimit -H -n` | ||
if [ $? -eq 0 ] ; then | ||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then | ||
MAX_FD="$MAX_FD_LIMIT" | ||
fi | ||
ulimit -n $MAX_FD | ||
if [ $? -ne 0 ] ; then | ||
warn "Could not set maximum file descriptor limit: $MAX_FD" | ||
fi | ||
else | ||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" | ||
fi | ||
fi | ||
|
||
# For Darwin, add options to specify how the application appears in the dock | ||
if $darwin; then | ||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" | ||
fi | ||
|
||
# For Cygwin or MSYS, switch paths to Windows format before running java | ||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then | ||
APP_HOME=`cygpath --path --mixed "$APP_HOME"` | ||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` | ||
|
||
JAVACMD=`cygpath --unix "$JAVACMD"` | ||
|
||
# We build the pattern for arguments to be converted via cygpath | ||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` | ||
SEP="" | ||
for dir in $ROOTDIRSRAW ; do | ||
ROOTDIRS="$ROOTDIRS$SEP$dir" | ||
SEP="|" | ||
done | ||
OURCYGPATTERN="(^($ROOTDIRS))" | ||
# Add a user-defined pattern to the cygpath arguments | ||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then | ||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" | ||
fi | ||
# Now convert the arguments - kludge to limit ourselves to /bin/sh | ||
i=0 | ||
for arg in "$@" ; do | ||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` | ||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option | ||
|
||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition | ||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` | ||
else | ||
eval `echo args$i`="\"$arg\"" | ||
fi | ||
i=`expr $i + 1` | ||
done | ||
case $i in | ||
0) set -- ;; | ||
1) set -- "$args0" ;; | ||
2) set -- "$args0" "$args1" ;; | ||
3) set -- "$args0" "$args1" "$args2" ;; | ||
4) set -- "$args0" "$args1" "$args2" "$args3" ;; | ||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; | ||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; | ||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; | ||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; | ||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; | ||
esac | ||
fi | ||
|
||
# Escape application args | ||
save () { | ||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done | ||
echo " " | ||
} | ||
APP_ARGS=`save "$@"` | ||
|
||
# Collect all arguments for the java command, following the shell quoting and substitution rules | ||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" | ||
|
||
exec "$JAVACMD" "$@" |
Oops, something went wrong.