Skip to content

Method: getNames()

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