{"id":16101420,"url":"https://github.com/xdrop/ensurej","last_synced_at":"2025-04-06T00:27:32.090Z","repository":{"id":96237436,"uuid":"77789044","full_name":"xdrop/EnsureJ","owner":"xdrop","description":"Validation framework for Java. Under development","archived":false,"fork":false,"pushed_at":"2017-03-01T18:16:54.000Z","size":91,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"dev","last_synced_at":"2025-02-12T06:38:42.576Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xdrop.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":"2017-01-01T17:31:00.000Z","updated_at":"2017-03-28T16:30:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"5cf12606-6df5-45bf-a9cf-913ba60106e1","html_url":"https://github.com/xdrop/EnsureJ","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdrop%2FEnsureJ","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdrop%2FEnsureJ/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdrop%2FEnsureJ/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdrop%2FEnsureJ/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xdrop","download_url":"https://codeload.github.com/xdrop/EnsureJ/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419640,"owners_count":20936009,"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","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":[],"created_at":"2024-10-09T18:49:54.283Z","updated_at":"2025-04-06T00:27:32.066Z","avatar_url":"https://github.com/xdrop.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003cimg src=\"http://i.imgur.com/cYFDzZO.png\" width=\"129px\"/\u003e\n\n[![Build Status](https://travis-ci.org/xdrop/EnsureJ.svg?branch=master)](https://travis-ci.org/xdrop/EnsureJ)\n[![Version](https://img.shields.io/badge/version-0.0.1--alpha-blue.svg\n)](https://travis-ci.org/xdrop/EnsureJ)\n\nA validation framework for Java focused on a clear user friendly API with lots of pre-defined tests. The framework is still in a very early stage with lots of checks that can be added, so **contributions are encouraged and very welcomed!**\n\n## Examples\n\n### General\n\nRequests start with `Ensure.that(T)` where `T` is the variable being validated. Depending on the variable type several condition checks are available and can be chained using `and()` and `or()` (Note: these boolean operators are left associative). For example:\n\n```java\nEnsure.that(T).conditionCheck().and().otherConditionCheck().or().otherConditionCheck().(...)\n```\n\n~~Also note that expressions are *short-circuited* ie. as soon as some condition evaluates to `false` in the chain the rest will not be evaluated.~~\n\nYou can also prepend a condition with `not()` which will invert it's result.\n\nChains are finished of with `andEval()`, or it's synonym `e()`,`eval()` to get the boolean truth of the validation, **or** with `andThrow()`, `andThrow(Class\u003c? extends Throwable\u003e)` or it's synonym `t()` to return `void` or thrown a exception (either the default `ParamCheckFailedException` or the custom one provided.\n\n### Generic examples\n```java\nEnsure.that(3).inRange(0, 4).andEval(); // yields true\nEnsure.that(3).inRange(0, 4).e(); // identical to above\nEnsure.that(3).inRange(0, 4).eval(); // identical to above\n\nEnsure.that(3).not().isPositive().andThrow(); // throws exception\nEnsure.that(3).not().isPositive().andThrow(\"Number was not positive\"); // throws default exception with custom message\nEnsure.that(3).not().isPositive().andThrow(MyThrowable.class); // throws MyThrowable exception\nEnsure.that(3).not().isPositive().andThrow(MyThrowable.class, \"Number was not positive\"); // throws MyThrowable exception with custom message\n```\n\n### Integers\n\n```java\nEnsure.that(3).inRange(0, 4).andEval(); // yields true\nEnsure.that(-10).isNegative.eval(); // yields true\nEnsure.that(-10).isNegative.e(); // yields true\nEnsure.that(3).isPositive().andEval(); // yields true\nEnsure.that(3).not().isPositive().andThrow(); // throws exception\nEnsure.that(3).not().isPositive().andThrow(MyThrowable.class); // throws MyThrowable exception\n```\n\n### Strings\n\n```java\nEnsure.that(\"HELLO\").isAllUppercase.eval(); // yields true\n\nEnsure.that(\"hello\").isAllLowercase.eval(); // yields true\n\nEnsure.that(\"hello\").hasOnlyLetters.eval(); // yields true\nEnsure.that(\"hello1\").hasOnlyLetters.eval(); // yields false\n\nEnsure.that(\"  h\").not().hasWhitespaceStart.eval(); // yields false\nEnsure.that(\"h   \").not().hasWhitespaceEnd.eval(); // yields false\n\nEnsure.that(\"  h  \").isTrimmed().eval(); // yields false\n\nEnsure.that(\"1112\").hasOnlyDigits.eval(); // yields true\n\nEnsure.that(\"wasd\").matches(\"\\\\w+\").eval() // yields true (matches regex)\n```\n\n### Lists\n```java\nList\u003cObject\u003e lst;\nEnsure.that(lst).all(CheckObject.equal(other)).eval(); // checks whether all list elements .equals(other)\n\nList\u003cInteger\u003e lst;\nEnsure.that(lst).all(CheckInt.isPositive()).eval();\nEnsure.that(lst).all(CheckInt.isNegative()).eval();\nEnsure.that(lst).all(CheckInt.inRange(0, 100)).eval();\n\n// Java \u003e= 8\nEnsure.that(lst).all(x -\u003e x \u003e 3).eval();\n\n// Java \u003c= 8\nEnsure.that(lst).all(new Predicate\u003cInteger\u003e() {\n    public boolean pass(Integer in) {\n        return in \u003e 3;\n    }\n}).eval();\n```\n\n## Shorthand notation\n\n`EnsureJ` can also be imported statically and used using the short `val()` notation.\n\n```java\nimport static me.xdrop.ensurej.Ensure.*;\n\nval(\"aaaa\").isAllUppercase().e();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxdrop%2Fensurej","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxdrop%2Fensurej","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxdrop%2Fensurej/lists"}