nazar_art

return Pair result from a method

Oct 21st, 2020 (edited)
1,062
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public Pair<IotPermission, Boolean> getValidPermissionPair(String qrCode, Entrance entrance) {
  2.     List<IotPermission> allPermissions = permissionRepository.findAllByQrCode(qrCode);
  3.  
  4.     List<IotPermission> permissions = entrance.getEntranceLabel().contains("IN")
  5.             ? Utils.validateEntrancePossibility(allPermissions) : allPermissions;
  6.  
  7.     IotPermission permission = null;
  8.     boolean isCarparkFound = false;
  9.     boolean ifCountShouldBeIncremented = true;
  10.  
  11.     // check valid permission
  12.     Integer carparkId = entrance.getGatewayRef().getCarParkRef().getId();
  13.     for (IotPermission perm : permissions) {
  14.         if (perm.isCarparkValid(carparkId)) {
  15.             log.debug("CARPARK_FOUND");
  16.             isCarparkFound = true;
  17.             permission = perm;
  18.             break;
  19.         }
  20.     }
  21.  
  22.     // check permission for parent carpark -> don't increment counter here
  23.     if (!isCarparkFound) {
  24.         Integer parentCarpark = entrance.getGatewayRef().getCarParkRef().getParentCarParkRef();
  25.         for (IotPermission perm : permissions) {
  26.             if (perm.isCarparkValid(parentCarpark)) {
  27.                 log.debug("PARENT_CARPARK_FOUND");
  28.                 ifCountShouldBeIncremented = false;
  29.                 permission = perm;
  30.                 break;
  31.             }
  32.         }
  33.     }
  34.  
  35.     Pair<IotPermission, Boolean> result = new Pair<>(permission, ifCountShouldBeIncremented);
  36.     log.debug("COUNTER_UPDATE_STATUS: {}; PERMISSION: {}", ifCountShouldBeIncremented, permission);
  37.     return result;
  38. }
  39.  
  40. @Data
  41. @Builder
  42. @NoArgsConstructor
  43. @AllArgsConstructor
  44. public final class Pair<K, V> {
  45.     private K key;
  46.     private V value;
  47. }
RAW Paste Data