View Javadoc
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  
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.accounting.model.JobEvent;
33  import it.tidalwave.accounting.model.types.Money;
34  import it.tidalwave.util.As;
35  import it.tidalwave.util.Id;
36  import lombok.EqualsAndHashCode;
37  import lombok.Getter;
38  import lombok.ToString;
39  import lombok.experimental.Delegate;
40  
41  /***************************************************************************************************************************************************************
42   *
43   * This class models a single job event.
44   *
45   * @author  Fabrizio Giudici
46   *
47   **************************************************************************************************************************************************************/
48  @Immutable @EqualsAndHashCode @ToString(exclude = "as")
49  public abstract class InMemoryJobEvent implements JobEvent
50    {
51      @Delegate
52      private final As as = As.forObject(this);
53  
54      @Getter @Nonnull
55      protected final Id id;
56      
57      @Getter @Nonnull
58      protected final String name;
59  
60      @Getter @Nonnull
61      protected final String description;
62  
63      /***********************************************************************************************************************************************************
64       * Creates a new builder.
65       *
66       * @return  the builder
67       **********************************************************************************************************************************************************/
68      @Nonnull
69      public static JobEvent.Builder builder()
70        {
71          return new JobEvent.Builder(); // FIXME: avoid nulls
72        }
73  
74      /***********************************************************************************************************************************************************
75       * Creates a new instance from a builder.
76       *
77       * @param builder   the builder
78       **********************************************************************************************************************************************************/
79      protected InMemoryJobEvent (@Nonnull final Builder builder)
80        {
81          this.id = builder.getId();
82          this.name = builder.getName();
83          this.description = builder.getDescription();
84        }
85      
86      /***********************************************************************************************************************************************************
87       * Returns the datetime of the event.
88       *
89       * @return    the date
90       **********************************************************************************************************************************************************/
91      @Nonnull
92      public abstract LocalDateTime getDateTime(); 
93      
94      /***********************************************************************************************************************************************************
95       * Returns the duration of the event.
96       *
97       * @return    the duration
98       **********************************************************************************************************************************************************/
99      @Nonnull
100     public abstract Duration getDuration(); 
101     
102     /***********************************************************************************************************************************************************
103      * Returns the earnings for the event.
104      *
105      * @return    the earnings
106      **********************************************************************************************************************************************************/
107     @Nonnull
108     public abstract Money getEarnings();
109     
110     /***********************************************************************************************************************************************************
111      * Returns a builder pre-populated with all the attributes.
112      *
113      * @return  the builder
114      **********************************************************************************************************************************************************/
115     @Nonnull
116     public abstract JobEvent.Builder toBuilder();
117   }