Update README.md

This commit is contained in:
Jordan Zimmerman
2022-04-08 09:01:07 +01:00
committed by GitHub
parent 0718e37f76
commit b2149622e4

View File

@@ -132,25 +132,15 @@ public class NameAndAgeBuilder {
* Return a "with"er for an existing record instance
*/
public static NameAndAgeBuilder.With from(NameAndAge from) {
return new NameAndAgeBuilder.With() {
@Override
public String name() {
return from.name();
}
@Override
public int age() {
return from.age();
}
};
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
*/
public static Stream<Map.Entry<String, Object>> stream(NameAndAge record) {
return Stream.of(Map.entry("name", record.name()),
Map.entry("age", record.age()));
return Stream.of(new AbstractMap.SimpleImmutableEntry<>("name", record.name()),
new AbstractMap.SimpleImmutableEntry<>("age", record.age()));
}
/**
@@ -251,6 +241,24 @@ public class NameAndAgeBuilder {
return new NameAndAge(name(), age);
}
}
private static final class _FromWith implements NameAndAgeBuilder.With {
private final NameAndAge from;
private _FromWith(NameAndAge from) {
this.from = from;
}
@Override
public String name() {
return from.name();
}
@Override
public int age() {
return from.age();
}
}
}
```