Skip to content

Commit

Permalink
Heap: consumeAll now returns an empty list if nothing was found
Browse files Browse the repository at this point in the history
  • Loading branch information
eledhwen committed Oct 7, 2021
1 parent 3113d91 commit 0784624
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Add the following in your `pom.xml`:
<dependency>
<groupId>com.noleme</groupId>
<artifactId>noleme-flow</artifactId>
<version>0.14.1</version>
<version>0.14.2</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.noleme</groupId>
<artifactId>noleme-flow</artifactId>
<version>0.14.1</version>
<version>0.14.2</version>
<packaging>jar</packaging>

<name>Noleme Flow</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import com.noleme.flow.io.output.WriteableOutput;
import com.noleme.flow.stream.StreamGenerator;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -214,7 +211,7 @@ public Collection<Object> consumeAll(String id)
this.streamLock.write.lock();

if (!this.streamContents.containsKey(id))
return null;
return Collections.emptyList();

List<Object> values = this.streamContents.get(id).stream()
.map(c -> c.decrement().getValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import com.noleme.flow.io.output.WriteableOutput;
import com.noleme.flow.stream.StreamGenerator;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -142,20 +139,18 @@ else if (this.has(id))
@Override
public Collection<Object> consumeAll(String id)
{
if (this.streamContents.containsKey(id))
{
List<Object> values = this.streamContents.get(id).stream()
.map(c -> c.decrement().getValue())
.collect(Collectors.toList())
;
if (!this.streamContents.containsKey(id))
return Collections.emptyList();

if (this.streamContents.get(id).removeConsumed() == 0)
this.streamContents.remove(id);
List<Object> values = this.streamContents.get(id).stream()
.map(c -> c.decrement().getValue())
.collect(Collectors.toList())
;

return values;
}
if (this.streamContents.get(id).removeConsumed() == 0)
this.streamContents.remove(id);

return null;
return values;
}

@Override
Expand Down

0 comments on commit 0784624

Please sign in to comment.