Skip to content

Commit

Permalink
Simplify postLoad function
Browse files Browse the repository at this point in the history
  • Loading branch information
hstonec committed Feb 7, 2020
1 parent 2d15ed5 commit 0f50d81
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions core/src/main/java/google/registry/model/eppcommon/Address.java
Expand Up @@ -16,6 +16,7 @@

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;

import com.google.common.annotations.VisibleForTesting;
Expand All @@ -28,6 +29,8 @@
import google.registry.model.Jsonifiable;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;
import javax.persistence.Embeddable;
import javax.persistence.MappedSuperclass;
import javax.persistence.PostLoad;
Expand Down Expand Up @@ -184,16 +187,11 @@ void onLoad(@AlsoLoad("street") List<String> street) {
*/
@PostLoad
void postLoad() {
ImmutableList.Builder<String> builder = new ImmutableList.Builder<>();
if (streetLine1 != null) {
builder.add(streetLine1);
if (streetLine2 != null) {
builder.add(streetLine2);
if (streetLine3 != null) {
builder.add(streetLine3);
}
}
}
street = streetLine1 == null ? null : builder.build();
street =
streetLine1 == null
? null
: Stream.of(streetLine1, streetLine2, streetLine3)
.filter(Objects::nonNull)
.collect(toImmutableList());
}
}

0 comments on commit 0f50d81

Please sign in to comment.