com.github.jonasgeiregat:bob-core

Builder generator for Java

License

License

Categories

Categories

JOnAS Container Application Servers
GroupId

GroupId

com.github.jonasgeiregat
ArtifactId

ArtifactId

bob-core
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Builder generator for Java

Download bob-core

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.jonasgeiregat/bob-core/ -->
<dependency>
    <groupId>com.github.jonasgeiregat</groupId>
    <artifactId>bob-core</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.jonasgeiregat/bob-core/
implementation 'com.github.jonasgeiregat:bob-core:0.1.0'
// https://jarcasting.com/artifacts/com.github.jonasgeiregat/bob-core/
implementation ("com.github.jonasgeiregat:bob-core:0.1.0")
'com.github.jonasgeiregat:bob-core:jar:0.1.0'
<dependency org="com.github.jonasgeiregat" name="bob-core" rev="0.1.0">
  <artifact name="bob-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.jonasgeiregat', module='bob-core', version='0.1.0')
)
libraryDependencies += "com.github.jonasgeiregat" % "bob-core" % "0.1.0"
[com.github.jonasgeiregat/bob-core "0.1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
com.google.guava : guava jar 19.0-rc3
com.annimon : stream jar 1.1.6

test (2)

Group / Artifact Type Version
junit : junit jar 4.10
com.google.truth : truth jar 0.28

Project Modules

There are no modules declared in this project.

Bob

Builder generator for Java

Getting Started

Annotate the class you which to build with @Buildable

package foo.bar

@Buildable
public class Car {
    private Brand brand;
    private String color;
    private BigDecimal price;
    
    ...
}

A CarBuilder class will be generated for you in the same package as the source class with builder as suffix. For the car example this will be foo.bar.builder

The location of the builder can be changed:

@Buildable(package = "custom.package")
public class Car {
  ...

The generated builder can be used now:

Car redCar = new CarBuilder().color("red").build();

Bob will try to be smart about creating a builder for you.

  • If there are standard Java Bean setters available they will be used. (setField)
  • If you do not have any setters reflection will be used.
  • If the fields are accessible directly (public or protected fields) they will be set directly.

Fields can be excluded:

@Buildable(excludes = {"brand", "color"})
public class Car {
  ...

By default Bob will generated setter methods consisting out of new style setters (name(String name) instead of setName(String name) or the default builder pattern setter style withName(String name)) If you want to change the prefix of those setter methods you can:

@Buildable(prefix = "with")
public class Car {
  ...      

Bob is not afraid of generics

@Buildable
public class Cup<T, R extends String> {
    private T contents;
    private R topping;
    
// usage

Cup<BigDecimal, String> string = new CupBuilder<BigDecimal, String>().topping("String").contents(BigDecimal.ZERO).build();

Bob can handle final fields

@Buildable
public class Car {
    private final String color; 
    
    public Car(String color) {
        ....

Versions

Version
0.1.0