Skip to content

Commit

Permalink
refactor: Replaced custom toString() methods with Lombok
Browse files Browse the repository at this point in the history
  • Loading branch information
jruaux committed Jan 25, 2025
1 parent 2baaf17 commit fd2304e
Show file tree
Hide file tree
Showing 22 changed files with 399 additions and 497 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ subprojects {
}

dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.redis.lettucemod;

import java.time.Duration;
import java.util.Arrays;

import io.lettuce.core.RedisURI;
import io.lettuce.core.SslVerifyMode;
import io.lettuce.core.internal.LettuceAssert;
import lombok.ToString;

@ToString
public class RedisURIBuilder {

public static final String DEFAULT_HOST = "127.0.0.1";
Expand Down Expand Up @@ -49,8 +50,12 @@ public RedisURI build() {
builder.withTimeout(timeout);
}
RedisURI redisURI = builder.build();
redisURI.setLibraryName(libraryName);
redisURI.setLibraryVersion(libraryVersion);
if (RedisModulesUtils.hasLength(libraryName) && !RedisModulesUtils.hasLength(redisURI.getLibraryName())) {
redisURI.setLibraryName(libraryName);
}
if (RedisModulesUtils.hasLength(libraryVersion) && !RedisModulesUtils.hasLength(redisURI.getLibraryVersion())) {
redisURI.setLibraryVersion(libraryVersion);
}
if (RedisModulesUtils.hasLength(clientName) && !RedisModulesUtils.hasLength(redisURI.getClientName())) {
redisURI.setClientName(clientName);
}
Expand Down Expand Up @@ -117,6 +122,16 @@ public RedisURIBuilder clientName(String clientName) {
return this;
}

public RedisURIBuilder libraryName(String libraryName) {
this.libraryName = libraryName;
return this;
}

public RedisURIBuilder libraryVersion(String libraryVersion) {
this.libraryVersion = libraryVersion;
return this;
}

public RedisURIBuilder tls(boolean tls) {
this.tls = tls;
return this;
Expand All @@ -127,12 +142,4 @@ public RedisURIBuilder verifyMode(SslVerifyMode verifyMode) {
return this;
}

@Override
public String toString() {
return "RedisURIBuilder [uri=" + uri + ", host=" + host + ", port=" + port + ", socket=" + socket
+ ", username=" + username + ", password=" + Arrays.toString(password) + ", timeout=" + timeout
+ ", database=" + database + ", clientName=" + clientName + ", tls=" + tls + ", verifyMode="
+ verifyMode + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import com.redis.lettucemod.protocol.SearchCommandKeyword;

import lombok.ToString;

@ToString
public class AggregateOptions<K, V> extends BaseSearchOptions<K, V> {

private static final Load LOAD_ALL = Load.identifier("*").build();
Expand Down Expand Up @@ -54,13 +57,6 @@ public void build(SearchCommandArgs<K, V> args) {
operations.forEach(op -> op.build(args));
}

@Override
public String toString() {
return "AggregateOptions [operations=" + operations + ", loads=" + loads + ", getTimeout()=" + getTimeout()
+ ", isVerbatim()=" + isVerbatim() + ", getLimit()=" + getLimit() + ", getParams()=" + getParams()
+ ", getDialect()=" + getDialect() + "]";
}

@SuppressWarnings("rawtypes")
public static class Load implements RediSearchArgument {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.redis.lettucemod.protocol.SearchCommandKeyword;

import lombok.ToString;

@ToString
public class Apply<K, V> implements AggregateOperation<K, V> {

private final V expression;
Expand Down Expand Up @@ -32,11 +35,6 @@ public void build(SearchCommandArgs<K, V> args) {
args.add(SearchCommandKeyword.AS).addKey(as);
}

@Override
public String toString() {
return "APPLY " + expression + " " + as;
}

public static <K, V> Builder<K, V> expression(V expression) {
return new Builder<>(expression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import com.redis.lettucemod.protocol.SearchCommandKeyword;

import lombok.ToString;

@ToString
public class CreateOptions<K, V> implements RediSearchArgument<K, V> {

public enum DataType {
Expand Down Expand Up @@ -222,15 +225,6 @@ public void build(SearchCommandArgs<K, V> args) {
});
}

@Override
public String toString() {
return "CreateOptions [on=" + on + ", prefixes=" + prefixes + ", filter=" + filter + ", defaultLanguage="
+ defaultLanguage + ", languageField=" + languageField + ", defaultScore=" + defaultScore
+ ", scoreField=" + scoreField + ", payloadField=" + payloadField + ", maxTextFields=" + maxTextFields
+ ", temporary=" + temporary + ", noOffsets=" + noOffsets + ", noHL=" + noHL + ", noFields=" + noFields
+ ", noFreqs=" + noFreqs + ", skipInitialScan=" + skipInitialScan + ", stopWords=" + stopWords + "]";
}

public static <K, V> Builder<K, V> builder() {
return new Builder<>();
}
Expand Down Expand Up @@ -299,7 +293,7 @@ public Builder<K, V> payloadField(K payloadField) {
this.payloadField = Optional.of(payloadField);
return this;
}

public Builder<K, V> maxTextFields() {
return maxTextFields(true);
}
Expand All @@ -313,7 +307,7 @@ public Builder<K, V> temporary(long temporary) {
this.temporary = OptionalLong.of(temporary);
return this;
}

public Builder<K, V> noOffsets() {
return noOffsets(true);
}
Expand All @@ -322,7 +316,7 @@ public Builder<K, V> noOffsets(boolean noOffsets) {
this.noOffsets = noOffsets;
return this;
}

public Builder<K, V> noHL() {
return noHL(true);
}
Expand All @@ -331,7 +325,7 @@ public Builder<K, V> noHL(boolean noHL) {
this.noHL = noHL;
return this;
}

public Builder<K, V> noFields() {
return noFields(true);
}
Expand All @@ -340,7 +334,7 @@ public Builder<K, V> noFields(boolean noFields) {
this.noFields = noFields;
return this;
}

public Builder<K, V> noFreqs() {
return noFreqs(true);
}
Expand All @@ -349,7 +343,7 @@ public Builder<K, V> noFreqs(boolean noFreqs) {
this.noFreqs = noFreqs;
return this;
}

public Builder<K, V> skipInitialScan() {
return skipInitialScan(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import com.redis.lettucemod.protocol.SearchCommandKeyword;

import lombok.ToString;

@ToString
public class CursorOptions {

private OptionalLong count = OptionalLong.empty();
Expand Down Expand Up @@ -52,11 +55,6 @@ public int hashCode() {
return Objects.hash(count, maxIdle);
}

@Override
public String toString() {
return "CursorOptions [count=" + count + ", maxIdle=" + maxIdle + "]";
}

@Override
public boolean equals(Object obj) {
if (this == obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import com.redis.lettucemod.protocol.SearchCommandKeyword;

import lombok.ToString;

@SuppressWarnings("rawtypes")
@ToString
public class Filter<V> implements AggregateOperation {

private final V expression;
Expand All @@ -20,11 +23,6 @@ public V getExpression() {
return expression;
}

@Override
public String toString() {
return "FILTER " + expression;
}

public static <V> Filter<V> expression(V expression) {
return new Filter<>(expression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.redis.lettucemod.protocol.SearchCommandKeyword;

import lombok.ToString;

@ToString
public class GeoField<K> extends Field<K> {

private GeoField(Builder<K> builder) {
Expand All @@ -13,12 +16,6 @@ protected void buildField(SearchCommandArgs<K, Object> args) {
args.add(SearchCommandKeyword.GEO);
}

@Override
public String toString() {
return "GeoField [type=" + type + ", name=" + name + ", as=" + as + ", sortable=" + sortable
+ ", unNormalizedForm=" + unNormalizedForm + ", noIndex=" + noIndex + "]";
}

public static <K> Builder<K> name(K name) {
return new Builder<>(name);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.redis.lettucemod.search;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand All @@ -20,8 +19,10 @@
import com.redis.lettucemod.search.Reducers.ToList;

import io.lettuce.core.internal.LettuceAssert;
import lombok.ToString;

@SuppressWarnings("rawtypes")
@ToString
public class Group implements AggregateOperation {

private final String[] properties;
Expand Down Expand Up @@ -61,11 +62,6 @@ public void build(SearchCommandArgs args) {
}
}

@Override
public String toString() {
return "GROUP [properties=" + Arrays.toString(properties) + ", reducers=" + Arrays.toString(reducers) + "]";
}

public static Builder by(String... properties) {
return new Builder(properties);
}
Expand Down
Loading

0 comments on commit fd2304e

Please sign in to comment.