{"id":25776397,"url":"https://github.com/valid4j/valid4j","last_synced_at":"2026-01-16T20:20:50.847Z","repository":{"id":14259152,"uuid":"16966816","full_name":"valid4j/valid4j","owner":"valid4j","description":"Simple assertion and validation library for Java","archived":false,"fork":false,"pushed_at":"2022-01-16T14:01:53.000Z","size":1073,"stargazers_count":48,"open_issues_count":3,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-17T22:48:59.410Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.valid4j.org/","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/valid4j.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}},"created_at":"2014-02-18T22:53:40.000Z","updated_at":"2024-03-31T14:14:32.000Z","dependencies_parsed_at":"2022-09-06T23:31:02.104Z","dependency_job_id":null,"html_url":"https://github.com/valid4j/valid4j","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valid4j%2Fvalid4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valid4j%2Fvalid4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valid4j%2Fvalid4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valid4j%2Fvalid4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/valid4j","download_url":"https://codeload.github.com/valid4j/valid4j/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240987434,"owners_count":19889333,"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":"2025-02-27T06:01:23.027Z","updated_at":"2026-01-16T20:20:45.804Z","avatar_url":"https://github.com/valid4j.png","language":"Java","readme":"valid4j\n=======\n\n[![Build Status](https://travis-ci.org/valid4j/valid4j.png)](https://travis-ci.org/valid4j/valid4j)\n[![Coverage Status](https://coveralls.io/repos/valid4j/valid4j/badge.png?branch=master\u0026service=github)](https://coveralls.io/github/valid4j/valid4j?branch=master)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.valid4j/valid4j/badge.png)](https://maven-badges.herokuapp.com/maven-central/org.valid4j/valid4j)\n\nA simple assertion and validation library for Java which makes it possible to use your\nfavorite [hamcrest-matchers](http://hamcrest.org/JavaHamcrest/) to \nexpress pre- and post-conditions in your code. Use the global default \npolicy to signal logical violations in your code or optionally specify \nyour own handling.\n\nFull documentation is available at [www.valid4j.org](http://www.valid4j.org).\n\nThis library is available at [Maven Central Repository](http://search.maven.org/).\nAdd this dependency to your `pom.xml`\n\n    \u003cdependency\u003e\n      \u003cgroupId\u003eorg.valid4j\u003c/groupId\u003e\n      \u003cartifactId\u003evalid4j\u003c/artifactId\u003e\n      \u003cversion\u003e0.5.0\u003c/version\u003e\n    \u003c/dependency\u003e\n\n### Design-by-contract (assertions)\n\nStatically import the library entry point:\n\n    import static org.valid4j.Assertive.*;\n\nUse assertive preconditions to check for programming errors in calling clients:\n\n    // Express your preconditions using plain boolean expressions, with a helpful error message (optional)\n    require(v \u003e 0.0, \"The value (%f) must be positive\", v);\n    \n    // Or use hamcrest-matchers\n    require(v, containsString(\"great!\"));\n    \nUse assertive postconditions to check for programming errors in your supplied code:\n\n    ensure(result != null);\n    ensure(result, greaterThan(3.0));\n    \nMake use of the convenient pass-through of valid objects:\n\n    // Initialize members with valid arguments\n    this.member = require(argument, notNullValue());\n\n    // Return valid results\n    return ensure(result, notNullValue());\n\nContract violations will contain a descriptive error message:\n\n    // E.g this contract\n    require(\"This message is bad\", containsString(\"good\"));\n    \n    // Will yield this error\n    org.valid4j.exceptions.RequireViolation: expected: a string containing \"good\"\n     but: was \"This message is bad\"\n\n### Validation (e.g. input validation)\n\nStatically import the library entry point:\n\n    import static org.valid4j.Validation.*;\n\nUse expressive hamcrest-matchers to validate input\n\n    validate(argument, isValid(), otherwiseThrowing(InvalidException.class));\n\nMake use of the convenient pass-through of valid objects:\n\n    // Initialize members with valid arguments\n    this.member = validate(arg, isValid(), otherwiseThrowing(InvalidException.class));\n\nFailed validations will contain a descriptive message:\n\n    // E.g this validation\n    validate(\"This message is bad\", containsString(\"good\"), IllegalArgumentException.class);\n    \n    // Will yield this exception with message\n    // (NOTE: Exception class must accept one String argument in constructor for this feature to be supported)\n    java.lang.IllegalArgumentException: expected: a string containing \"good\"\n     but: was \"This message is bad\"\n     \n","funding_links":[],"categories":["测试"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalid4j%2Fvalid4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvalid4j%2Fvalid4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalid4j%2Fvalid4j/lists"}