Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. // debug is never used.
  2. // Wouldn't have been better to use and return a checked List interface instead of uncheck implementations ?
  3. // Are we sure we return the OFFLINE user devices here ?
  4. public LinkedList getOfflineDevicesForUser(User user, boolean debug) {
  5.  
  6. // Why not using the LinkedList implementation directly ?
  7. ArrayList l = new ArrayList();
  8.  
  9. // Why to use an unchecked List instead of List<Device> ?
  10. // Isn't there any conventions to use the i, j, k suite for counter variables instead of x, y, z ?
  11. // Couldn't we replace that block with a: for each / if ? removing the need of the found variable.
  12. List allDevices = deviceRepository.getAll();
  13.  
  14. for (int x=0; x<allDevices.size();x++) {
  15.  
  16. // Why a primitive should be initialized to its default value ?
  17. boolean found = false;
  18.  
  19. // Why to use an unchecked List instead of either List<User> or List<Owner> and then cast it down to List<User> ?
  20. List owners = ((Device) allDevices.get(x)).getOwners();
  21.  
  22. if (owners.size() > 0) {
  23.  
  24. for (int y = 0; y < owners.size(); y++) {
  25.  
  26. User owner = (User) owners.get(x);
  27.  
  28. found = (owner == user);
  29.  
  30. }
  31.  
  32. if (found && allDevices != null)
  33.  
  34. l.add(allDevices.get(x));
  35.  
  36. }
  37.  
  38. }
  39.  
  40. return new LinkedList(l);
  41.  
  42. //What do you think about something like this ?
  43.  
  44. /*
  45. public List<Device> getOfflineDevicesForUser(User user) {
  46. List<Device> userOffLineDevices = new LinkedList<Device>();
  47.  
  48. for (Device device : deviceRepository.getAll()) {
  49. List<User> owners = (List<User>)(List<?>) device.getOwners();
  50.  
  51. // TODO: Also check the device is offline ?
  52. if (owners.contains(user)) {
  53. userOffLineDevices.add(device);
  54. }
  55. }
  56.  
  57. return userOffLineDevices;
  58. }
  59. */
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement