-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove guava & lettuce * remove io.projectreactor:reactor-core from dependency * Update CHANGELOG.md
- Loading branch information
Showing
6 changed files
with
466 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
src/main/java/com/clickhouse/kafka/connect/util/reactor/function/Tuple2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
package com.clickhouse.kafka.connect.util.reactor.function; | ||
|
||
import java.io.Serializable; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* A tuple that holds two non-null values. | ||
* | ||
* @param <T1> The type of the first non-null value held by this tuple | ||
* @param <T2> The type of the second non-null value held by this tuple | ||
* @author Jon Brisbin | ||
* @author Stephane Maldini | ||
*/ | ||
@SuppressWarnings("rawtypes") | ||
public class Tuple2<T1, T2> implements Iterable<Object>, Serializable { | ||
|
||
private static final long serialVersionUID = -3518082018884860684L; | ||
|
||
final T1 t1; | ||
final T2 t2; | ||
|
||
Tuple2(T1 t1, T2 t2) { | ||
this.t1 = Objects.requireNonNull(t1, "t1"); | ||
this.t2 = Objects.requireNonNull(t2, "t2"); | ||
} | ||
|
||
/** | ||
* Type-safe way to get the first object of this {@link Tuples}. | ||
* | ||
* @return The first object | ||
*/ | ||
public T1 getT1() { | ||
return t1; | ||
} | ||
|
||
/** | ||
* Type-safe way to get the second object of this {@link Tuples}. | ||
* | ||
* @return The second object | ||
*/ | ||
public T2 getT2() { | ||
return t2; | ||
} | ||
|
||
/** | ||
* Map the left-hand part (T1) of this {@link reactor.util.function.Tuple2} into a different value and type, | ||
* keeping the right-hand part (T2). | ||
* | ||
* @param mapper the mapping {@link Function} for the left-hand part | ||
* @param <R> the new type for the left-hand part | ||
* @return a new {@link reactor.util.function.Tuple2} with a different left (T1) value | ||
*/ | ||
public <R> com.clickhouse.kafka.connect.util.reactor.function.Tuple2<R, T2> mapT1(Function<T1, R> mapper) { | ||
return new com.clickhouse.kafka.connect.util.reactor.function.Tuple2<>(mapper.apply(t1), t2); | ||
} | ||
|
||
/** | ||
* Map the right-hand part (T2) of this {@link reactor.util.function.Tuple2} into a different value and type, | ||
* keeping the left-hand part (T1). | ||
* | ||
* @param mapper the mapping {@link Function} for the right-hand part | ||
* @param <R> the new type for the right-hand part | ||
* @return a new {@link reactor.util.function.Tuple2} with a different right (T2) value | ||
*/ | ||
public <R> com.clickhouse.kafka.connect.util.reactor.function.Tuple2<T1, R> mapT2(Function<T2, R> mapper) { | ||
return new com.clickhouse.kafka.connect.util.reactor.function.Tuple2<>(t1, mapper.apply(t2)); | ||
} | ||
|
||
/** | ||
* Get the object at the given index. | ||
* | ||
* @param index The index of the object to retrieve. Starts at 0. | ||
* @return The object or {@literal null} if out of bounds. | ||
*/ | ||
public Object get(int index) { | ||
switch (index) { | ||
case 0: | ||
return t1; | ||
case 1: | ||
return t2; | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Turn this {@code Tuple} into a {@link List List<Object>}. | ||
* The list isn't tied to this Tuple but is a <strong>copy</strong> with limited | ||
* mutability ({@code add} and {@code remove} are not supported, but {@code set} is). | ||
* | ||
* @return A copy of the tuple as a new {@link List List<Object>}. | ||
*/ | ||
public List<Object> toList() { | ||
return Arrays.asList(toArray()); | ||
} | ||
|
||
/** | ||
* Turn this {@code Tuple} into a plain {@code Object[]}. | ||
* The array isn't tied to this Tuple but is a <strong>copy</strong>. | ||
* | ||
* @return A copy of the tuple as a new {@link Object Object[]}. | ||
*/ | ||
public Object[] toArray() { | ||
return new Object[]{t1, t2}; | ||
} | ||
|
||
/** | ||
* Return an <strong>immutable</strong> {@link Iterator Iterator<Object>} around | ||
* the content of this {@code Tuple}. | ||
* | ||
* @implNote As an {@link Iterator} is always tied to its {@link Iterable} source by | ||
* definition, the iterator cannot be mutable without the iterable also being mutable. | ||
* Since {@link Tuples} are <strong>immutable</strong>, so is the {@link Iterator} | ||
* returned by this method. | ||
* | ||
* @return An unmodifiable {@link Iterator} over the elements in this Tuple. | ||
*/ | ||
@Override | ||
public Iterator<Object> iterator() { | ||
return Collections.unmodifiableList(toList()).iterator(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
com.clickhouse.kafka.connect.util.reactor.function.Tuple2<?, ?> tuple2 = (com.clickhouse.kafka.connect.util.reactor.function.Tuple2<?, ?>) o; | ||
|
||
return t1.equals(tuple2.t1) && t2.equals(tuple2.t2); | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = size(); | ||
result = 31 * result + t1.hashCode(); | ||
result = 31 * result + t2.hashCode(); | ||
return result; | ||
} | ||
|
||
/** | ||
* Return the number of elements in this {@literal Tuples}. | ||
* | ||
* @return The size of this {@literal Tuples}. | ||
*/ | ||
public int size() { | ||
return 2; | ||
} | ||
|
||
/** | ||
* A Tuple String representation is the comma separated list of values, enclosed | ||
* in square brackets. | ||
* @return the Tuple String representation | ||
*/ | ||
@Override | ||
public final String toString() { | ||
return Tuples.tupleStringRepresentation(toArray()).insert(0, '[').append(']').toString(); | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
src/main/java/com/clickhouse/kafka/connect/util/reactor/function/Tuple3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package com.clickhouse.kafka.connect.util.reactor.function; | ||
|
||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* A tuple that holds three non-null values. | ||
* | ||
* @param <T1> The type of the first non-null value held by this tuple | ||
* @param <T2> The type of the second non-null value held by this tuple | ||
* @param <T3> The type of the third non-null value held by this tuple | ||
* @author Jon Brisbin | ||
* @author Stephane Maldini | ||
*/ | ||
public class Tuple3<T1, T2, T3> extends Tuple2<T1, T2> { | ||
|
||
private static final long serialVersionUID = -4430274211524723033L; | ||
|
||
final T3 t3; | ||
|
||
Tuple3(T1 t1, T2 t2, T3 t3) { | ||
super(t1, t2); | ||
this.t3 = Objects.requireNonNull(t3, "t3"); | ||
} | ||
|
||
/** | ||
* Type-safe way to get the third object of this {@link Tuples}. | ||
* | ||
* @return The third object | ||
*/ | ||
public T3 getT3() { | ||
return t3; | ||
} | ||
|
||
/** | ||
* Map the 1st part (T1) of this {@link reactor.util.function.Tuple3} into a different value and type, | ||
* keeping the other parts. | ||
* | ||
* @param mapper the mapping {@link Function} for the T1 part | ||
* @param <R> the new type for the T1 part | ||
* @return a new {@link reactor.util.function.Tuple3} with a different T1 value | ||
*/ | ||
public <R> com.clickhouse.kafka.connect.util.reactor.function.Tuple3<R, T2, T3> mapT1(Function<T1, R> mapper) { | ||
return new com.clickhouse.kafka.connect.util.reactor.function.Tuple3<>(mapper.apply(t1), t2, t3); | ||
} | ||
|
||
/** | ||
* Map the 2nd part (T2) of this {@link reactor.util.function.Tuple3} into a different value and type, | ||
* keeping the other parts. | ||
* | ||
* @param mapper the mapping {@link Function} for the T2 part | ||
* @param <R> the new type for the T2 part | ||
* @return a new {@link reactor.util.function.Tuple3} with a different T2 value | ||
*/ | ||
public <R> com.clickhouse.kafka.connect.util.reactor.function.Tuple3<T1, R, T3> mapT2(Function<T2, R> mapper) { | ||
return new com.clickhouse.kafka.connect.util.reactor.function.Tuple3<>(t1, mapper.apply(t2), t3); | ||
} | ||
|
||
/** | ||
* Map the 3rd part (T3) of this {@link reactor.util.function.Tuple3} into a different value and type, | ||
* keeping the other parts. | ||
* | ||
* @param mapper the mapping {@link Function} for the T3 part | ||
* @param <R> the new type for the T3 part | ||
* @return a new {@link reactor.util.function.Tuple3} with a different T3 value | ||
*/ | ||
public <R> com.clickhouse.kafka.connect.util.reactor.function.Tuple3<T1, T2, R> mapT3(Function<T3, R> mapper) { | ||
return new com.clickhouse.kafka.connect.util.reactor.function.Tuple3<>(t1, t2, mapper.apply(t3)); | ||
} | ||
|
||
@Override | ||
public Object get(int index) { | ||
switch (index) { | ||
case 0: | ||
return t1; | ||
case 1: | ||
return t2; | ||
case 2: | ||
return t3; | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public Object[] toArray() { | ||
return new Object[]{t1, t2, t3}; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof com.clickhouse.kafka.connect.util.reactor.function.Tuple3)) return false; | ||
if (!super.equals(o)) return false; | ||
|
||
@SuppressWarnings("rawtypes") | ||
com.clickhouse.kafka.connect.util.reactor.function.Tuple3 tuple3 = (com.clickhouse.kafka.connect.util.reactor.function.Tuple3) o; | ||
|
||
return t3.equals(tuple3.t3); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return 3; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = super.hashCode(); | ||
result = 31 * result + t3.hashCode(); | ||
return result; | ||
} | ||
} |
Oops, something went wrong.