Guest User

Untitled

a guest
Jan 12th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. public final class BuilderUtils {
  2.  
  3. private BuilderUtils () {
  4. throw new UnsupportedOperationException("do not call")
  5. }
  6.  
  7. public static <B> List<B> convertBuilderList(List<? extends ModelBuilder<B>> toConvert) {
  8. if (CollectionUtils.isEmpty(toConvert)) {
  9. return Collections.emptyList();
  10. }
  11.  
  12. final List<B> results = new ArrayList<B>(toConvert.size());
  13. for (ModelBuilder<B> elem : toConvert) {
  14. if (elem != null) {
  15. results.add(elem.build());
  16. }
  17. }
  18. return Collections.unmodifiableList(results);
  19. }
  20.  
  21. public static <B> Collection<B> convertBuilderCollection(Collection<? extends ModelBuilder<B>> toConvert) {
  22. if (CollectionUtils.isEmpty(toConvert)) {
  23. return Collections.emptyList();
  24. }
  25.  
  26. final Collection<B> results = new ArrayList<B>(toConvert.size());
  27. for (ModelBuilder<B> elem : toConvert) {
  28. if (elem != null) {
  29. results.add(elem.build());
  30. }
  31. }
  32. return Collections.unmodifiableCollection(results);
  33. }
  34.  
  35. public static <B> Set<B> convertBuilderSet(Collection<? extends ModelBuilder<B>> toConvert) {
  36. if (CollectionUtils.isEmpty(toConvert)) {
  37. return Collections.emptySet();
  38. }
  39.  
  40. final Set<B> results = new HashSet<B>(toConvert.size());
  41. for (ModelBuilder<B> elem : toConvert) {
  42. if (elem != null) {
  43. results.add(elem.build());
  44. }
  45. }
  46. return Collections.unmodifiableSet(results);
  47. }
  48. }
Add Comment
Please, Sign In to add comment