Skip to content

Commit

Permalink
change list implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Don Henton committed Jul 3, 2018
1 parent 0499154 commit 9e30f4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class OrdersServiceImpl implements OrdersService {
@Override
public List<Orders> getAllOrders() {

Iterable<Orders> items = ordersRepository.findAll();
Iterable<Orders> items = ordersRepository.findAll();
return EntityUtils.makeCollection(items);
}

Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/dhenton9000/jpa/util/EntityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Spliterator;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

/**
*
Expand All @@ -23,12 +27,12 @@ public static String trimField(String f)
}
}

public static <E> ArrayList<E> makeCollection(Iterable<E> iter) {
ArrayList<E> list = new ArrayList<E>();
for (E item : iter) {
list.add(item);
}
return list;
public static <E> List<E> makeCollection(Iterable<E> iter) {

return StreamSupport.stream(iter.spliterator(),false)
.collect(Collectors.toList());
}

}

0 comments on commit 9e30f4d

Please sign in to comment.