ReservationSystemUtil { public static List<ReservationAllocationState> convertAllocationsToReservationInfo(Set<ReservationAllocation> res, boolean includeResourceAllocations) { List<ReservationAllocationState> reservationInfo = new ArrayList<>(); Map<ReservationInterval, Resource> requests; for (ReservationAllocation allocation : res) { List<ResourceAllocationRequest> allocations = new ArrayList<>(); if (includeResourceAllocations) { requests = allocation.getAllocationRequests(); for (Map.Entry<ReservationInterval, Resource> request : requests.entrySet()) { ReservationInterval interval = request.getKey(); allocations.add(ResourceAllocationRequest.newInstance( interval.getStartTime(), interval.getEndTime(), request.getValue())); } } reservationInfo.add(ReservationAllocationState.newInstance( allocation.getAcceptanceTime(), allocation.getUser(), allocations, allocation.getReservationId(), allocation.getReservationDefinition())); } return reservationInfo; } private  ReservationSystemUtil(); static Resource toResource(ReservationRequest request); static Map<ReservationInterval, Resource> toResources(
      Map<ReservationInterval, ReservationRequest> allocations); static ReservationAllocationStateProto buildStateProto(
      ReservationAllocation allocation); static ResourceProto convertToProtoFormat(Resource e); static Map<ReservationInterval, Resource> toAllocations(
      List<ResourceAllocationRequestProto> allocationRequestsList); static ReservationDefinitionPBImpl convertFromProtoFormat(
      ReservationDefinitionProto r); static ReservationIdPBImpl convertFromProtoFormat(
      ReservationIdProto r); static ReservationId toReservationId(
      ReservationIdProto reservationId); static InMemoryReservationAllocation toInMemoryAllocation(
          String planName, ReservationId reservationId,
          ReservationAllocationStateProto allocationState, Resource minAlloc,
          ResourceCalculator planResourceCalculator); static List<ReservationAllocationState> convertAllocationsToReservationInfo(Set<ReservationAllocation> res,
                        boolean includeResourceAllocations);  }
@Test public void testConvertAllocationsToReservationInfo() { long startTime = new Date().getTime(); long step = 10000; int[] alloc = {10, 10, 10}; ReservationId id = ReservationSystemTestUtil.getNewReservationId(); ReservationAllocation allocation = createReservationAllocation( startTime, startTime + 10 * step, step, alloc, id, createResource(4000, 2)); List<ReservationAllocationState> infoList = ReservationSystemUtil .convertAllocationsToReservationInfo( Collections.singleton(allocation), true); Assert.assertEquals(infoList.size(), 1); Assert.assertEquals(infoList.get(0).getReservationId().toString(), id.toString()); Assert.assertFalse(infoList.get(0).getResourceAllocationRequests() .isEmpty()); }
@Test public void testConvertAllocationsToReservationInfoEmptySet() { List<ReservationAllocationState> infoList = ReservationSystemUtil .convertAllocationsToReservationInfo( Collections.<ReservationAllocation>emptySet(), false); Assert.assertEquals(infoList.size(), 0); }