-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
948 additions
and
26 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,14 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="RunAll" type="JUnit" factoryName="JUnit"> | ||
<module name="statemachineftc.unitTest" /> | ||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" /> | ||
<option name="ALTERNATIVE_JRE_PATH" value="Android API 34, extension level 7 Platform" /> | ||
<option name="PACKAGE_NAME" value="tests" /> | ||
<option name="MAIN_CLASS_NAME" value="" /> | ||
<option name="METHOD_NAME" value="" /> | ||
<option name="TEST_OBJECT" value="package" /> | ||
<method v="2"> | ||
<option name="Make" enabled="true" /> | ||
</method> | ||
</configuration> | ||
</component> |
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
Binary file modified
BIN
-1.45 KB
(100%)
build/intermediates/compile_and_runtime_not_namespaced_r_class_jar/debugUnitTest/R.jar
Binary file not shown.
Binary file modified
BIN
+47.1 KB
(150%)
build/intermediates/compile_library_classes_jar/debug/classes.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
build/intermediates/incremental/debug/packageDebugResources/compile-file-map.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 |
---|---|---|
@@ -1 +1 @@ | ||
#Tue Apr 02 21:32:58 MDT 2024 | ||
#Fri Oct 11 22:12:12 MDT 2024 |
2 changes: 1 addition & 1 deletion
2
build/intermediates/incremental/debug/packageDebugResources/merger.xml
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<merger version="3"><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="main$Generated" generated="true" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/gradengentry/Desktop/Repos/StateMachineFTC/src/main/res"/><source path="/Users/gradengentry/Desktop/Repos/StateMachineFTC/build/generated/res/rs/debug"/><source path="/Users/gradengentry/Desktop/Repos/StateMachineFTC/build/generated/res/resValues/debug"/></dataSet><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="main" generated-set="main$Generated" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/gradengentry/Desktop/Repos/StateMachineFTC/src/main/res"/><source path="/Users/gradengentry/Desktop/Repos/StateMachineFTC/build/generated/res/rs/debug"/><source path="/Users/gradengentry/Desktop/Repos/StateMachineFTC/build/generated/res/resValues/debug"/></dataSet><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="debug$Generated" generated="true" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/gradengentry/Desktop/Repos/StateMachineFTC/src/debug/res"/></dataSet><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="debug" generated-set="debug$Generated" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/gradengentry/Desktop/Repos/StateMachineFTC/src/debug/res"/></dataSet><mergedItems/></merger> | ||
<merger version="3"><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="main$Generated" generated="true" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/gradengentry/Downloads/Repos/StateMachineFTC/src/main/res"/><source path="/Users/gradengentry/Downloads/Repos/StateMachineFTC/build/generated/res/rs/debug"/><source path="/Users/gradengentry/Downloads/Repos/StateMachineFTC/build/generated/res/resValues/debug"/></dataSet><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="main" generated-set="main$Generated" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/gradengentry/Downloads/Repos/StateMachineFTC/src/main/res"/><source path="/Users/gradengentry/Downloads/Repos/StateMachineFTC/build/generated/res/rs/debug"/><source path="/Users/gradengentry/Downloads/Repos/StateMachineFTC/build/generated/res/resValues/debug"/></dataSet><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="debug$Generated" generated="true" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/gradengentry/Downloads/Repos/StateMachineFTC/src/debug/res"/></dataSet><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="debug" generated-set="debug$Generated" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/gradengentry/Downloads/Repos/StateMachineFTC/src/debug/res"/></dataSet><mergedItems/></merger> |
Binary file added
BIN
+5.76 KB
...diates/javac/debug/classes/org/gentrifiedApps/statemachineftc/ParallelRunSM$Builder.class
Binary file not shown.
Binary file added
BIN
+4.46 KB
.../intermediates/javac/debug/classes/org/gentrifiedApps/statemachineftc/ParallelRunSM.class
Binary file not shown.
Binary file added
BIN
+5.59 KB
...ates/javac/debug/classes/org/gentrifiedApps/statemachineftc/SequentialRunSM$Builder.class
Binary file not shown.
Binary file added
BIN
+4.99 KB
...ntermediates/javac/debug/classes/org/gentrifiedApps/statemachineftc/SequentialRunSM.class
Binary file not shown.
Binary file added
BIN
+1.3 KB
build/intermediates/javac/debug/classes/tests/ParallelRunSMTestCases$States.class
Binary file not shown.
Binary file added
BIN
+10.6 KB
build/intermediates/javac/debug/classes/tests/ParallelRunSMTestCases.class
Binary file not shown.
Binary file added
BIN
+1.26 KB
build/intermediates/javac/debug/classes/tests/SequentialRunSMTestCases$States.class
Binary file not shown.
Binary file added
BIN
+11.8 KB
build/intermediates/javac/debug/classes/tests/SequentialRunSMTestCases.class
Binary file not shown.
Binary file modified
BIN
+1 Byte
(100%)
build/intermediates/javac/debug/classes/tests/StateMachineTestCases.class
Binary file not shown.
Binary file removed
BIN
-519 Bytes
.../intermediates/javac/release/classes/org/gentrifiedApps/statemachineftc/BuildConfig.class
Binary file not shown.
Binary file removed
BIN
-258 Bytes
...diates/javac/release/classes/org/gentrifiedApps/statemachineftc/StateChangeCallback.class
Binary file not shown.
Binary file removed
BIN
-6.96 KB
...iates/javac/release/classes/org/gentrifiedApps/statemachineftc/StateMachine$Builder.class
Binary file not shown.
Binary file removed
BIN
-6.06 KB
...intermediates/javac/release/classes/org/gentrifiedApps/statemachineftc/StateMachine.class
Binary file not shown.
Binary file removed
BIN
-1.46 KB
...release/classes/org/gentrifiedApps/statemachineftc/examples/StateMachineLocal$state.class
Binary file not shown.
Binary file removed
BIN
-3.55 KB
...javac/release/classes/org/gentrifiedApps/statemachineftc/examples/StateMachineLocal.class
Binary file not shown.
Binary file removed
BIN
-1.57 KB
...org/gentrifiedApps/statemachineftc/examples/abstracted/StateMachineAbstracted$state.class
Binary file not shown.
Binary file removed
BIN
-1.42 KB
...asses/org/gentrifiedApps/statemachineftc/examples/abstracted/StateMachineAbstracted.class
Binary file not shown.
Binary file removed
BIN
-3.44 KB
...release/classes/org/gentrifiedApps/statemachineftc/examples/abstracted/abstractedSM.class
Binary file not shown.
Binary file removed
BIN
-6.32 KB
build/intermediates/javac/release/classes/tests/StateMachineTestCases$LargeStates.class
Binary file not shown.
Binary file removed
BIN
-1.35 KB
build/intermediates/javac/release/classes/tests/StateMachineTestCases$States.class
Binary file not shown.
Binary file removed
BIN
-56.3 KB
build/intermediates/javac/release/classes/tests/StateMachineTestCases.class
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
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 |
---|---|---|
@@ -1,25 +1,25 @@ | ||
-- Merging decision tree log --- | ||
manifest | ||
ADDED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml:2:13-3:63 | ||
INJECTED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml:2:13-3:63 | ||
INJECTED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml:2:13-3:63 | ||
ADDED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml:2:13-3:63 | ||
INJECTED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml:2:13-3:63 | ||
INJECTED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml:2:13-3:63 | ||
package | ||
ADDED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml:3:16-60 | ||
INJECTED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml | ||
INJECTED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml | ||
ADDED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml:3:16-60 | ||
INJECTED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml | ||
INJECTED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml | ||
xmlns:android | ||
ADDED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml:2:23-81 | ||
ADDED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml:2:23-81 | ||
uses-sdk | ||
INJECTED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml reason: use-sdk injection requested | ||
INJECTED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml | ||
INJECTED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml | ||
INJECTED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml | ||
INJECTED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml | ||
INJECTED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml reason: use-sdk injection requested | ||
INJECTED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml | ||
INJECTED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml | ||
INJECTED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml | ||
INJECTED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml | ||
android:targetSdkVersion | ||
INJECTED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml | ||
ADDED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml | ||
INJECTED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml | ||
INJECTED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml | ||
ADDED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml | ||
INJECTED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml | ||
android:minSdkVersion | ||
INJECTED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml | ||
ADDED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml | ||
INJECTED from /Users/gradengentry/Desktop/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest11121576163084389438.xml | ||
INJECTED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml | ||
ADDED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml | ||
INJECTED from /Users/gradengentry/Downloads/Repos/StateMachineFTC/build/intermediates/tmp/ProcessLibraryManifest/debug/tempAndroidManifest7491562204287475936.xml |
Binary file modified
BIN
+649 Bytes
(120%)
build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin
Binary file not shown.
153 changes: 153 additions & 0 deletions
153
src/main/java/org/gentrifiedApps/statemachineftc/ParallelRunSM.java
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,153 @@ | ||
package org.gentrifiedApps.statemachineftc; | ||
|
||
import android.util.Pair; | ||
|
||
import org.junit.jupiter.api.DisplayNameGenerator; | ||
|
||
import java.util.AbstractMap; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
public class ParallelRunSM<T extends Enum<T>> { | ||
private List<T> states; | ||
private Map<T, StateChangeCallback> onEnterCommands; | ||
private Supplier<Boolean> exitTransition; | ||
private boolean isStarted = false; | ||
private boolean isRunning = true; | ||
private long startTime; | ||
|
||
private AbstractMap.SimpleEntry<Boolean, Integer> timeout; | ||
|
||
public boolean isRunning() { | ||
return isRunning; | ||
} | ||
|
||
public boolean isStarted() { | ||
return isStarted; | ||
} | ||
|
||
ParallelRunSM(ParallelRunSM.Builder<T> builder) { | ||
this.states = builder.states; | ||
this.exitTransition = builder.exitTransition; | ||
this.onEnterCommands = builder.onEnterCommands; | ||
this.timeout = builder.timeout; | ||
} | ||
|
||
public static class Builder<T extends Enum<T>> { | ||
private List<T> states; | ||
private Map<T, StateChangeCallback> onEnterCommands; | ||
private Supplier<Boolean> exitTransition; | ||
private ParallelRunSM<T> machine; | ||
private int stopRunningIncluded = 0; | ||
private AbstractMap.SimpleEntry<Boolean, Integer> timeout; | ||
|
||
public Builder() { | ||
states = new ArrayList<>(); | ||
onEnterCommands = new HashMap<>(); | ||
} | ||
|
||
public ParallelRunSM.Builder<T> state(T state) { | ||
if (states.contains(state)) { | ||
throw new IllegalArgumentException("State already exists"); | ||
} | ||
states.add(state); | ||
return this; | ||
} | ||
|
||
public ParallelRunSM.Builder<T> onEnter(T state, StateChangeCallback command) { | ||
if (!states.contains(state)) { | ||
throw new IllegalArgumentException("State does not exist"); | ||
} | ||
onEnterCommands.put(state, command); | ||
return this; | ||
} | ||
|
||
public ParallelRunSM.Builder<T> stopRunning(T state, Supplier<Boolean> exitCommand) { | ||
this.stopRunningIncluded++; | ||
if (states.contains(state)) { | ||
throw new IllegalArgumentException("State already exists"); | ||
} | ||
states.add(state); | ||
onEnterCommands.put(state, () -> { | ||
if (exitCommand.get()) { | ||
this.machine.isRunning = false; | ||
} | ||
}); | ||
this.exitTransition = exitCommand; | ||
return this; | ||
} | ||
|
||
public ParallelRunSM<T> build(Boolean useTimeout, Integer timeout) { | ||
this.timeout = new AbstractMap.SimpleEntry<>(useTimeout, timeout); | ||
if (states == null || states.isEmpty()) { | ||
throw new IllegalArgumentException("States cannot be null or empty"); | ||
} | ||
|
||
if (new HashSet<>(states).size() != states.size()) { | ||
throw new IllegalArgumentException("States cannot have duplicates"); | ||
} | ||
|
||
if (onEnterCommands.get(states.get(0)) == null) { | ||
throw new IllegalArgumentException("Initial state must have a corresponding onEnter command"); | ||
} | ||
if (this.stopRunningIncluded != 1) { | ||
throw new IllegalArgumentException("Not enough or too many stopRunning commands"); | ||
} | ||
if (this.exitTransition == null) { | ||
throw new IllegalArgumentException("Exit transition must be set"); | ||
} | ||
this.machine = new ParallelRunSM<T>(this); | ||
return this.machine; | ||
} | ||
} | ||
|
||
public void start() { | ||
if (isStarted) { | ||
throw new IllegalStateException("StateMachine has already been started"); | ||
} | ||
isStarted = true; | ||
startTime = System.currentTimeMillis(); | ||
} | ||
|
||
public void stop() { | ||
if (!isRunning) { | ||
throw new IllegalStateException("StateMachine is already stopped"); | ||
} | ||
isRunning = false; | ||
//delete all actions | ||
states.clear(); | ||
onEnterCommands.clear(); | ||
} | ||
|
||
public boolean update() { | ||
if (!states.isEmpty()) { | ||
// run all states at once | ||
for (T state : states) { | ||
StateChangeCallback onEnterAction = onEnterCommands.get(state); | ||
if (onEnterAction != null) { | ||
onEnterAction.onStateChange(); | ||
} | ||
} | ||
} | ||
if (checkExitTransition()) { | ||
isRunning = false; | ||
} | ||
return true; | ||
} | ||
|
||
public boolean checkExitTransition() { | ||
boolean exitResult = exitTransition.get(); | ||
long elapsedTime = System.currentTimeMillis() - startTime; | ||
System.out.println("Checking exit transition: " + exitResult); | ||
System.out.println("Elapsed time: " + elapsedTime + "ms"); | ||
final boolean condition = exitResult || (timeout.getKey() && elapsedTime > timeout.getValue()); | ||
if (condition) { | ||
isRunning = false; | ||
} | ||
return condition; | ||
} | ||
} |
Oops, something went wrong.