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 4219e92 commit 4142a72
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ public MessageHandler mqttInputMessageHandler() {
// remove stoveId props as it has its own property in the wrapping object
props.remove("stoveId");

applicationEventPublisher.publishEvent(new MqttCommandEvent(stoveId, props));
applicationEventPublisher.publishEvent(
MqttCommandEvent.builder().withStoveId(stoveId).withProps(props));
} catch (JsonSyntaxException ex) {
log.atWarning().log(
"Received an invalid json payload via MQTT. Please ensure it follows the format defined in the doc.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,82 @@
package dev.cookiecode.rika2mqtt.rika.mqtt.event;

import java.util.Map;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

/**
* @author Sebastien Vermeille
*/
@Getter
@EqualsAndHashCode
@ToString
@RequiredArgsConstructor
public class MqttCommandEvent {

private final Long stoveId;

@Getter private final Map<String, String> props;
private final Map<String, String> props;

private MqttCommandEvent(Builder builder) {
stoveId = builder.stoveId;
props = builder.props;
}

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

public interface IBuild {
MqttCommandEvent build();
}

public interface IProps {
IBuild withProps(Map<String, String> val);
}

public interface IStoveId {
IProps withStoveId(Long val);
}

/** {@code MqttCommandEvent} builder static inner class. */
public static final class Builder implements IProps, IStoveId, IBuild {
private Map<String, String> props;
private Long stoveId;

private Builder() {}

/**
* Sets the {@code props} and returns a reference to {@code IBuild}
*
* @param val the {@code props} to set
* @return a reference to this Builder
*/
@Override
public IBuild withProps(Map<String, String> val) {
props = val;
return this;
}

/**
* Sets the {@code stoveId} and returns a reference to {@code IProps}
*
* @param val the {@code stoveId} to set
* @return a reference to this Builder
*/
@Override
public IProps withStoveId(Long val) {
stoveId = val;
return this;
}

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

0 comments on commit 4142a72

Please sign in to comment.