Skip to content

Commit

Permalink
fix: replace create with constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
lbovet committed Aug 23, 2021
1 parent b6659c8 commit 99a9f8f
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 49 deletions.
2 changes: 1 addition & 1 deletion kobuka-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kobuka</artifactId>
<groupId>org.swisspush</groupId>
<version>1.0.1</version>
<version>1.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
package org.swisspush.kobuka.client;

import org.swisspush.kobuka.client.base.BaseAdminClientConfigBuilder;
import org.swisspush.kobuka.client.base.BaseCommonClientConfigBuilder;

public class AdminClientConfigBuilder extends BaseAdminClientConfigBuilder<AdminClientConfigBuilder> {

public AdminClientConfigBuilder() {
}

public AdminClientConfigBuilder(BaseAdminClientConfigBuilder<?> parent) {
copyFrom(parent);
}

public AdminClientConfigBuilder(BaseCommonClientConfigBuilder<?> parent) {
copyFrom(parent);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
package org.swisspush.kobuka.client;

import org.swisspush.kobuka.client.base.BaseCommonClientConfigBuilder;
import org.swisspush.kobuka.client.base.BaseConsumerConfigBuilder;

public class ConsumerConfigBuilder extends BaseConsumerConfigBuilder<ConsumerConfigBuilder> {

public ConsumerConfigBuilder() {
}

public ConsumerConfigBuilder(BaseConsumerConfigBuilder<?> parent) {
copyFrom(parent);
}

public ConsumerConfigBuilder(BaseCommonClientConfigBuilder<?> parent) {
copyFrom(parent);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
package org.swisspush.kobuka.client;

import org.swisspush.kobuka.client.base.BaseCommonClientConfigBuilder;
import org.swisspush.kobuka.client.base.BaseConsumerConfigBuilder;
import org.swisspush.kobuka.client.base.BaseProducerConfigBuilder;

public class ProducerConfigBuilder extends BaseProducerConfigBuilder<ProducerConfigBuilder> {

public ProducerConfigBuilder() {
}

public ProducerConfigBuilder(BaseProducerConfigBuilder<?> parent) {
copyFrom(parent);
}

public ProducerConfigBuilder(BaseCommonClientConfigBuilder<?> parent) {
copyFrom(parent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,12 @@
public class BaseAdminClientConfigBuilder<T extends BaseAdminClientConfigBuilder<T>>
extends AbstractAdminClientConfigBuilder<T> implements ClientBuilderFunctions<T> {

public static <T extends BaseAdminClientConfigBuilder<T>> BaseAdminClientConfigBuilder<T> create() {
return new BaseAdminClientConfigBuilder<>();
public void copyFrom(BaseAdminClientConfigBuilder<?> parent) {
configs.putAll(parent.configs);
}

public static <T extends BaseAdminClientConfigBuilder<T>> BaseAdminClientConfigBuilder<T> create(BaseAdminClientConfigBuilder<?> parent) {
BaseAdminClientConfigBuilder<T> result = new BaseAdminClientConfigBuilder<>();
result.configs.putAll(parent.configs);
return result;
}

public static <T extends BaseAdminClientConfigBuilder<T>> BaseAdminClientConfigBuilder<T> create(BaseCommonClientConfigBuilder<?> parent) {
BaseAdminClientConfigBuilder<T> result = new BaseAdminClientConfigBuilder<>();
result.configs.putAll(parent.configs);
return result;
public void copyFrom(BaseCommonClientConfigBuilder<?> parent) {
configs.putAll(parent.configs);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package org.swisspush.kobuka.client.base;

import java.util.Map;
import java.util.function.Function;

/**
* Base class for custom builders. Do not use directly.
*/
public class BaseCommonClientConfigBuilder<T extends BaseCommonClientConfigBuilder<T>> extends AbstractCommonClientConfigBuilder<T> {
public class BaseCommonClientConfigBuilder<T extends BaseCommonClientConfigBuilder<T>>
extends AbstractCommonClientConfigBuilder<T>
implements ClientBuilderFunctions<T> {

public static BaseCommonClientConfigBuilder<?> create() {
return new BaseCommonClientConfigBuilder<>();
}

@Override
public Map<String, Object> build() {
return configs;
}

public <R> R transform(Function<BaseCommonClientConfigBuilder<?>, R> fn) {
return fn.apply(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,12 @@
public class BaseConsumerConfigBuilder<T extends BaseConsumerConfigBuilder<T> & ClientBuilderFunctions<T>>
extends AbstractConsumerConfigBuilder<T> implements ClientBuilderFunctions<T> {

public static <T extends BaseConsumerConfigBuilder<T>> BaseConsumerConfigBuilder<T> create() {
return new BaseConsumerConfigBuilder<T>();
public void copyFrom(BaseConsumerConfigBuilder<?> parent) {
configs.putAll(parent.configs);
}

public static <T extends BaseConsumerConfigBuilder<T>> BaseConsumerConfigBuilder<T> create(BaseConsumerConfigBuilder<?> parent) {
BaseConsumerConfigBuilder<T> result = new BaseConsumerConfigBuilder<>();
result.configs.putAll(parent.configs);
return result;
}

public static <T extends BaseConsumerConfigBuilder<T>> BaseConsumerConfigBuilder<T> create(BaseCommonClientConfigBuilder<?> parent) {
BaseConsumerConfigBuilder<T> result = new BaseConsumerConfigBuilder<>();
result.configs.putAll(parent.configs);
return result;
public void copyFrom(BaseCommonClientConfigBuilder<?> parent) {
configs.putAll(parent.configs);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@
*/
public class BaseProducerConfigBuilder<T extends BaseProducerConfigBuilder<T> & ClientBuilderFunctions<T>>
extends AbstractProducerConfigBuilder<T> implements ClientBuilderFunctions<T> {
public static <T extends BaseProducerConfigBuilder<T>> BaseProducerConfigBuilder<T> create() {
return new BaseProducerConfigBuilder<T>();
}

public static <T extends BaseProducerConfigBuilder<T>> BaseProducerConfigBuilder<T> create(BaseProducerConfigBuilder<?> parent) {
BaseProducerConfigBuilder<T> result = new BaseProducerConfigBuilder<>();
result.configs.putAll(parent.configs);
return result;
public void copyFrom(BaseProducerConfigBuilder<?> parent) {
configs.putAll(parent.configs);
}

public static <T extends BaseProducerConfigBuilder<T>> BaseProducerConfigBuilder<T> create(BaseCommonClientConfigBuilder<?> parent) {
BaseProducerConfigBuilder<T> result = new BaseProducerConfigBuilder<>();
result.configs.putAll(parent.configs);
return result;
public void copyFrom(BaseCommonClientConfigBuilder<?> parent) {
configs.putAll(parent.configs);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testCopy() {

ConsumerConfig config =
original
.transform(ConsumerConfigBuilder::create)
.transform(ConsumerConfigBuilder::new)
.autoCommitIntervalMs(1234)
.build(ConsumerConfig::new);

Expand All @@ -69,14 +69,14 @@ public void testInheritance() {

ConsumerConfig consumerConfig =
commonConfigBuilder
.transform(ConsumerConfigBuilder::create)
.transform(ConsumerConfigBuilder::new)
.keyDeserializer(StringDeserializer.class)
.valueDeserializer(StringDeserializer.class)
.build(ConsumerConfig::new);

ProducerConfig producerConfig =
commonConfigBuilder
.transform(ProducerConfigBuilder::create)
.transform(ProducerConfigBuilder::new)
.keySerializer(StringDeserializer.class)
.valueSerializer(StringDeserializer.class)
.build(ProducerConfig::new);
Expand Down Expand Up @@ -149,4 +149,12 @@ private <T> T safeGet(Supplier<T> supplier) {
throw new RuntimeException(e);
}
}

@Test
public void testCast() {
ConsumerConfigBuilder b = new CommonClientConfigBuilder()
.bootstrapServers("localhost:9092")
.transform(ConsumerConfigBuilder::new);
}

}
2 changes: 1 addition & 1 deletion kobuka-gen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kobuka</artifactId>
<groupId>org.swisspush</groupId>
<version>1.0.1</version>
<version>1.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion kobuka-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kobuka</artifactId>
<groupId>org.swisspush</groupId>
<version>1.0.1</version>
<version>1.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,4 @@ public DefaultKafkaConsumerFactoryBuilder(Map<String, Object> configs) {
configs(configs);
}

public static <K, V> DefaultKafkaConsumerFactoryBuilder<K, V> create(Map<String, Object> configs) {
return new DefaultKafkaConsumerFactoryBuilder<K, V>(configs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,4 @@ public DefaultKafkaProducerFactoryBuilder(Map<String, Object> configs) {
configs(configs);
}

public static <K, V> DefaultKafkaProducerFactoryBuilder<K, V> create(Map<String, Object> configs) {
return new DefaultKafkaProducerFactoryBuilder<K, V>(configs);
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>org.swisspush</groupId>
<artifactId>kobuka</artifactId>
<packaging>pom</packaging>
<version>1.0.1</version>
<version>1.0.2</version>

<build>
<plugins>
Expand Down

0 comments on commit 99a9f8f

Please sign in to comment.