Created
August 13, 2021 00:20
-
-
Save Randgalt/01acd70fedb2c474b5af6d8d0fc452a8 to your computer and use it in GitHub Desktop.
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
// Auto generated by io.soabase.recordbuilder.core.RecordBuilder: https://github.com/Randgalt/record-builder | |
package io.soabase.recordbuilder.test; | |
import java.util.AbstractMap; | |
import java.util.Collection; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.Objects; | |
import java.util.Set; | |
import java.util.function.Consumer; | |
import java.util.stream.Stream; | |
import javax.annotation.processing.Generated; | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public class CollectionRecordBuilder<T, X extends Point> { | |
private List<T> l; | |
private Set<T> s; | |
private Map<T, X> m; | |
private Collection<X> c; | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
private CollectionRecordBuilder() { | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
private CollectionRecordBuilder(List<T> l, Set<T> s, Map<T, X> m, Collection<X> c) { | |
this.l = l; | |
this.s = s; | |
this.m = m; | |
this.c = c; | |
} | |
/** | |
* Static constructor/builder. Can be used instead of new CollectionRecord(...) | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public static <T, X extends Point> CollectionRecord<T, X> CollectionRecord(List<T> l, Set<T> s, | |
Map<T, X> m, Collection<X> c) { | |
return new CollectionRecord<T, X>(__list(l), __set(s), __map(m), __collection(c)); | |
} | |
/** | |
* Return a new builder with all fields set to default Java values | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public static <T, X extends Point> CollectionRecordBuilder<T, X> builder() { | |
return new CollectionRecordBuilder<T, X>(); | |
} | |
/** | |
* Return a new builder with all fields set to the values taken from the given record instance | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public static <T, X extends Point> CollectionRecordBuilder<T, X> builder( | |
CollectionRecord<T, X> from) { | |
return new CollectionRecordBuilder<T, X>(from.l(), from.s(), from.m(), from.c()); | |
} | |
/** | |
* Return a stream of the record components as map entries keyed with the component name and the value as the component value | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public static <T, X extends Point> Stream<Map.Entry<String, Object>> stream( | |
CollectionRecord<T, X> record) { | |
return Stream.of(new AbstractMap.SimpleEntry<>("l", record.l()), | |
new AbstractMap.SimpleEntry<>("s", record.s()), | |
new AbstractMap.SimpleEntry<>("m", record.m()), | |
new AbstractMap.SimpleEntry<>("c", record.c())); | |
} | |
/** | |
* Return a new record instance with all fields set to the current values in this builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public CollectionRecord<T, X> build() { | |
return new CollectionRecord<T, X>(__list(l), __set(s), __map(m), __collection(c)); | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@Override | |
public String toString() { | |
return "CollectionRecordBuilder[l=" + l + ", s=" + s + ", m=" + m + ", c=" + c + "]"; | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@Override | |
public int hashCode() { | |
return Objects.hash(l, s, m, c); | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@Override | |
public boolean equals(Object o) { | |
return (this == o) || ((o instanceof CollectionRecordBuilder r) | |
&& Objects.equals(l, r.l) | |
&& Objects.equals(s, r.s) | |
&& Objects.equals(m, r.m) | |
&& Objects.equals(c, r.c)); | |
} | |
/** | |
* Set a new value for the {@code l} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public CollectionRecordBuilder<T, X> l(List<T> l) { | |
this.l = l; | |
return this; | |
} | |
/** | |
* Return the current value for the {@code l} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public List<T> l() { | |
return l; | |
} | |
/** | |
* Set a new value for the {@code s} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public CollectionRecordBuilder<T, X> s(Set<T> s) { | |
this.s = s; | |
return this; | |
} | |
/** | |
* Return the current value for the {@code s} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public Set<T> s() { | |
return s; | |
} | |
/** | |
* Set a new value for the {@code m} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public CollectionRecordBuilder<T, X> m(Map<T, X> m) { | |
this.m = m; | |
return this; | |
} | |
/** | |
* Return the current value for the {@code m} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public Map<T, X> m() { | |
return m; | |
} | |
/** | |
* Set a new value for the {@code c} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public CollectionRecordBuilder<T, X> c(Collection<X> c) { | |
this.c = c; | |
return this; | |
} | |
/** | |
* Return the current value for the {@code c} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public Collection<X> c() { | |
return c; | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
private static <T> List<T> __list(List<T> o) { | |
return (o != null) ? List.copyOf(o) : List.of(); | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
private static <T> Set<T> __set(Set<T> o) { | |
return (o != null) ? Set.copyOf(o) : Set.of(); | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
private static <K, V> Map<K, V> __map(Map<K, V> o) { | |
return (o != null) ? Map.copyOf(o) : Map.of(); | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
private static <T> Collection<T> __collection(Collection<T> o) { | |
if (o instanceof Set) { | |
return (o != null) ? Set.copyOf(o) : Set.of(); | |
}; | |
return (o != null) ? List.copyOf(o) : List.of(); | |
} | |
/** | |
* Add withers to {@code CollectionRecord} | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public interface With<T, X extends Point> { | |
/** | |
* Return the current value for the {@code l} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
List<T> l(); | |
/** | |
* Return the current value for the {@code s} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
Set<T> s(); | |
/** | |
* Return the current value for the {@code m} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
Map<T, X> m(); | |
/** | |
* Return the current value for the {@code c} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
Collection<X> c(); | |
/** | |
* Return a new record builder using the current values | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
default CollectionRecordBuilder<T, X> with() { | |
return new CollectionRecordBuilder(l(), s(), m(), c()); | |
} | |
/** | |
* Return a new record built from the builder passed to the given consumer | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
default CollectionRecord<T, X> with(Consumer<CollectionRecordBuilder<T, X>> consumer) { | |
CollectionRecordBuilder<T, X> builder = with(); | |
consumer.accept(builder); | |
return builder.build(); | |
} | |
/** | |
* Return a new instance of {@code CollectionRecord} with a new value for {@code l} | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
default CollectionRecord<T, X> withL(List<T> l) { | |
return new CollectionRecord<T, X>(__list(l), s(), m(), c()); | |
} | |
/** | |
* Return a new instance of {@code CollectionRecord} with a new value for {@code s} | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
default CollectionRecord<T, X> withS(Set<T> s) { | |
return new CollectionRecord<T, X>(l(), __set(s), m(), c()); | |
} | |
/** | |
* Return a new instance of {@code CollectionRecord} with a new value for {@code m} | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
default CollectionRecord<T, X> withM(Map<T, X> m) { | |
return new CollectionRecord<T, X>(l(), s(), __map(m), c()); | |
} | |
/** | |
* Return a new instance of {@code CollectionRecord} with a new value for {@code c} | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
default CollectionRecord<T, X> withC(Collection<X> c) { | |
return new CollectionRecord<T, X>(l(), s(), m(), __collection(c)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment