Skip to content

Commit

Permalink
Updating to set
Browse files Browse the repository at this point in the history
  • Loading branch information
josdem committed Apr 28, 2024
2 parents 6deb826 + 7a530f6 commit 9ea0142
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.josdem.kata;

public record CustomInputStream(int id) implements Comparable<CustomInputStream> {

@Override
public int compareTo(CustomInputStream that) {
return Integer.compare(this.id, that.id);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package com.josdem.kata;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

public class CustomOutputStream {
private final List<Integer> list = new ArrayList<>();
private final Logger log = Logger.getLogger(this.getClass().getName());

void storeValue(int value) {
list.add(value);
}

public List<Integer> getList() {
return list;
log.info("value: " + value);
}
}
17 changes: 0 additions & 17 deletions stream-merger/src/main/java/com/josdem/kata/CustomStream.java

This file was deleted.

10 changes: 5 additions & 5 deletions stream-merger/src/main/java/com/josdem/kata/StreamMerger.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.josdem.kata;

import java.util.List;
import java.util.Set;
import java.util.TreeSet;

public record StreamMerger(Set<CustomStream> streams) {
public record StreamMerger(Set<CustomInputStream> streams) {

public Set<CustomStream> mergeInto(CustomOutputStream stream) {
TreeSet<CustomStream> treeSet = new TreeSet<>(streams);
treeSet.forEach(item -> stream.storeValue(item.getId()));
public Set<CustomInputStream> mergeInto(CustomOutputStream stream) {
TreeSet<CustomInputStream> treeSet = new TreeSet<>(streams);
treeSet.forEach(item -> stream.storeValue(item.id()));
return treeSet;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.junit.jupiter.api.Test;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -21,17 +20,17 @@ class StreamMergerTest {
@Test
@DisplayName("getting an ordered stream collection")
void shouldGetOrderedStreamCollection() {
CustomStream cst1 = new CustomStream(2);
CustomStream cst2 = new CustomStream(1);
CustomStream cst3 = new CustomStream(0);
CustomInputStream cst1 = new CustomInputStream(2);
CustomInputStream cst2 = new CustomInputStream(1);
CustomInputStream cst3 = new CustomInputStream(0);

Set<CustomStream> streams = new HashSet<>();
Set<CustomInputStream> streams = new HashSet<>();
streams.add(cst1);
streams.add(cst2);
streams.add(cst3);

StreamMerger streamMerger = new StreamMerger(streams);
Set<CustomStream> result = streamMerger.mergeInto(new CustomOutputStream());
Set<CustomInputStream> result = streamMerger.mergeInto(new CustomOutputStream());

assertEquals(3, result.size(), "should contain three streams");
assertEquals(cst3, result.toArray()[0], "should have cst3 value");
Expand Down

0 comments on commit 9ea0142

Please sign in to comment.