{"id":16305473,"url":"https://github.com/moznion/arnold","last_synced_at":"2025-06-13T01:36:09.675Z","repository":{"id":145077973,"uuid":"124896965","full_name":"moznion/arnold","owner":"moznion","description":"Arnold is a builder (and the generator) that guarantees all mandatory elements for instantiation","archived":false,"fork":false,"pushed_at":"2018-03-15T05:49:00.000Z","size":37,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-04T22:12:00.276Z","etag":null,"topics":["annotation","builder","java"],"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/moznion.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":"2018-03-12T13:54:50.000Z","updated_at":"2021-03-06T03:35:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"30f4e12c-7163-43e1-920e-51dbc35a58cb","html_url":"https://github.com/moznion/arnold","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"1efeb16bee5179b2b0df78cca028e275942a81c7"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/moznion/arnold","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Farnold","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Farnold/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Farnold/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Farnold/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moznion","download_url":"https://codeload.github.com/moznion/arnold/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Farnold/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259562262,"owners_count":22876977,"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":["annotation","builder","java"],"created_at":"2024-10-10T21:07:07.365Z","updated_at":"2025-06-13T01:36:09.629Z","avatar_url":"https://github.com/moznion.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Arnold\n\n[![Build Status](https://travis-ci.org/moznion/arnold.svg?branch=master)](https://travis-ci.org/moznion/arnold) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.moznion.arnold/core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.moznion.arnold/core) [![javadoc.io](https://javadocio-badges.herokuapp.com/net.moznion.arnold/core/badge.svg)](https://javadocio-badges.herokuapp.com/net.moznion.arnold/core)\n\nArnold is a builder (and the generator) that guarantees all mandatory elements for instantiation.\n\nThis library uses annotation processor, so it generates the builder automatically on annotation\nprocessing phase if `@ArnoldBuilder` annotation is marked.\n\n## Synopsis\n\n### Basic usage\n\n```java\nimport net.moznion.arnold.annotation.ArnoldBuilder;\nimport net.moznion.arnold.annotation.Required;\n\n@ArnoldBuilder\npublic class Example {\n    @Required\n    private String foo;\n    @Required\n    private int bar;\n    @Required\n    private double buz;\n}\n```\n\nThen build the project, it generates builder(s). You can use the builder like so;\n\n```java\nExample example = new ExampleBuilder().foo(\"foo\")\n                                      .bar(42)\n                                      .buz(2.71828)\n                                      .build();\n```\n\n### With `final` field\n\n```java\nimport net.moznion.arnold.annotation.ArnoldBuilder;\nimport net.moznion.arnold.annotation.Required;\n\n@ArnoldBuilder\npublic class Example {\n    private final String foo;\n    private final int bar;\n    private final double buz;\n    \n    /**\n     * This constructor is dummy. ArnoldBuilder requires no-arg constructor for instantiate.\n     */\n    Example() {\n        this.foo = \"\";\n        this.bar = 0;\n        this.buz = 0.0;\n    }\n}\n```\n\nThen;\n\n```java\nExample example = new ExampleBuilder().foo(\"foo\")\n                                      .bar(42)\n                                      .buz(2.71828)\n                                      .build();\n```\n\nThe `final` field is treated as a necessary element even if `@Required` is not given.\n\n### Specify the order\n\nYou can specify the order of appearance the fields in the builder.\n\n```java\nimport net.moznion.arnold.annotation.ArnoldBuilder;\nimport net.moznion.arnold.annotation.Required;\n\n@ArnoldBuilder\npublic class Example {\n    @Required(order = 2)\n    private String foo;\n    @Required(order = 0)\n    private int bar;\n    @Required\n    private double buz;\n    @Required(order = 1)\n    private boolean qux;\n}\n```\n\nThen;\n\n```java\nExample example = new ExampleBuilder().buz(2.71828) // order -1 (not specified)\n                                      .bar(42)      // order 0\n                                      .qux(true)    // order 1\n                                      .foo(\"foo\")   // order 2\n                                      .build();\n```\n\nLower values are processed first. If the same value is given, the one defined earlier will be\nprocessed first.\n\n### Note!\n\nArnoldBuilder requires the default (no-arg) constructor in the target class for instantiation.\n\n## Motivation\n\nIn a general builder (such as a builder that lombok generates) it is inconvenient, as it could potentially drop out the necessary elements.\nFor example;\n\n```java\npublic class Example {\n    private final String foo;\n    private final String bar;\n    private final String buz;\n\n    private Example(final String foo, final String bar, final String buz) {\n        this.foo = foo;\n        this.bar = bar;\n        this.buz = buz;\n    }\n\n    public static class Builder {\n        private String foo;\n        private String bar;\n        private String buz;\n\n        public Builder foo(final String foo) {\n            this.foo = foo;\n            return this;\n        }\n\n        public Builder bar(final String bar) {\n            this.bar = bar;\n            return this;\n        }\n\n        public Builder buz(final String buz) {\n            this.buz = buz;\n            return this;\n        }\n\n        public Example build() {\n            return new Example(foo, bar, buz);\n        }\n    }\n}\n```\n\nThis builder works well, but...\n\n```java\nnew Builder().foo(\"foo\")\n             .buz(\"buz\")\n             .build(); // bar is missing!\n```\n\nIt can create incomplete instances like this.\n\nArnold is developed to solve these problems. This library generates a Builder Class that guarantees\nall necessary elements in the phase of annotation Processing.\n\n## How does it work\n\nArnold uses annotation processor.\n\nThis library generates as many classes as the number of mandatory elements. The following example \nwill be easy to understand.\n\n```java\nnew ExampleBuilder()       // =\u003e ExampleBuilder: receives `foo`\n             .foo(\"foo\")   // =\u003e ExampleBuilder1: receives `bar`\n             .bar(42)      // =\u003e ExampleBuilder2: receives `buz`\n             .buz(2.71828) // =\u003e ExampleBuilder3: buildable\n             .build();     // =\u003e instance!\n```\n\nIn other words, it generates one class for one required element.\nThis may be a rich solution depending on the environment.\n\n## FAQ\n\n### Why not expand the lombok\n\nI tried it first, but it was a hard way to expand the lombok (that is complicated!).\nWhen implementing a single feature simply as this library, it is easier to implement as an\nindividual library.\n\n## Author\n\nmoznion (\u003cmoznion@gmail.com\u003e)\n\n## License\n\n```\nThe MIT License (MIT)\nCopyright © 2018 moznion, http://moznion.net/ \u003cmoznion@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the “Software”), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoznion%2Farnold","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoznion%2Farnold","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoznion%2Farnold/lists"}