Package: PresentationModelAsDelegateDecorator
PresentationModelAsDelegateDecorator
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
as(Class) |
|
|
|
|
|
||||||||||||||||||||
asMany(Class) |
|
|
|
|
|
||||||||||||||||||||
decorating(PresentationModel, As) |
|
|
|
|
|
||||||||||||||||||||
lambda$as$0(Class) |
|
|
|
|
|
||||||||||||||||||||
maybeAs(Class) |
|
|
|
|
|
Coverage
1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * SteelBlue: DCI User Interfaces
5: * http://tidalwave.it/projects/steelblue
6: *
7: * Copyright (C) 2015 - 2025 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/steelblue-src
22: * git clone https://github.com/tidalwave-it/steelblue-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.ui.javafx.impl.common;
27:
28: import jakarta.annotation.Nonnull;
29: import java.util.ArrayList;
30: import java.util.Collection;
31: import java.util.List;
32: import java.util.Optional;
33: import it.tidalwave.util.As;
34: import it.tidalwave.util.AsException;
35: import it.tidalwave.ui.core.role.PresentationModel;
36: import lombok.AccessLevel;
37: import lombok.RequiredArgsConstructor;
38: import lombok.ToString;
39: import lombok.experimental.Delegate;
40:
41: /***************************************************************************************************************************************************************
42: *
43: * A decorator for {@link PresentationModel} that also searches for roles in a specified delegate as a fallback.
44: *
45: * FIME: move to TFT
46: *
47: * @stereotype Decorator
48: * @author Fabrizio Giudici
49: *
50: **************************************************************************************************************************************************************/
51: @RequiredArgsConstructor(access = AccessLevel.PRIVATE) @ToString
52: public class PresentationModelAsDelegateDecorator implements PresentationModel
53: {
54: @Delegate(excludes = As.class) @Nonnull
55: private final PresentationModel pmDelegate;
56:
57: private final As asDelegate;
58:
59: @Nonnull
60: public static PresentationModel decorating (@Nonnull final PresentationModel pmDelegate,
61: @Nonnull final As asDelegate)
62: {
63: return new PresentationModelAsDelegateDecorator(pmDelegate, asDelegate);
64: }
65:
66: @Override @Nonnull
67: public <T> T as (@Nonnull final Class<? extends T> type)
68: {
69: return maybeAs(type).orElseThrow(() -> new AsException(type));
70: }
71:
72: @Override @Nonnull
73: public <T> Optional<T> maybeAs (@Nonnull Class<? extends T> type)
74: {
75: final Optional<T> t = pmDelegate.maybeAs(type);
76:• return t.isPresent() ? t : asDelegate.maybeAs(type);
77: // .or(() -> (Optional<T>)asDelegate.maybeAs(type));
78: }
79:
80: @Override @Nonnull
81: public <T> Collection<T> asMany (@Nonnull final Class<? extends T> type)
82: {
83: final List<T> results = new ArrayList<>();
84: results.addAll(pmDelegate.asMany(type));
85: results.addAll(asDelegate.asMany(type));
86:
87: return results;
88: }
89: }