Skip to content

Package: PresentationModelAggregate

PresentationModelAggregate

nameinstructionbranchcomplexitylinemethod
getByName(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%
getNames()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
newInstance()
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%
withPmOf(String, Collection)
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%

Coverage

1: /*
2: * *********************************************************************************************************************
3: *
4: * TheseFoolishThings: Miscellaneous utilities
5: * http://tidalwave.it/projects/thesefoolishthings
6: *
7: * Copyright (C) 2009 - 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
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/thesefoolishthings-src
23: * git clone https://github.com/tidalwave-it/thesefoolishthings-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.role.ui;
28:
29: import javax.annotation.Nonnull;
30: import java.util.Collection;
31: import java.util.Optional;
32: import java.util.Set;
33: import it.tidalwave.role.Aggregate;
34: import lombok.AccessLevel;
35: import lombok.RequiredArgsConstructor;
36: import lombok.ToString;
37:
38: /***********************************************************************************************************************
39: *
40: * A specialisation of {@link Aggregate}{@code <PresentationModel>} which offers a convenience method for aggregating
41: * its contained objects.
42: *
43: * @author Fabrizio Giudici
44: * @since 3.2-ALPHA-3
45: *
46: **********************************************************************************************************************/
47: @RequiredArgsConstructor(access = AccessLevel.PRIVATE) @ToString
48: public class PresentationModelAggregate implements Aggregate<PresentationModel>
49: {
50: @Nonnull
51: private final Aggregate<PresentationModel> delegate;
52:
53: /*******************************************************************************************************************
54: *
55: * Creates a new, empty instance.
56: *
57: * @return the new instance
58: *
59: ******************************************************************************************************************/
60: @Nonnull
61: public static PresentationModelAggregate newInstance()
62: {
63: return new PresentationModelAggregate(Aggregate.newInstance());
64: }
65:
66: /*******************************************************************************************************************
67: *
68: * Adds another {@link PresentationModel} with the given roles, associated to the given name. With a plain
69: * {@link Aggregate}{@code <PresentationModel>} the code would be:
70: *
71: * <pre>
72: * Aggregate<PresentationModel> aggregate = Aggregate.newInstance()
73: * .with("name", PresentationModel.of("", r(role1, role2, role3));
74: * </pre>
75: *
76: * The simplified code is:
77: *
78: * <pre>
79: * Aggregate<PresentationModel> aggregate = PresentationModelAggregate.newInstance()
80: * .withPmOf("name", r(role1, role2, role3));
81: * </pre>
82: *
83: * @param name the name of the {@code PresentationModel}
84: * @param roles the roles
85: * @return the new {@code PresentationModel}
86: *
87: ******************************************************************************************************************/
88: @Nonnull
89: public PresentationModelAggregate withPmOf (@Nonnull final String name, @Nonnull final Collection<Object> roles)
90: {
91: return new PresentationModelAggregate(delegate.with(name, PresentationModel.of("", roles)));
92: }
93:
94: /*******************************************************************************************************************
95: *
96: * {@inheritDoc}
97: *
98: ******************************************************************************************************************/
99: @Override @Nonnull
100: public Optional<PresentationModel> getByName (@Nonnull final String name)
101: {
102: return delegate.getByName(name);
103: }
104:
105: /*******************************************************************************************************************
106: *
107: * {@inheritDoc}
108: *
109: ******************************************************************************************************************/
110: @Override @Nonnull
111: public Set<String> getNames()
112: {
113: return delegate.getNames();
114: }
115: }