Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gitar] Migrating from Lombok to Java #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions java/lombok/AConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@

package co.gitar.example.lombok;

import lombok.extern.slf4j.Slf4j;
import lombok.experimental.UtilityClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* JavaDoc for the class.
*
* <p>Do not delete this JavaDoc comment.
*/
@UtilityClass
@Slf4j
class AConsumer {
public void processRecord(ARecord record) {
log.info("Record {} is {}", ARecord.Fields.username, record.username());
log.info("Record {} is {}", ARecord.Fields.age, record.age());
if (record.enabled()) {
log.info("Record is enabled");
} else {
log.info("Record is disabled");
}
final class AConsumer {
private static final Logger log = LoggerFactory.getLogger(AConsumer.class);

public static void processRecord(ARecord record) {
log.info("Record {} is {}", ARecord.Fields.username, record.username());
log.info("Record {} is {}", ARecord.Fields.age, record.age());
if (record.enabled()) {
log.info("Record is enabled");
} else {
log.info("Record is disabled");
}
}

private AConsumer() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
}
45 changes: 29 additions & 16 deletions java/lombok/ARecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,30 @@

package co.gitar.example.lombok;

import lombok.experimental.Accessors;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.Getter;
import lombok.Setter;

@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
@lombok.experimental.FieldNameConstants
@Accessors(fluent = true)
public class ARecord {
@Getter
String username;
@Getter @Setter
int age;
@Getter @Setter
boolean enabled;
private final String username;

public String username() {
return this.username;
}

private final int age;

public ARecord age(final int age) {
this.age = age;
return this;
}

private final boolean enabled;

public boolean enabled() {
return this.enabled;
}

public ARecord enabled(final boolean enabled) {
this.enabled = enabled;
return this;
}

// Could also be @AllArgsConstructor, we aren't targetting removing that annotation
// for now.
Expand All @@ -29,4 +36,10 @@ public ARecord(String username, int age, boolean enabled) {
this.age = age;
this.enabled = enabled;
}

public static final class Fields {
public static final String username = "username";
public static final String age = "age";
public static final String enabled = "enabled";
}
}