Skip to content

Package: ConfigurationDecorator

ConfigurationDecorator

nameinstructionbranchcomplexitylinemethod
getDate(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDateTime(String)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getId(String)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getIds(String)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getMoney(String)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getStream(String)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$getStream$0(Object)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

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.importer.ibiz.impl;
27:
28: import javax.annotation.Nonnull;
29: import java.time.LocalDate;
30: import java.time.LocalDateTime;
31: import java.time.ZoneId;
32: import java.util.Date;
33: import java.util.List;
34: import java.util.stream.Stream;
35: import java.math.MathContext;
36: import org.apache.commons.configuration2.Configuration;
37: import it.tidalwave.accounting.model.types.Money;
38: import it.tidalwave.util.Id;
39: import lombok.RequiredArgsConstructor;
40: import lombok.experimental.Delegate;
41: import static java.util.stream.Collectors.*;
42:
43: /***************************************************************************************************************************************************************
44: *
45: * Decorates Apache Commons' {@link Configuration} to provide extra methods for specific data types.
46: *
47: * @author Fabrizio Giudici
48: *
49: **************************************************************************************************************************************************************/
50: @RequiredArgsConstructor
51: public class ConfigurationDecorator implements Configuration
52: {
53: private static final MathContext ROUNDING = new MathContext(6);
54:
55: @Nonnull @Delegate
56: private final Configuration delegate;
57:
58: @Nonnull
59: public Id getId (@Nonnull final String key)
60: {
61: return new Id(delegate.getString(key).replace(":ABPerson", ""));
62: }
63:
64: @Nonnull
65: public Money getMoney (@Nonnull final String key)
66: {
67: return Money.of(delegate.getBigDecimal(key).round(ROUNDING), "EUR");
68: }
69:
70: @Nonnull
71: public LocalDateTime getDateTime (@Nonnull final String key)
72: {
73: return LocalDateTime.ofInstant(((Date)delegate.getProperty(key)).toInstant(), ZoneId.systemDefault());
74: }
75:
76: @Nonnull
77: public LocalDate getDate (@Nonnull final String key)
78: {
79: return getDateTime(key).toLocalDate();
80: }
81:
82: @Nonnull
83: public Stream<ConfigurationDecorator> getStream (@Nonnull final String name)
84: {
85: return delegate.getList(name).stream().map(o -> new ConfigurationDecorator((Configuration)o));
86: }
87:
88: @Nonnull
89: public List<Id> getIds (@Nonnull final String key)
90: {
91: return delegate.getList(key).stream().map(Id::new).collect(toList());
92: }
93: }