Skip to content

Commit

Permalink
Use step builders instead of lombok builders
Browse files Browse the repository at this point in the history
That way it increases developer experience
  • Loading branch information
sebastienvermeille committed Feb 6, 2024
1 parent 9bde64b commit 4219e92
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void publishToMqtt() {

applicationEventPublisher.publishEvent(
PolledStoveStatusEvent.builder()
.stoveStatus(stoveStatusMapper.toApiStoveStatus(status))
.withStoveStatus(stoveStatusMapper.toApiStoveStatus(status))
.build());

handleStoveErrors(status);
Expand Down Expand Up @@ -180,7 +180,7 @@ private void handleStoveErrors(@NonNull StoveStatus status) {
mqttService.publishNotification(jsonNotification);

applicationEventPublisher.publishEvent(
StoveErrorEvent.builder().stoveError(enrichedStoveError).build());
StoveErrorEvent.builder().withStoveError(enrichedStoveError).build());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,55 @@
/**
* @author Sebastien Vermeille
*/
@RequiredArgsConstructor
@Getter
@ToString
@EqualsAndHashCode
@Builder
@Beta
public class PolledStoveStatusEvent implements Rika2MqttPluginEvent {
private final StoveStatus stoveStatus;

private PolledStoveStatusEvent(Builder builder) {
stoveStatus = builder.stoveStatus;
}

public static IStoveStatus builder() {
return new Builder();
}

public interface IBuild {
PolledStoveStatusEvent build();
}

public interface IStoveStatus {
IBuild withStoveStatus(StoveStatus val);
}

/** {@code PolledStoveStatusEvent} builder static inner class. */
public static final class Builder implements IStoveStatus, IBuild {
private StoveStatus stoveStatus;

private Builder() {}

/**
* Sets the {@code stoveStatus} and returns a reference to {@code IBuild}
*
* @param val the {@code stoveStatus} to set
* @return a reference to this Builder
*/
@Override
public IBuild withStoveStatus(StoveStatus val) {
stoveStatus = val;
return this;
}

/**
* Returns a {@code PolledStoveStatusEvent} built from the parameters previously set.
*
* @return a {@code PolledStoveStatusEvent} built with parameters of this {@code
* PolledStoveStatusEvent.Builder}
*/
public PolledStoveStatusEvent build() {
return new PolledStoveStatusEvent(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,55 @@
*
* @author Sebastien Vermeille
*/
@RequiredArgsConstructor
@Getter
@ToString
@EqualsAndHashCode
@Builder
@Beta
public class StoveErrorEvent implements Rika2MqttPluginEvent {
private final StoveError stoveError;

private StoveErrorEvent(Builder builder) {
stoveError = builder.stoveError;
}

public static IStoveError builder() {
return new Builder();
}

public interface IBuild {
StoveErrorEvent build();
}

public interface IStoveError {
IBuild withStoveError(StoveError val);
}

/** {@code StoveErrorEvent} builder static inner class. */
public static final class Builder implements IStoveError, IBuild {
private StoveError stoveError;

private Builder() {}

/**
* Sets the {@code stoveError} and returns a reference to {@code IBuild}
*
* @param val the {@code stoveError} to set
* @return a reference to this Builder
*/
@Override
public IBuild withStoveError(StoveError val) {
stoveError = val;
return this;
}

/**
* Returns a {@code StoveErrorEvent} built from the parameters previously set.
*
* @return a {@code StoveErrorEvent} built with parameters of this {@code
* StoveErrorEvent.Builder}
*/
public StoveErrorEvent build() {
return new StoveErrorEvent(this);
}
}
}

0 comments on commit 4219e92

Please sign in to comment.