Created
May 30, 2020 15:00
-
-
Save Randgalt/42a3200a15ab831f8738c7fcea51a796 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.Map; | |
import java.util.Objects; | |
import java.util.stream.Stream; | |
import javax.annotation.processing.Generated; | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public class PersonRecordBuilder { | |
private String name; | |
private int age; | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
private PersonRecordBuilder() { | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
private PersonRecordBuilder(String name, int age) { | |
this.name = name; | |
this.age = age; | |
} | |
/** | |
* Return a new builder with all fields set to default Java values | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public static PersonRecordBuilder builder() { | |
return new PersonRecordBuilder(); | |
} | |
/** | |
* 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 PersonRecordBuilder builder(PersonRecord from) { | |
return new PersonRecordBuilder(from.name(), from.age()); | |
} | |
/** | |
* 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(PersonRecord record) { | |
return Stream.of(new AbstractMap.SimpleEntry<>("name", record.name()), | |
new AbstractMap.SimpleEntry<>("age", record.age())); | |
} | |
/** | |
* Return a new record instance with all fields set to the current values in this builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public PersonRecord build() { | |
return new PersonRecord(name, age); | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@Override | |
public String toString() { | |
return "PersonRecordBuilder[name=" + name + ", age=" + age + "]"; | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@Override | |
public int hashCode() { | |
return Objects.hash(name, age); | |
} | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
@Override | |
public boolean equals(Object o) { | |
return (this == o) || ((o instanceof PersonRecordBuilder b) | |
&& Objects.equals(name, b.name) | |
&& (age == b.age)); | |
} | |
/** | |
* Set a new value for the {@code name} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public PersonRecordBuilder name(String name) { | |
this.name = name; | |
return this; | |
} | |
/** | |
* Return the current value for the {@code name} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public String name() { | |
return name; | |
} | |
/** | |
* Set a new value for the {@code age} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public PersonRecordBuilder age(int age) { | |
this.age = age; | |
return this; | |
} | |
/** | |
* Return the current value for the {@code age} record component in the builder | |
*/ | |
@Generated("io.soabase.recordbuilder.core.RecordBuilder") | |
public int age() { | |
return age; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment