InMemoryTimedJobEvent.java

  1. /*
  2.  * #%L
  3.  * *********************************************************************************************************************
  4.  *
  5.  * blueHour
  6.  * http://bluehour.tidalwave.it - git clone git@bitbucket.org:tidalwave/bluehour-src.git
  7.  * %%
  8.  * Copyright (C) 2013 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
  9.  * %%
  10.  * *********************************************************************************************************************
  11.  *
  12.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  13.  * the License. You may obtain a copy of the License at
  14.  *
  15.  *     http://www.apache.org/licenses/LICENSE-2.0
  16.  *
  17.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  18.  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
  19.  * specific language governing permissions and limitations under the License.
  20.  *
  21.  * *********************************************************************************************************************
  22.  *
  23.  *
  24.  * *********************************************************************************************************************
  25.  * #L%
  26.  */
  27. package it.tidalwave.accounting.model.impl;

  28. import javax.annotation.Nonnull;
  29. import javax.annotation.concurrent.Immutable;
  30. import java.util.Collections;
  31. import java.time.Duration;
  32. import java.time.LocalDateTime;
  33. import it.tidalwave.accounting.model.JobEvent;
  34. import it.tidalwave.accounting.model.JobEvent.Builder;
  35. import it.tidalwave.accounting.model.types.Money;
  36. import it.tidalwave.accounting.model.spi.TimedJobEventSpi;
  37. import lombok.EqualsAndHashCode;
  38. import lombok.Getter;
  39. import lombok.ToString;

  40. /***********************************************************************************************************************
  41.  *
  42.  * @author  Fabrizio Giudici
  43.  *
  44.  **********************************************************************************************************************/
  45. @Immutable @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true)
  46. public class InMemoryTimedJobEvent extends InMemoryJobEvent implements TimedJobEventSpi
  47.   {
  48.     @Getter @Nonnull
  49.     private final LocalDateTime startDateTime;

  50.     @Getter @Nonnull
  51.     private final LocalDateTime endDateTime;

  52.     @Getter @Nonnull
  53.     private final Money earnings;

  54.     @Getter @Nonnull
  55.     private final Money hourlyRate;

  56.     /*******************************************************************************************************************
  57.      *
  58.      *
  59.      *
  60.      ******************************************************************************************************************/
  61.     public /* FIXME protected */ InMemoryTimedJobEvent (@Nonnull final Builder builder)
  62.       {
  63.         super(builder);
  64.         this.startDateTime = builder.getStartDateTime();
  65.         this.endDateTime = builder.getEndDateTime();
  66.         this.earnings = builder.getEarnings();
  67.         this.hourlyRate = builder.getHourlyRate();
  68.       }
  69.    
  70.     /*******************************************************************************************************************
  71.      *
  72.      * {@inheritDoc}
  73.      *
  74.      ******************************************************************************************************************/
  75.     @Override @Nonnull
  76.     public JobEvent.Builder toBuilder()
  77.       {
  78.         return new Builder(id, Type.TIMED, startDateTime, endDateTime, name, description,
  79.                            earnings, hourlyRate, Collections.emptyList());
  80.       }
  81.    
  82.     /*******************************************************************************************************************
  83.      *
  84.      * {@inheritDoc}
  85.      *
  86.      ******************************************************************************************************************/
  87.     @Override @Nonnull
  88.     public LocalDateTime getDateTime()
  89.       {
  90.         return startDateTime;
  91.       }

  92.     /*******************************************************************************************************************
  93.      *
  94.      * {@inheritDoc}
  95.      *
  96.      ******************************************************************************************************************/
  97.     @Override @Nonnull
  98.     public Duration getDuration()
  99.       {
  100.         return Duration.between(startDateTime, endDateTime);
  101.       }
  102.   }