InMemoryJobEvent.java

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

  27. import javax.annotation.Nonnull;
  28. import javax.annotation.concurrent.Immutable;
  29. import java.time.Duration;
  30. import java.time.LocalDateTime;
  31. import it.tidalwave.accounting.model.JobEvent;
  32. import it.tidalwave.accounting.model.types.Money;
  33. import it.tidalwave.util.As;
  34. import it.tidalwave.util.Id;
  35. import lombok.EqualsAndHashCode;
  36. import lombok.Getter;
  37. import lombok.ToString;
  38. import lombok.experimental.Delegate;

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

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

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

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

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