Package: TerminalDataManagerPresentation
TerminalDataManagerPresentation
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
TerminalDataManagerPresentation() |
|
|
|
|
|
||||||||||||||||||||
lambda$renderBackup$2(As) |
|
|
|
|
|
||||||||||||||||||||
lambda$renderManagedFile$0(As) |
|
|
|
|
|
||||||||||||||||||||
lambda$renderManagedFile$1(SimpleComposite) |
|
|
|
|
|
||||||||||||||||||||
notifyError(String) |
|
|
|
|
|
||||||||||||||||||||
output(String) |
|
|
|
|
|
||||||||||||||||||||
renderBackup(Pair) |
|
|
|
|
|
||||||||||||||||||||
renderBackups(PresentationModel) |
|
|
|
|
|
||||||||||||||||||||
renderManagedFile(Pair) |
|
|
|
|
|
||||||||||||||||||||
renderManagedFiles(PresentationModel) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: /*
2: * *********************************************************************************************************************
3: *
4: * SolidBlue 3: Data safety
5: * http://tidalwave.it/projects/solidblue3
6: *
7: * Copyright (C) 2023 - 2023 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
12: * the License. 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
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/solidblue3j-src
23: * git clone https://github.com/tidalwave-it/solidblue3j-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.datamanager.application.nogui.impl;
28:
29: import jakarta.annotation.Nonnull;
30: import java.util.function.Consumer;
31: import org.springframework.stereotype.Component;
32: import it.tidalwave.util.As;
33: import it.tidalwave.util.Pair;
34: import it.tidalwave.role.SimpleComposite;
35: import it.tidalwave.role.ui.PresentationModel;
36: import it.tidalwave.datamanager.application.nogui.DataManagerPresentation;
37: import lombok.AllArgsConstructor;
38: import static it.tidalwave.role.ui.Displayable._Displayable_;
39:
40: /***********************************************************************************************************************
41: *
42: * An implementation of {@link DataManagerPresentation} that goes on the terminal.
43: *
44: * @stereotype Presentation
45: * @author Fabrizio Giudici
46: *
47: **********************************************************************************************************************/
48: @Component @AllArgsConstructor
49: public class TerminalDataManagerPresentation implements DataManagerPresentation
50: {
51: private static final As.Type<SimpleComposite<As>> _CompositeOfAs_ = As.type(SimpleComposite.class);
52:
53: private static final As.Type<SimpleComposite<PresentationModel>> _CompositeOfPresentationModel_
54: = As.type(SimpleComposite.class);
55:
56: private final Consumer<String> printer;
57:
58: /*******************************************************************************************************************
59: * {@inheritDoc}
60: ******************************************************************************************************************/
61: public TerminalDataManagerPresentation()
62: {
63: printer = System.out::println;
64: }
65:
66: /*******************************************************************************************************************
67: * {@inheritDoc}
68: ******************************************************************************************************************/
69: @Override
70: public void renderManagedFiles (@Nonnull final PresentationModel pm)
71: {
72: final var s = pm.as(_CompositeOfPresentationModel_).findChildren().stream();
73: Pair.indexedPairStream(s, Pair.BASE_1).forEach(this::renderManagedFile);
74: }
75:
76: /*******************************************************************************************************************
77: * {@inheritDoc}
78: ******************************************************************************************************************/
79: @Override
80: public void renderBackups (@Nonnull final PresentationModel pm)
81: {
82: final var s = pm.as(_CompositeOfPresentationModel_).findChildren().stream();
83: Pair.indexedPairStream(s, Pair.BASE_1).forEach(this::renderBackup);
84: }
85:
86: /*******************************************************************************************************************
87: * {@inheritDoc}
88: ******************************************************************************************************************/
89: @Override
90: public void output (@Nonnull final String string)
91: {
92: printer.accept(string);
93: }
94:
95: /*******************************************************************************************************************
96: * {@inheritDoc}
97: ******************************************************************************************************************/
98: @Override
99: public void notifyError (@Nonnull final String string)
100: {
101: System.err.println(string);
102: }
103:
104: /*******************************************************************************************************************
105: *
106: ******************************************************************************************************************/
107: private void renderManagedFile (@Nonnull final Pair<Integer, ? extends PresentationModel> pair)
108: {
109: final var managedFilePm = pair.b;
110: printer.accept("%05d) %s".formatted(pair.a, managedFilePm.as(_Displayable_).getDisplayName()));
111: managedFilePm.maybeAs(_CompositeOfAs_).ifPresent(c ->
112: c.findChildren().forEach(f -> printer.accept(" " + f.as(_Displayable_).getDisplayName())));
113: }
114:
115: /*******************************************************************************************************************
116: *
117: ******************************************************************************************************************/
118: private void renderBackup (@Nonnull final Pair<Integer, ? extends PresentationModel> pair)
119: {
120: printer.accept("%05d) %s".formatted(pair.a,
121: pair.b.as(_Displayable_).getDisplayName().replace("\n", "\n ")));
122: pair.b.as(_CompositeOfAs_)
123: .findChildren()
124: .forEach(f -> printer.accept(" " + f.as(_Displayable_).getDisplayName()));
125: }
126: }