Package: DefaultLayoutFinder
DefaultLayoutFinder
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DefaultLayoutFinder(DefaultLayoutFinder, Object) |
|
|
|
|
|
||||||||||||||||||||
DefaultLayoutFinder(List, Map) |
|
|
|
|
|
||||||||||||||||||||
DefaultLayoutFinder(List, Map, Id) |
|
|
|
|
|
||||||||||||||||||||
computeNeededResults() |
|
|
|
|
|
||||||||||||||||||||
fields(List, Map, Id) |
|
|
|
|
|
||||||||||||||||||||
withId(Id) |
|
|
|
|
|
Coverage
1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
7: * %%
8: * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: *
24: * *********************************************************************************************************************
25: * #L%
26: */
27: package it.tidalwave.northernwind.frontend.impl.ui;
28:
29: import javax.annotation.Nonnull;
30: import javax.annotation.Nullable;
31: import javax.annotation.concurrent.Immutable;
32: import java.util.ArrayList;
33: import java.util.List;
34: import java.util.Map;
35: import it.tidalwave.util.Id;
36: import it.tidalwave.util.spi.HierarchicFinderSupport;
37: import it.tidalwave.northernwind.frontend.ui.Layout;
38: import it.tidalwave.northernwind.frontend.ui.LayoutFinder;
39: import lombok.AccessLevel;
40: import lombok.RequiredArgsConstructor;
41:
42: /***********************************************************************************************************************
43: *
44: * A default implementation of {@link LayoutFinder}.
45: *
46: * @author Fabrizio Giudici
47: *
48: **********************************************************************************************************************/
49: @Immutable @RequiredArgsConstructor(access = AccessLevel.PRIVATE, staticName = "fields")
50: public class DefaultLayoutFinder extends HierarchicFinderSupport<Layout, LayoutFinder> implements LayoutFinder
51: {
52: private static final long serialVersionUID = 2354576587657345L;
53:
54: @Nonnull
55: private final transient List<Layout> children;
56:
57: @Nonnull
58: private final transient Map<Id, Layout> childrenMapById;
59:
60: @Nullable
61: private final Id id;
62:
63: /*******************************************************************************************************************
64: *
65: * Constructor used to create an instance with the given data.
66: *
67: * @param children the list of children
68: * @param childrenMapById the map of children indexed by their id
69: *
70: ******************************************************************************************************************/
71: public DefaultLayoutFinder (@Nonnull final List<Layout> children, @Nonnull final Map<Id, Layout> childrenMapById)
72: {
73: this(children, childrenMapById, null);
74: }
75:
76: /*******************************************************************************************************************
77: *
78: * Clone constructor. See documentation of {@link HierarchicFinderSupport} for more information.
79: *
80: * @param other the {@code Finder} to clone
81: * @param override the override object
82: *
83: ******************************************************************************************************************/
84: // FIXME: should be protected
85: public DefaultLayoutFinder (@Nonnull final DefaultLayoutFinder other, @Nonnull final Object override)
86: {
87: super(other, override);
88: final var source = getSource(DefaultLayoutFinder.class, other, override);
89: this.children = source.children;
90: this.childrenMapById = source.childrenMapById;
91: this.id = source.id;
92: }
93:
94: /*******************************************************************************************************************
95: *
96: * {@inheritDoc}
97: *
98: ******************************************************************************************************************/
99: @Override @Nonnull
100: public LayoutFinder withId (@Nonnull final Id id)
101: {
102: return clonedWith(fields(children, childrenMapById, id));
103: }
104:
105: /*******************************************************************************************************************
106: *
107: * {@inheritDoc}
108: *
109: ******************************************************************************************************************/
110: @Override @Nonnull
111: protected List<Layout> computeNeededResults()
112: {
113: final var result = new ArrayList<Layout>();
114:
115:• if (id != null)
116: {
117: final var child = childrenMapById.get(id);
118:
119:• if (child != null)
120: {
121: result.add(child);
122: }
123: }
124: else
125: {
126: result.addAll(children);
127: }
128:
129: return result;
130: }
131: }