Skip to content

Commit

Permalink
Make DatastreamMetadata Immutable (#72693)
Browse files Browse the repository at this point in the history
This map should not be mutable. Also, the builder is unused.
  • Loading branch information
original-brownbear authored May 4, 2021
1 parent 276601d commit cbb2ca2
Showing 1 changed file with 2 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public class DataStreamMetadata implements Metadata.Custom {
private final Map<String, DataStream> dataStreams;

public DataStreamMetadata(Map<String, DataStream> dataStreams) {
this.dataStreams = dataStreams;
this.dataStreams = Map.copyOf(dataStreams);
}

public DataStreamMetadata(StreamInput in) throws IOException {
this.dataStreams = in.readMap(StreamInput::readString, DataStream::new);
this(in.readMap(StreamInput::readString, DataStream::new));
}

public Map<String, DataStream> dataStreams() {
Expand Down Expand Up @@ -105,10 +105,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}

public static Builder builder() {
return new Builder();
}

@Override
public int hashCode() {
return Objects.hash(this.dataStreams);
Expand All @@ -131,20 +127,6 @@ public String toString() {
return Strings.toString(this);
}

public static class Builder {

private final Map<String, DataStream> dataStreams = new HashMap<>();

public Builder putDataStream(DataStream dataStream) {
dataStreams.put(dataStream.getName(), dataStream);
return this;
}

public DataStreamMetadata build() {
return new DataStreamMetadata(dataStreams);
}
}

static class DataStreamMetadataDiff implements NamedDiff<Metadata.Custom> {

final Diff<Map<String, DataStream>> dataStreamDiff;
Expand Down

0 comments on commit cbb2ca2

Please sign in to comment.