Skip to content

Commit

Permalink
Create v3
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp94831 committed Apr 19, 2024
1 parent f09f874 commit 776832c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
import org.apache.kafka.common.serialization.Serde;

@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
final class ConfigurableSerde<T> implements Configurable<Serde<T>> {
final class ConfigurableSerde<S extends Serde<T>, T> implements Configurable<S> {

private final @NonNull Serde<T> serde;
private final @NonNull S serde;

@Override
public Serde<T> configure(final Map<String, Object> config, final boolean isKey) {
public S configure(final Map<String, Object> config, final boolean isKey) {
this.serde.configure(config, isKey);
return this.serde;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
import org.apache.kafka.common.serialization.Serializer;

@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
final class ConfigurableSerializer<T> implements Configurable<Serializer<T>> {
final class ConfigurableSerializer<S extends Serializer<T>, T> implements Configurable<S> {

private final @NonNull Serializer<T> serializer;
private final @NonNull S serializer;

@Override
public Serializer<T> configure(final Map<String, Object> config, final boolean isKey) {
public S configure(final Map<String, Object> config, final boolean isKey) {
this.serializer.configure(config, isKey);
return this.serializer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ public <T> Serializer<T> configureForKeys(final Serializer<T> serializer,

/**
* Configure a {@code Preconfigured} object using {@link #kafkaProperties}
* @param preConfigured pre-configured {@link Serde} or {@link Serializer}
* @param preconfigured pre-configured {@link Serde} or {@link Serializer}
* @return configured instance
* @param <T> type of configured instance
*/
public <T> T configure(final Preconfigured<T> preConfigured) {
return preConfigured.configure(this.kafkaProperties);
public <T> T configure(final Preconfigured<T> preconfigured) {
return preconfigured.configure(this.kafkaProperties);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ public final class Preconfigured<T> {
* Pre-configure a {@code Serde} for values
* @param serde {@code Serde} to pre-configure
* @return pre-configured serde
* @param <S> type of {@link Serde}
* @param <T> type (de-)serialized by the {@code Serde}
*/
public static <T> Preconfigured<Serde<T>> value(final Serde<T> serde) {
public static <S extends Serde<T>, T> Preconfigured<S> value(final S serde) {
return value(configurable(serde));
}

Expand All @@ -60,19 +61,22 @@ public static <T> Preconfigured<Serde<T>> value(final Serde<T> serde) {
* @param serde {@code Serde} to pre-configure
* @param configOverrides configs passed to {@link Serde#configure(Map, boolean)}
* @return pre-configured serde
* @param <S> type of {@link Serde}
* @param <T> type (de-)serialized by the {@code Serde}
*/
public static <T> Preconfigured<Serde<T>> value(final Serde<T> serde, final Map<String, Object> configOverrides) {
public static <S extends Serde<T>, T> Preconfigured<S> value(final S serde,
final Map<String, Object> configOverrides) {
return value(configurable(serde), configOverrides);
}

/**
* Pre-configure a {@code Serde} for keys
* @param serde {@code Serde} to pre-configure
* @return pre-configured serde
* @param <S> type of {@link Serde}
* @param <T> type (de-)serialized by the {@code Serde}
*/
public static <T> Preconfigured<Serde<T>> key(final Serde<T> serde) {
public static <S extends Serde<T>, T> Preconfigured<S> key(final S serde) {
return key(configurable(serde));
}

Expand All @@ -81,19 +85,22 @@ public static <T> Preconfigured<Serde<T>> key(final Serde<T> serde) {
* @param serde {@code Serde} to pre-configure
* @param configOverrides configs passed to {@link Serde#configure(Map, boolean)}
* @return pre-configured serde
* @param <S> type of {@link Serde}
* @param <T> type (de-)serialized by the {@code Serde}
*/
public static <T> Preconfigured<Serde<T>> key(final Serde<T> serde, final Map<String, Object> configOverrides) {
public static <S extends Serde<T>, T> Preconfigured<S> key(final S serde,
final Map<String, Object> configOverrides) {
return key(configurable(serde), configOverrides);
}

/**
* Pre-configure a {@code Serializer} for values
* @param serializer {@code Serializer} to pre-configure
* @return pre-configured serializer
* @param <S> type of {@link Serializer}
* @param <T> type serialized by the {@code Serializer}
*/
public static <T> Preconfigured<Serializer<T>> value(final Serializer<T> serializer) {
public static <S extends Serializer<T>, T> Preconfigured<S> value(final S serializer) {
return value(configurable(serializer));
}

Expand All @@ -102,9 +109,10 @@ public static <T> Preconfigured<Serializer<T>> value(final Serializer<T> seriali
* @param serializer {@code Serializer} to pre-configure
* @param configOverrides configs passed to {@link Serializer#configure(Map, boolean)}
* @return pre-configured serializer
* @param <S> type of {@link Serializer}
* @param <T> type serialized by the {@code Serializer}
*/
public static <T> Preconfigured<Serializer<T>> value(final Serializer<T> serializer,
public static <S extends Serializer<T>, T> Preconfigured<S> value(final S serializer,
final Map<String, Object> configOverrides) {
return value(configurable(serializer), configOverrides);
}
Expand All @@ -113,9 +121,10 @@ public static <T> Preconfigured<Serializer<T>> value(final Serializer<T> seriali
* Pre-configure a {@code Serializer} for keys
* @param serializer {@code Serializer} to pre-configure
* @return pre-configured serializer
* @param <S> type of {@link Serializer}
* @param <T> type serialized by the {@code Serializer}
*/
public static <T> Preconfigured<Serializer<T>> key(final Serializer<T> serializer) {
public static <S extends Serializer<T>, T> Preconfigured<S> key(final S serializer) {
return key(configurable(serializer));
}

Expand All @@ -124,18 +133,19 @@ public static <T> Preconfigured<Serializer<T>> key(final Serializer<T> serialize
* @param serializer {@code Serializer} to pre-configure
* @param configOverrides configs passed to {@link Serializer#configure(Map, boolean)}
* @return pre-configured serializer
* @param <S> type of {@link Serializer}
* @param <T> type serialized by the {@code Serializer}
*/
public static <T> Preconfigured<Serializer<T>> key(final Serializer<T> serializer,
public static <S extends Serializer<T>, T> Preconfigured<S> key(final S serializer,
final Map<String, Object> configOverrides) {
return key(configurable(serializer), configOverrides);
}

private static <T> ConfigurableSerde<T> configurable(final Serde<T> serde) {
private static <S extends Serde<T>, T> ConfigurableSerde<S, T> configurable(final S serde) {
return new ConfigurableSerde<>(serde);
}

private static <T> ConfigurableSerializer<T> configurable(final Serializer<T> serializer) {
private static <S extends Serializer<T>, T> ConfigurableSerializer<S, T> configurable(final S serializer) {
return new ConfigurableSerializer<>(serializer);
}

Expand Down

0 comments on commit 776832c

Please sign in to comment.