Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.iamMehedi:stepbuilder:'
}
dependencies {
implementation("com.github.iamMehedi:stepbuilder:")
}
<dependency>
<groupId>com.github.iamMehedi</groupId>
<artifactId>stepbuilder</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.iamMehedi" % "stepbuilder" % ""
:dependencies [[com.github.iamMehedi/stepbuilder ""]]
IntelliJ IDEA/Android Studio plugin that adds a 'Step Builder' action to the Generate menu (Alt+Insert) which generates a Builder class which follows the Step Builder pattern. You can read about the Step Builder pattern and why it might be a little more effective than the usual Builder pattern here.
public class Server{
final static int DEFAULT_PORT = 8080;
private String protocol;
private String url;
private String ipAddress;
private int port;
private String description;
private long uptime;
private Server(Builder builder) {
protocol = builder.protocol;
url = builder.url;
ipAddress = builder.ipAddress;
port = builder.port;
description = builder.description;
uptime = builder.uptime;
}
public static IProtocol builder() {
return new Builder();
}
public interface IBuild {
Server build();
}
public interface IUptime {
IBuild withUptime(long val);
}
public interface IDescription {
IUptime withDescription(String val);
}
public interface IPort {
IDescription withPort(int val);
}
public interface IIpAddress {
IPort withIpAddress(String val);
}
public interface IUrl {
IIpAddress withUrl(String val);
}
public interface IProtocol {
IUrl withProtocol(String val);
}
public static final class Builder implements IUptime, IDescription, IPort, IIpAddress, IUrl, IProtocol, IBuild {
private long uptime;
private String description;
private int port;
private String ipAddress;
private String url;
private String protocol;
private Builder() {
}
@Override
public IBuild withUptime(long val) {
uptime = val;
return this;
}
@Override
public IUptime withDescription(String val) {
description = val;
return this;
}
@Override
public IDescription withPort(int val) {
port = val;
return this;
}
@Override
public IPort withIpAddress(String val) {
ipAddress = val;
return this;
}
@Override
public IIpAddress withUrl(String val) {
url = val;
return this;
}
@Override
public IUrl withProtocol(String val) {
protocol = val;
return this;
}
public Server build() {
return new Server(this);
}
}
}
In IntelliJ IDEA 12.x or later, go to File
> Settings
> Plugins
or
Intellij IDEA
> Preferences
> Plugins
on Mac OSx. Click the Browse repositories
button, in
the search field, type online.devliving.stepbuilder.generator
or Step Builder Generator
.
It should show up in the plugin list. Right-click it and select Download and Install
.
Download the plugin jar stepbuilder.jar
and select "Install Plugin From Disk" in IntelliJ's plugin preferences.
Use Shift+Ctrl+S
or Alt+Insert
and select Step Builder
. Choose the mandatory fields
(the fields that must be set for an object of this class) and press OK
.
If you enjoy this plugin, please rate it on it's plugins.jetbrains.com page.
Licensed under the Apache License, Version 2.0.
The source code is based on the code from the innerbuilder plugin.