Package: DefaultLayoutFinder
DefaultLayoutFinder
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DefaultLayoutFinder(DefaultLayoutFinder, Object) |
|
|
|
|
|
||||||||||||||||||||
DefaultLayoutFinder(List, Map) |
|
|
|
|
|
||||||||||||||||||||
computeNeededResults() |
|
|
|
|
|
||||||||||||||||||||
withId(Id) |
|
|
|
|
|
Coverage
1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * NorthernWind - lightweight CMS
5: * http://tidalwave.it/projects/northernwind
6: *
7: * Copyright (C) 2011 - 2025 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/northernwind-src
22: * git clone https://github.com/tidalwave-it/northernwind-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.northernwind.frontend.impl.ui;
27:
28: import javax.annotation.Nonnull;
29: import javax.annotation.Nullable;
30: import javax.annotation.concurrent.Immutable;
31: import java.util.ArrayList;
32: import java.util.List;
33: import java.util.Map;
34: import it.tidalwave.util.Id;
35: import it.tidalwave.util.spi.HierarchicFinderSupport;
36: import it.tidalwave.northernwind.frontend.ui.Layout;
37: import it.tidalwave.northernwind.frontend.ui.LayoutFinder;
38: import lombok.AccessLevel;
39: import lombok.RequiredArgsConstructor;
40:
41: /***************************************************************************************************************************************************************
42: *
43: * A default implementation of {@link LayoutFinder}.
44: *
45: * @author Fabrizio Giudici
46: *
47: **************************************************************************************************************************************************************/
48: @Immutable @RequiredArgsConstructor(access = AccessLevel.PRIVATE, staticName = "fields")
49: public class DefaultLayoutFinder extends HierarchicFinderSupport<Layout, LayoutFinder> implements LayoutFinder
50: {
51: private static final long serialVersionUID = 2354576587657345L;
52:
53: @Nonnull
54: private final transient List<Layout> children;
55:
56: @Nonnull
57: private final transient Map<Id, Layout> childrenMapById;
58:
59: @Nullable
60: private final Id id;
61:
62: /***********************************************************************************************************************************************************
63: * Constructor used to create an instance with the given data.
64: *
65: * @param children the list of children
66: * @param childrenMapById the map of children indexed by their id
67: **********************************************************************************************************************************************************/
68: public DefaultLayoutFinder (@Nonnull final List<Layout> children, @Nonnull final Map<Id, Layout> childrenMapById)
69: {
70: this(children, childrenMapById, null);
71: }
72:
73: /***********************************************************************************************************************************************************
74: * Clone constructor. See documentation of {@link HierarchicFinderSupport} for more information.
75: *
76: * @param other the {@code Finder} to clone
77: * @param override the override object
78: **********************************************************************************************************************************************************/
79: // FIXME: should be protected
80: public DefaultLayoutFinder (@Nonnull final DefaultLayoutFinder other, @Nonnull final Object override)
81: {
82: super(other, override);
83: final var source = getSource(DefaultLayoutFinder.class, other, override);
84: this.children = source.children;
85: this.childrenMapById = source.childrenMapById;
86: this.id = source.id;
87: }
88:
89: /***********************************************************************************************************************************************************
90: * {@inheritDoc}
91: **********************************************************************************************************************************************************/
92: @Override @Nonnull
93: public LayoutFinder withId (@Nonnull final Id id)
94: {
95: return clonedWith(fields(children, childrenMapById, id));
96: }
97:
98: /***********************************************************************************************************************************************************
99: * {@inheritDoc}
100: **********************************************************************************************************************************************************/
101: @Override @Nonnull
102: protected List<Layout> computeNeededResults()
103: {
104: final var result = new ArrayList<Layout>();
105:
106:• if (id != null)
107: {
108: final var child = childrenMapById.get(id);
109:
110:• if (child != null)
111: {
112: result.add(child);
113: }
114: }
115: else
116: {
117: result.addAll(children);
118: }
119:
120: return result;
121: }
122: }