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.LocalDate;
32 import java.time.LocalDateTime;
33 import java.util.Collections;
34 import it.tidalwave.accounting.model.JobEvent;
35 import it.tidalwave.accounting.model.spi.FlatJobEventSpi;
36 import it.tidalwave.accounting.model.types.Money;
37 import lombok.EqualsAndHashCode;
38 import lombok.Getter;
39 import lombok.ToString;
40
41 /***************************************************************************************************************************************************************
42 *
43 * @author Fabrizio Giudici
44 *
45 **************************************************************************************************************************************************************/
46 @Immutable @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true)
47 public class InMemoryFlatJobEvent extends InMemoryJobEvent implements FlatJobEventSpi
48 {
49 @Getter @Nonnull
50 private final LocalDate date;
51
52 @Getter @Nonnull
53 private final Money earnings;
54
55 /***********************************************************************************************************************************************************
56 *
57 **********************************************************************************************************************************************************/
58 public /* FIXME protected */ InMemoryFlatJobEvent (@Nonnull final Builder builder)
59 {
60 super(builder);
61 this.date = builder.getStartDateTime().toLocalDate();
62 this.earnings = builder.getEarnings();
63 }
64
65 /***********************************************************************************************************************************************************
66 * {@inheritDoc}
67 **********************************************************************************************************************************************************/
68 @Override @Nonnull
69 public JobEvent.Builder toBuilder()
70 {
71 return new Builder(id, Type.FLAT, date.atStartOfDay(), null,
72 name, description, earnings, null, Collections.emptyList());
73 }
74
75 /***********************************************************************************************************************************************************
76 * {@inheritDoc}
77 **********************************************************************************************************************************************************/
78 @Override @Nonnull
79 public LocalDateTime getDateTime()
80 {
81 return date.atStartOfDay();
82 }
83
84 /***********************************************************************************************************************************************************
85 * {@inheritDoc}
86 **********************************************************************************************************************************************************/
87 @Override @Nonnull
88 public Duration getDuration()
89 {
90 return Duration.ZERO;
91 }
92 }