From 7469cedffa412ac37d5d601ef10e1918d8828232 Mon Sep 17 00:00:00 2001 From: josdem Date: Sat, 27 Apr 2024 12:44:45 -0400 Subject: [PATCH 1/2] Adding final keyword --- stream-merger/StreamMerger.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stream-merger/StreamMerger.java b/stream-merger/StreamMerger.java index d1d3588..216fcf7 100644 --- a/stream-merger/StreamMerger.java +++ b/stream-merger/StreamMerger.java @@ -3,8 +3,8 @@ import java.util.TreeSet; class InputStream implements Comparable { - private Integer streamId; - private Integer nextValue; + private final Integer streamId; + private final Integer nextValue; public InputStream(Integer streamId, Integer nextValue) { this.streamId = streamId; From c1ccbed54cbe6b9e0798d641b39cd958796394b8 Mon Sep 17 00:00:00 2001 From: josdem Date: Sat, 27 Apr 2024 12:50:26 -0400 Subject: [PATCH 2/2] Adding record --- stream-merger/StreamMerger.java | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/stream-merger/StreamMerger.java b/stream-merger/StreamMerger.java index 216fcf7..aaa11c0 100644 --- a/stream-merger/StreamMerger.java +++ b/stream-merger/StreamMerger.java @@ -2,31 +2,16 @@ import java.util.Set; import java.util.TreeSet; -class InputStream implements Comparable { - private final Integer streamId; - private final Integer nextValue; - - public InputStream(Integer streamId, Integer nextValue) { - this.streamId = streamId; - this.nextValue = nextValue; - } - - public Integer getStreamId() { - return streamId; - } - - public Integer getNextValue() { - return nextValue; - } +record InputStream(Integer streamId, Integer nextValue) implements Comparable { @Override public int compareTo(InputStream that) { - return this.getStreamId().compareTo(that.getStreamId()); + return this.streamId().compareTo(that.streamId()); } @Override public String toString() { - return this.getStreamId().toString(); + return this.streamId().toString(); } } @@ -47,7 +32,7 @@ public class StreamMerger { void mergeInto(OutputStream stream) { TreeSet treeSet = new TreeSet<>(streams); - treeSet.forEach(item -> stream.emitValue(item.getStreamId())); + treeSet.forEach(item -> stream.emitValue(item.streamId())); } public static void main(String[] args) {