Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // debug is never used.
- // Wouldn't have been better to use and return a checked List interface instead of uncheck implementations ?
- // Are we sure we return the OFFLINE user devices here ?
- public LinkedList getOfflineDevicesForUser(User user, boolean debug) {
- // Why not using the LinkedList implementation directly ?
- ArrayList l = new ArrayList();
- // Why to use an unchecked List instead of List<Device> ?
- // Isn't there any conventions to use the i, j, k suite for counter variables instead of x, y, z ?
- // Couldn't we replace that block with a: for each / if ? removing the need of the found variable.
- List allDevices = deviceRepository.getAll();
- for (int x=0; x<allDevices.size();x++) {
- // Why a primitive should be initialized to its default value ?
- boolean found = false;
- // Why to use an unchecked List instead of either List<User> or List<Owner> and then cast it down to List<User> ?
- List owners = ((Device) allDevices.get(x)).getOwners();
- if (owners.size() > 0) {
- for (int y = 0; y < owners.size(); y++) {
- User owner = (User) owners.get(x);
- found = (owner == user);
- }
- if (found && allDevices != null)
- l.add(allDevices.get(x));
- }
- }
- return new LinkedList(l);
- //What do you think about something like this ?
- /*
- public List<Device> getOfflineDevicesForUser(User user) {
- List<Device> userOffLineDevices = new LinkedList<Device>();
- for (Device device : deviceRepository.getAll()) {
- List<User> owners = (List<User>)(List<?>) device.getOwners();
- // TODO: Also check the device is offline ?
- if (owners.contains(user)) {
- userOffLineDevices.add(device);
- }
- }
- return userOffLineDevices;
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement