コード例 #1
0
 /**
  * Transforms a {@link PtuFlexOffer} to its corresponding DTO object.
  *
  * @param ptuFlexOffer {@link PtuFlexOffer} database object.
  * @return a {@link PtuFlexOfferDto} DTO object.
  */
 public static PtuFlexOfferDto transformPtuFlexOffer(PtuFlexOffer ptuFlexOffer) {
   if (ptuFlexOffer == null) {
     return null;
   }
   PtuFlexOfferDto ptuFlexOfferDto = new PtuFlexOfferDto();
   ptuFlexOfferDto.setPower(ptuFlexOffer.getPower());
   ptuFlexOfferDto.setPrice(ptuFlexOffer.getPrice());
   ptuFlexOfferDto.setPtuIndex(BigInteger.valueOf(ptuFlexOffer.getPtuContainer().getPtuIndex()));
   return ptuFlexOfferDto;
 }
 private void max100PercentOfOriginalPower(
     PtuFlexRequestDto ptuFlexRequestDto, PtuFlexOfferDto ptuFlexOfferDto) {
   BigDecimal percentage = BigDecimal.valueOf(Math.abs(new Random().nextDouble() % 1));
   // Offer up to 0% of the requested power and max 100%
   ptuFlexOfferDto.setPower(
       percentage
           .multiply(new BigDecimal(ptuFlexRequestDto.getPower()), MathContext.DECIMAL64)
           .toBigInteger());
   ptuFlexOfferDto.setPrice(
       BigDecimal.valueOf(0.4)
           .multiply(new BigDecimal(ptuFlexOfferDto.getPower()), MathContext.DECIMAL64));
 }
 private void populateFlexOfferDto(
     FlexOfferDto flexOfferDto, FlexRequestDto flexRequestDto, boolean populatePtus) {
   flexOfferDto.setPeriod(flexRequestDto.getPeriod());
   flexOfferDto.setConnectionGroupEntityAddress(flexRequestDto.getConnectionGroupEntityAddress());
   flexOfferDto.setParticipantDomain(flexRequestDto.getParticipantDomain());
   if (populatePtus) {
     flexRequestDto
         .getPtus()
         .stream()
         .forEach(
             ptuFlexRequestDto -> {
               PtuFlexOfferDto ptuFlexOfferDto = new PtuFlexOfferDto();
               ptuFlexOfferDto.setPtuIndex(ptuFlexRequestDto.getPtuIndex());
               if (ptuFlexRequestDto.getDisposition() == DispositionTypeDto.AVAILABLE) {
                 ptuFlexOfferDto.setPrice(BigDecimal.ZERO);
                 ptuFlexOfferDto.setPower(BigInteger.ZERO);
               } else {
                 max100PercentOfOriginalPower(ptuFlexRequestDto, ptuFlexOfferDto);
               }
               flexOfferDto.getPtus().add(ptuFlexOfferDto);
             });
   }
 }