Skip to content

Commit

Permalink
JAMES-2637 return streams for getSourcesForType and getMappingsForTyp…
Browse files Browse the repository at this point in the history
…e methods
  • Loading branch information
Arsnael authored and chibenwa committed Jan 16, 2019
1 parent 03ee195 commit dcb093e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
Expand Up @@ -126,13 +126,12 @@ default List<MappingSource> listSources(Mapping mapping) throws RecipientRewrite
.collect(Guavate.toImmutableList());
}

default List<MappingSource> getSourcesForType(Mapping.Type type) throws RecipientRewriteTableException {
default Stream<MappingSource> getSourcesForType(Mapping.Type type) throws RecipientRewriteTableException {
return getAllMappings()
.entrySet().stream()
.filter(e -> e.getValue().contains(type))
.map(Map.Entry::getKey)
.sorted(Comparator.comparing(MappingSource::asMailAddressString))
.collect(Guavate.toImmutableList());
.sorted(Comparator.comparing(MappingSource::asMailAddressString));
}

default Stream<Mapping> getMappingsForType(Mapping.Type type) throws RecipientRewriteTableException {
Expand Down
Expand Up @@ -124,7 +124,7 @@ public Object throwUnknownPath(Request request, Response response) {
message = "Internal server error - Something went bad on the server side.")
})
public List<MappingSource> listForwards(Request request, Response response) throws RecipientRewriteTableException {
return recipientRewriteTable.getSourcesForType(Mapping.Type.Forward);
return recipientRewriteTable.getSourcesForType(Mapping.Type.Forward).collect(Guavate.toImmutableList());
}

@PUT
Expand Down
Expand Up @@ -121,7 +121,7 @@ public void define(Service service) {
message = "Internal server error - Something went bad on the server side.")
})
public List<MappingSource> listGroups(Request request, Response response) throws RecipientRewriteTableException {
return recipientRewriteTable.getSourcesForType(Mapping.Type.Group);
return recipientRewriteTable.getSourcesForType(Mapping.Type.Group).collect(Guavate.toImmutableList());
}

@PUT
Expand Down

0 comments on commit dcb093e

Please sign in to comment.