★ wanayoo — archive 1999 https://github.com/davidmoten/java-builder2Nouvelle recherche | Portail wanayoo
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 

README.md

java-builder2


Maven Central
codecov

Generates chained or unchained java builders (see java-builder-pattern-tricks).

  • write concise java code to generate a class with a builder
  • supports builder chaining for mandatory parameters
  • represents non-mandatory parameters using java.util.Optional
  • performs null checks
  • converts Number classes to primitives in builder method parameters because cannot be null

Getting started

Add this maven dependency to your pom.xml:

<dependency>
  <groupId>com.github.davidmoten</groupId>
  <artifactId>java-builder2</artifact>
  <version>VERSION_HERE</version>
  <scope>test</scope>
</dependency>

Normally you'll add it as a test scoped dependency.

Usage

The code below (put in a unit test or a main method in a test class) generates a Person class in the target directory and prints it to stdout.

Generator
  .pkg("com.github.davidmoten.javabuilder") //
  .className("Person") //
  .type("String").name("firstName").mandatory().entryMethod().build() //
  .type("String").name("lastName").mandatory().build() //
  .type("Integer").name("age").build() //
  .type("int").name("height").defaultValue("0").build() //
  .type("String").name("nickname").defaultValue("\"bucko\"").build() //
  .generate();

There are other overloads of generate to write the class to a directory or an OutputStream. You can chain generate calls to do all of those things if you want.

Building

mvn clean install

About

Generate complex builder code using java code

Resources

License

Packages

No packages published

Languages

You can’t perform that action at this time.