{"id":24301010,"url":"https://github.com/weilueluo/tsm4j","last_synced_at":"2025-09-26T03:30:27.140Z","repository":{"id":224920058,"uuid":"764266656","full_name":"weilueluo/tsm4j","owner":"weilueluo","description":"A tiny, in-memory, zero dependency state machine library","archived":false,"fork":false,"pushed_at":"2024-07-21T15:07:00.000Z","size":174,"stargazers_count":26,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T23:41:27.220Z","etag":null,"topics":["java","state-machine"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weilueluo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-27T19:20:39.000Z","updated_at":"2025-02-01T02:53:00.000Z","dependencies_parsed_at":"2024-02-28T12:29:07.385Z","dependency_job_id":"2e678dd5-3ea6-44f3-a9cf-8bfb8661963a","html_url":"https://github.com/weilueluo/tsm4j","commit_stats":null,"previous_names":["weilueluo/tsm4j"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/weilueluo/tsm4j","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weilueluo%2Ftsm4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weilueluo%2Ftsm4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weilueluo%2Ftsm4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weilueluo%2Ftsm4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weilueluo","download_url":"https://codeload.github.com/weilueluo/tsm4j/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weilueluo%2Ftsm4j/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277015015,"owners_count":25745506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-26T02:00:09.010Z","response_time":78,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","state-machine"],"created_at":"2025-01-16T23:30:01.472Z","updated_at":"2025-09-26T03:30:25.814Z","avatar_url":"https://github.com/weilueluo.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tsm4j\r\n\r\nA tiny, in-memory, zero dependency state machine library\r\n\r\n## Install\r\n\r\n### Gradle\r\n```\r\nimplementation 'com.tsm4j:tsm4j:1.1.0'\r\n```\r\n\r\n### Maven\r\n```xml\r\n\u003cdependency\u003e\r\n    \u003cgroupId\u003ecom.tsm4j\u003c/groupId\u003e\r\n    \u003cartifactId\u003etsm4j\u003c/artifactId\u003e\r\n    \u003cversion\u003e1.1.0\u003c/version\u003e\r\n\u003c/dependency\u003e\r\n```\r\n\r\n## Usage\r\n\r\n### Example\r\nAn example of defining and running a state machine:\r\n\r\n```java\r\nStateMachine\u003cTestState\u003e stateMachine = StateMachineBuilder.from(TestState.class)\r\n    .addTransition(TestState.HUNGRY, TestState.MAKE_FOOD)\r\n    .addTransition(TestState.MAKE_FOOD, TestState.FOOD_IS_READY)\r\n    .addTransition(TestState.FOOD_IS_READY, TestState.EAT_FOOD)\r\n    .addTransition(TestState.EAT_FOOD, TestState.FULL)\r\n    .build();\r\n\r\nassertThat(stateMachine.send(TestState.HUNGRY).reached(TestState.FULL)).isTrue();\r\n```\r\n\r\nYou can bind a listener which is called whenever some state(s) is reached\r\n```java\r\nStateMachine\u003cTestState\u003e stateMachine = StateMachineBuilder.from(TestState.class)\r\n    .addTransition(TestState.NO_FOOD, TestState.MAKE_FOOD)\r\n    .addListener(TestState.MAKE_FOOD, context -\u003e {\r\n        System.out.println(\"making food...\");\r\n        context.queue(TestState.FOOD_IS_READY);\r\n    })\r\n    .addListener(debugLoggingListener())\r\n    .build();\r\n\r\nassertThat(stateMachine.send(TestState.NO_FOOD).reached(TestState.FOOD_IS_READY)).isTrue();\r\n```\r\n\r\n### More Examples\r\nsee tsm4j/test.\r\n\r\n## About the older version\r\nIn short, it was going in the wrong direction, we should separate state machine from action.\r\n\r\n## Contributing\r\nFeel free to open up an issue for a feature request, bug report, or pull request.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweilueluo%2Ftsm4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweilueluo%2Ftsm4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweilueluo%2Ftsm4j/lists"}