Skip to content

Package: PathAwareMediaFolderDecorator

PathAwareMediaFolderDecorator

nameinstructionbranchcomplexitylinemethod
PathAwareMediaFolderDecorator(Entity, PathAwareEntity, Path)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
PathAwareMediaFolderDecorator(Entity, PathAwareEntity, Path, Collection)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
findChildren()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
lambda$wrappedFinder$0(MediaFolder, Object)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toDumpString()
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
wrappedFinder(MediaFolder, Finder)
M: 3 C: 14
82%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 2
67%
M: 0 C: 1
100%

Coverage

1: /*
2: * *********************************************************************************************************************
3: *
4: * blueMarine II: Semantic Media Centre
5: * http://tidalwave.it/projects/bluemarine2
6: *
7: * Copyright (C) 2015 - 2021 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/bluemarine2-src
23: * git clone https://github.com/tidalwave-it/bluemarine2-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.bluemarine2.model.impl;
28:
29: import javax.annotation.Nonnull;
30: import java.util.Collection;
31: import java.util.Collections;
32: import java.nio.file.Path;
33: import it.tidalwave.util.Finder;
34: import it.tidalwave.util.MappingFinder;
35: import it.tidalwave.role.SimpleComposite;
36: import it.tidalwave.bluemarine2.model.MediaFolder;
37: import it.tidalwave.bluemarine2.model.spi.Entity;
38: import it.tidalwave.bluemarine2.model.spi.PathAwareEntity;
39: import it.tidalwave.bluemarine2.model.spi.PathAwareFinder;
40:
41: /***********************************************************************************************************************
42: *
43: * @author Fabrizio Giudici
44: *
45: **********************************************************************************************************************/
46: public class PathAwareMediaFolderDecorator extends PathAwareEntityDecorator implements MediaFolder
47: {
48: /*******************************************************************************************************************
49: *
50: * Default constructor.
51: *
52: * @param delegate the delegate
53: * @param parent the parent
54: * @param pathSegment the path segment of this object
55: * @param additionalRoles some additional roles
56: *
57: ******************************************************************************************************************/
58: public PathAwareMediaFolderDecorator (@Nonnull final Entity delegate,
59: @Nonnull final PathAwareEntity parent,
60: @Nonnull final Path pathSegment,
61: @Nonnull final Collection<Object> additionalRoles)
62: {
63: super(delegate, parent, pathSegment, additionalRoles);
64: }
65:
66: public PathAwareMediaFolderDecorator (@Nonnull final Entity delegate,
67: @Nonnull final PathAwareEntity parent,
68: @Nonnull final Path pathSegment)
69: {
70: this(delegate, parent, pathSegment, Collections.emptyList());
71: }
72:
73: /*******************************************************************************************************************
74: *
75: * {@inheritDoc}
76: *
77: ******************************************************************************************************************/
78: @Override @Nonnull
79: public PathAwareFinder findChildren()
80: {
81: final SimpleComposite<Entity> composite = delegate.as(SimpleComposite.class);
82: return wrappedFinder(this, composite.findChildren());
83: }
84:
85: /*******************************************************************************************************************
86: *
87: * {@inheritDoc}
88: *
89: ******************************************************************************************************************/
90: @Override @Nonnull
91: public String toDumpString()
92: {
93: return String.format("Folder(path=%s, parent=Folder(path=%s))", getPath(), parent.getPath());
94: }
95:
96: /*******************************************************************************************************************
97: *
98: * Creates a wrapped finder, that wraps all entities in its result.
99: *
100: * @param parent the parent
101: * @param finder the source finder
102: * @return the wrapped finder
103: *
104: ******************************************************************************************************************/
105: @Nonnull
106: private static PathAwareFinder wrappedFinder (@Nonnull final MediaFolder parent,
107: @Nonnull final Finder<? extends Entity> finder)
108: {
109:• if (finder instanceof PathAwareEntityFinderDelegate)
110: {
111: return (PathAwareFinder)finder;
112: }
113:
114: return new PathAwareEntityFinderDelegate(parent,
115: new MappingFinder<>((Finder)finder, child -> wrappedEntity(parent, (Entity)child)));
116: }
117: }