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 java.util.Collections;
33 import it.tidalwave.accounting.model.JobEvent;
34 import it.tidalwave.accounting.model.spi.TimedJobEventSpi;
35 import it.tidalwave.accounting.model.types.Money;
36 import lombok.EqualsAndHashCode;
37 import lombok.Getter;
38 import lombok.ToString;
39
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
51 @Getter @Nonnull
52 private final LocalDateTime endDateTime;
53
54 @Getter @Nonnull
55 private final Money earnings;
56
57 @Getter @Nonnull
58 private final Money hourlyRate;
59
60 /***********************************************************************************************************************************************************
61 *
62 **********************************************************************************************************************************************************/
63 public /* FIXME protected */ InMemoryTimedJobEvent (@Nonnull final Builder builder)
64 {
65 super(builder);
66 this.startDateTime = builder.getStartDateTime();
67 this.endDateTime = builder.getEndDateTime();
68 this.earnings = builder.getEarnings();
69 this.hourlyRate = builder.getHourlyRate();
70 }
71
72 /***********************************************************************************************************************************************************
73 * {@inheritDoc}
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 * {@inheritDoc}
84 **********************************************************************************************************************************************************/
85 @Override @Nonnull
86 public LocalDateTime getDateTime()
87 {
88 return startDateTime;
89 }
90
91 /***********************************************************************************************************************************************************
92 * {@inheritDoc}
93 **********************************************************************************************************************************************************/
94 @Override @Nonnull
95 public Duration getDuration()
96 {
97 return Duration.between(startDateTime, endDateTime);
98 }
99 }