InMemoryJobEvent.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.time.Duration;
  31. import java.time.LocalDateTime;
  32. import it.tidalwave.util.As;
  33. import it.tidalwave.util.Id;
  34. import it.tidalwave.accounting.model.JobEvent;
  35. import it.tidalwave.accounting.model.types.Money;
  36. import lombok.experimental.Delegate;
  37. import lombok.EqualsAndHashCode;
  38. import lombok.Getter;
  39. import lombok.ToString;

  40. /***********************************************************************************************************************
  41.  *
  42.  * This class models a single job event.
  43.  *
  44.  * @author  Fabrizio Giudici
  45.  *
  46.  **********************************************************************************************************************/
  47. @Immutable @EqualsAndHashCode @ToString(exclude = "as")
  48. public abstract class InMemoryJobEvent implements JobEvent
  49.   {
  50.     @Delegate
  51.     private final As as = As.forObject(this);

  52.     @Getter @Nonnull
  53.     protected final Id id;
  54.    
  55.     @Getter @Nonnull
  56.     protected final String name;

  57.     @Getter @Nonnull
  58.     protected final String description;

  59.     /*******************************************************************************************************************
  60.      *
  61.      * Creates a new builder.
  62.      *
  63.      * @return  the builder
  64.      *
  65.      ******************************************************************************************************************/
  66.     @Nonnull
  67.     public static JobEvent.Builder builder()
  68.       {
  69.         return new JobEvent.Builder(); // FIXME: avoid nulls
  70.       }

  71.     /*******************************************************************************************************************
  72.      *
  73.      * Creates a new instance from a builder.
  74.      *
  75.      * @param builder   the builder
  76.      *
  77.      ******************************************************************************************************************/
  78.     protected InMemoryJobEvent (@Nonnull final Builder builder)
  79.       {
  80.         this.id = builder.getId();
  81.         this.name = builder.getName();
  82.         this.description = builder.getDescription();
  83.       }
  84.    
  85.     /*******************************************************************************************************************
  86.      *
  87.      * Returns the datetime of the event.
  88.      *
  89.      * @return    the date
  90.      *
  91.      ******************************************************************************************************************/
  92.     @Nonnull
  93.     public abstract LocalDateTime getDateTime();
  94.    
  95.     /*******************************************************************************************************************
  96.      *
  97.      * Returns the duration of the event.
  98.      *
  99.      * @return    the duration
  100.      *
  101.      ******************************************************************************************************************/
  102.     @Nonnull
  103.     public abstract Duration getDuration();
  104.    
  105.     /*******************************************************************************************************************
  106.      *
  107.      * Returns the earnings for the event.
  108.      *
  109.      * @return    the earnings
  110.      *
  111.      ******************************************************************************************************************/
  112.     @Nonnull
  113.     public abstract Money getEarnings();
  114.    
  115.     /*******************************************************************************************************************
  116.      *
  117.      * Returns a builder pre-populated with all the attributes.
  118.      *
  119.      * @return  the builder
  120.      *
  121.      ******************************************************************************************************************/
  122.     @Nonnull
  123.     public abstract JobEvent.Builder toBuilder();
  124.   }