Last active
April 8, 2022 08:03
-
-
Save Randgalt/8aa487a847ea2acdd76d702f7cf17d6a 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 io.soabase.recordbuilder.core.RecordBuilderGenerated; | |
import java.util.AbstractMap; | |
import java.util.ArrayList; | |
import java.util.Collection; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.Objects; | |
import java.util.stream.Stream; | |
import javax.annotation.processing.Generated; | |
import javax.validation.constraints.NotNull; | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@RecordBuilderGenerated | |
public class FullRecordBuilder { | |
private List<Number> numbers; | |
private Map<Number, FullRecord> fullRecords; | |
private String justAString; | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
private FullRecordBuilder() { | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
private FullRecordBuilder(List<Number> numbers, Map<Number, FullRecord> fullRecords, | |
String justAString) { | |
this.numbers = new ArrayList<>(numbers); | |
this.fullRecords = new HashMap<>(fullRecords); | |
this.justAString = justAString; | |
} | |
/** | |
* Static constructor/builder. Can be used instead of new FullRecord(...) | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public static FullRecord FullRecord(@NotNull List<Number> numbers, | |
@NotNull Map<Number, FullRecord> fullRecords, @NotNull String justAString) { | |
numbers = __list(numbers); | |
fullRecords = __map(fullRecords); | |
Objects.requireNonNull(justAString, "justAString is required"); | |
return new FullRecord(numbers, fullRecords, justAString); | |
} | |
/** | |
* Return a new builder with all fields set to default Java values | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public static FullRecordBuilder builder() { | |
return new FullRecordBuilder(); | |
} | |
/** | |
* 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 FullRecordBuilder builder(FullRecord from) { | |
return new FullRecordBuilder(from.numbers(), from.fullRecords(), from.justAString()); | |
} | |
/** | |
* Return a "with"er for an existing record instance | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public static FullRecordBuilder.With from(FullRecord from) { | |
return new _FromWith(from); | |
} | |
/** | |
* 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 Stream<Map.Entry<String, Object>> stream(FullRecord record) { | |
return Stream.of(new AbstractMap.SimpleImmutableEntry<>("numbers", record.numbers()), | |
new AbstractMap.SimpleImmutableEntry<>("fullRecords", record.fullRecords()), | |
new AbstractMap.SimpleImmutableEntry<>("justAString", record.justAString())); | |
} | |
/** | |
* Return a new record instance with all fields set to the current values in this builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public FullRecord build() { | |
numbers = __list(numbers); | |
fullRecords = __map(fullRecords); | |
Objects.requireNonNull(justAString, "justAString is required"); | |
return new FullRecord(numbers, fullRecords, justAString); | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@Override | |
public String toString() { | |
return "FullRecordBuilder[numbers=" + numbers + ", fullRecords=" + fullRecords + ", justAString=" + justAString + "]"; | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@Override | |
public int hashCode() { | |
return Objects.hash(numbers, fullRecords, justAString); | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@Override | |
public boolean equals(Object o) { | |
return (this == o) || ((o instanceof FullRecordBuilder r) | |
&& Objects.equals(numbers, r.numbers) | |
&& Objects.equals(fullRecords, r.fullRecords) | |
&& Objects.equals(justAString, r.justAString)); | |
} | |
/** | |
* Re-create the internally allocated {@code ArrayList} for {@code numbers} by copying the argument | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public FullRecordBuilder numbers(@NotNull Collection<? extends Number> numbers) { | |
this.numbers = (numbers != null) ? new ArrayList<>(numbers) : null; | |
return this; | |
} | |
/** | |
* Return the current value for the {@code numbers} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@NotNull | |
public List<Number> numbers() { | |
return numbers; | |
} | |
/** | |
* Add to the internally allocated {@code ArrayList} for {@code numbers} | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public FullRecordBuilder addNumbers(Number i) { | |
if (this.numbers == null) { | |
this.numbers = new ArrayList<>(); | |
} | |
this.numbers.add(i); | |
return this; | |
} | |
/** | |
* Add to the internally allocated {@code ArrayList} for {@code numbers} | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public FullRecordBuilder addNumbers(Stream<? extends Number> i) { | |
if (this.numbers == null) { | |
this.numbers = new ArrayList<>(); | |
} | |
i.forEach(this.numbers::add); | |
return this; | |
} | |
/** | |
* Add to the internally allocated {@code ArrayList} for {@code numbers} | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public FullRecordBuilder addNumbers(Iterable<? extends Number> i) { | |
if (this.numbers == null) { | |
this.numbers = new ArrayList<>(); | |
} | |
i.forEach(this.numbers::add); | |
return this; | |
} | |
/** | |
* Re-create the internally allocated {@code HashMap} for {@code fullRecords} by copying the argument | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public FullRecordBuilder fullRecords( | |
@NotNull Map<? extends Number, ? extends FullRecord> fullRecords) { | |
this.fullRecords = (fullRecords != null) ? new HashMap<>(fullRecords) : null; | |
return this; | |
} | |
/** | |
* Return the current value for the {@code fullRecords} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@NotNull | |
public Map<Number, FullRecord> fullRecords() { | |
return fullRecords; | |
} | |
/** | |
* Add to the internally allocated {@code HashMap} for {@code fullRecords} | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public FullRecordBuilder addFullRecords(Number key, FullRecord value) { | |
if (this.fullRecords == null) { | |
this.fullRecords = new HashMap<>(); | |
} | |
this.fullRecords.put(key, value); | |
return this; | |
} | |
/** | |
* Add to the internally allocated {@code HashMap} for {@code fullRecords} | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public FullRecordBuilder addFullRecords( | |
Stream<? extends Map.Entry<? extends Number, ? extends FullRecord>> i) { | |
if (this.fullRecords == null) { | |
this.fullRecords = new HashMap<>(); | |
} | |
i.forEach(entry -> this.fullRecords.put(entry.getKey(), entry.getValue())); | |
return this; | |
} | |
/** | |
* Add to the internally allocated {@code HashMap} for {@code fullRecords} | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public FullRecordBuilder addFullRecords( | |
Iterable<? extends Map.Entry<? extends Number, ? extends FullRecord>> i) { | |
if (this.fullRecords == null) { | |
this.fullRecords = new HashMap<>(); | |
} | |
i.forEach(entry -> this.fullRecords.put(entry.getKey(), entry.getValue())); | |
return this; | |
} | |
/** | |
* Set a new value for the {@code justAString} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public FullRecordBuilder justAString(@NotNull String justAString) { | |
this.justAString = justAString; | |
return this; | |
} | |
/** | |
* Return the current value for the {@code justAString} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@NotNull | |
public String justAString() { | |
return justAString; | |
} | |
@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 <K, V> Map<K, V> __map(Map<K, V> o) { | |
return (o != null) ? Map.copyOf(o) : Map.of(); | |
} | |
/** | |
* Add withers to {@code FullRecord} | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@RecordBuilderGenerated | |
public interface With { | |
/** | |
* Return the current value for the {@code numbers} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@NotNull | |
List<Number> numbers(); | |
/** | |
* Return the current value for the {@code fullRecords} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@NotNull | |
Map<Number, FullRecord> fullRecords(); | |
/** | |
* Return the current value for the {@code justAString} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@NotNull | |
String justAString(); | |
/** | |
* Return a new record builder using the current values | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
default FullRecordBuilder with() { | |
return new FullRecordBuilder(numbers(), fullRecords(), justAString()); | |
} | |
/** | |
* Return a new record built from the builder passed to the given consumer | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
default FullRecord with(java.util.function.Consumer<FullRecordBuilder> consumer) { | |
FullRecordBuilder builder = with(); | |
consumer.accept(builder); | |
return builder.build(); | |
} | |
/** | |
* Return a new instance of {@code FullRecord} with a new value for {@code numbers} | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
default FullRecord withNumbers(@NotNull List<Number> numbers) { | |
return new FullRecord(__list(numbers), fullRecords(), justAString()); | |
} | |
/** | |
* Return a new instance of {@code FullRecord} with a new value for {@code fullRecords} | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
default FullRecord withFullRecords(@NotNull Map<Number, FullRecord> fullRecords) { | |
return new FullRecord(numbers(), __map(fullRecords), justAString()); | |
} | |
/** | |
* Return a new instance of {@code FullRecord} with a new value for {@code justAString} | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
default FullRecord withJustAString(@NotNull String justAString) { | |
Objects.requireNonNull(justAString, "justAString is required"); | |
return new FullRecord(numbers(), fullRecords(), justAString); | |
} | |
/** | |
* Map record components into a new object | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
default <R> R map(Function<R> proc) { | |
return proc.apply(numbers(), fullRecords(), justAString()); | |
} | |
/** | |
* Perform an operation on record components | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
default void accept(Consumer proc) { | |
proc.apply(numbers(), fullRecords(), justAString()); | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@FunctionalInterface | |
interface Function<R> { | |
R apply(@NotNull List<Number> numbers, @NotNull Map<Number, FullRecord> fullRecords, | |
@NotNull String justAString); | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@FunctionalInterface | |
interface Consumer { | |
void apply(@NotNull List<Number> numbers, @NotNull Map<Number, FullRecord> fullRecords, | |
@NotNull String justAString); | |
} | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@RecordBuilderGenerated | |
private static final class _FromWith implements FullRecordBuilder.With { | |
private final FullRecord from; | |
private _FromWith(FullRecord from) { | |
this.from = from; | |
} | |
@Override | |
public List<Number> numbers() { | |
return from.numbers(); | |
} | |
@Override | |
public Map<Number, FullRecord> fullRecords() { | |
return from.fullRecords(); | |
} | |
@Override | |
public String justAString() { | |
return from.justAString(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment