Map<String, Map<Long, Long>> getOverallRequirements(Collection<DiskSpaceRequirements> requirementsList) {
    Map<String, Map<Long, Long>> overallRequirements = new HashMap<>();
    Map<Long, Long> swapSegmentsUsed = new HashMap<>();
    Map<Long, Long> swapSegmentsRequired = new HashMap<>();

    for (DiskSpaceRequirements requirements : requirementsList) {
      long segmentSizeInBytes = requirements.getSegmentSizeInBytes();
      String storeId = requirements.getStoreId();
      Map<Long, Long> storeSegmentRequirements = new HashMap<>();
      storeSegmentRequirements.put(segmentSizeInBytes, requirements.getSegmentsNeeded());
      overallRequirements.put(storeId, storeSegmentRequirements);
      swapSegmentsUsed.put(segmentSizeInBytes,
          swapSegmentsUsed.getOrDefault(segmentSizeInBytes, 0L) + requirements.getSwapSegmentsInUse());
    }
    for (Map.Entry<Long, Long> sizeAndSwapSegments : swapSegmentsUsed.entrySet()) {
      long sizeInBytes = sizeAndSwapSegments.getKey();
      long existingSegmentsNum = swapSegmentNumBySize.getOrDefault(sizeInBytes, 0L);
      long swapSegmentsNeededNum =
          Math.max(requiredSwapSegmentsPerSize - swapSegmentsUsed.get(sizeInBytes) - existingSegmentsNum, 0L);
      // Update swapSegmentNumBySize map by adding up existing segments, segments in use and segments needed
      // During server startup, existing segments = 0;
      // During new store addition, segments in use = 0;
      swapSegmentNumBySize.put(sizeInBytes,
          existingSegmentsNum + swapSegmentsUsed.get(sizeInBytes) + swapSegmentsNeededNum);
      swapSegmentsRequired.put(sizeInBytes, swapSegmentsNeededNum);
    }
    overallRequirements.put(SWAP_DIR_NAME, swapSegmentsRequired);
    return Collections.unmodifiableMap(overallRequirements);
  }
Iterates over the provided requirements and creates a map that describes the number of segments that need to be in
the pool for each segment size.
@param requirementsList the collection of {@link DiskSpaceRequirements} objects to be accumulated
@return a {@link Map} from segment sizes to the number of reserve segments needed at that size.
ambry-store/src/main/java/com/github/ambry/store/DiskSpaceAllocator.java