java-builder


License

License

Categories

Categories

Java Languages
GroupId

GroupId

com.github.leeonky
ArtifactId

ArtifactId

java-builder
Last Version

Last Version

0.1.10
Release Date

Release Date

Type

Type

jar
Description

Description

java-builder
java-builder
Project URL

Project URL

https://github.com/leeonky/java-builder
Source Code Management

Source Code Management

https://github.com/leeonky/java-builder.git

Download java-builder

How to add to project

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

Dependencies

runtime (1)

Group / Artifact Type Version
com.github.leeonky : bean-util jar 0.0.14

Project Modules

There are no modules declared in this project.

Java-builder

travis-ci coveralls Lost commit Maven Central License

Codacy Badge Maintainability Code Climate issues Code Climate maintainability (percentage)

A library for building objects in test.

Getting Started

Given a bean class:

@Getter
@Setter
public class Bean {
    private String strValue;
    private int intValue;
};

Create FactorySet

FactorySet factorySet = new FactorySet();

Register and build

// Register class
factorySet.onBuild(Bean.class, bean -> {
    bean.setStrValue("hello world");
});

// Build one object
Bean bean = factorySet.type(Bean.class).build();

// Output is
// hello world
println(bean.getStrValue());

Register

  • With build context
factorySet.onBuild(Bean.class, (bean, buildContext) -> {
    bean.setStrValue("hello " + buildContext.getSequence());
});
Builder<Bean> builder = factorySet.type(Bean.class);

// Output is:
// hello 1
// hello 2
println(builder.build().getStrValue());
println(builder.build().getStrValue());
  • with no default constructor
factorySet.register(Bean.class, (sequence) -> {
    Bean bean = new Bean();
    bean.setStrValue("hello " + sequence);
    return bean;
});
Builder<Bean> builder = factorySet.type(Bean.class);

// Output is:
// hello 1
println(builder.build().getStrValue());

Build with property

factorySet.onBuild(Bean.class, (bean) -> {
});

// Output is:
// hello world
println(factorySet.type(Bean.class).properties(new HashMap<String, Object>{{
    put("strValue", "hello world");
}}).build().getStrValue());
  • guess and convert to right type
factorySet.onBuild(Bean.class, (bean) -> {
});

// Output is:
// 100
println(factorySet.type(Bean.class).properties(new HashMap<String, Object>{{
    put("intValue", "100");
}}).build().getIntValue());
  • register customer converter
factorySet.onBuild(Bean.class, (bean) -> {
});

factorySet.registerConverter(converter ->
    converter.addTypeConverter(Long.class, int.class, Long::intValue));

// Output is:
// 100
println(factorySet.type(Bean.class).properties(new HashMap<String, Object>{{
    put("intValue", 100L);
}}).build().getIntValue());

Data repository

Factory alias

Definition class

Combined build

Versions

Version
0.1.10
0.1.9
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.0.13
0.0.12
0.0.11
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.1