Skip to content

Package: Aggregate

Aggregate

nameinstructionbranchcomplexitylinemethod
getNames()
M: 2 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: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
of(Map)
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%
of(String, Object)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
with(String, Object)
M: 7 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 - 2025 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 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/thesefoolishthings-src
22: * git clone https://github.com/tidalwave-it/thesefoolishthings-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.role;
27:
28: import jakarta.annotation.Nonnull;
29: import java.util.Collections;
30: import java.util.Map;
31: import java.util.Optional;
32: import java.util.Set;
33: import it.tidalwave.role.impl.MapAggregate;
34:
35: /***************************************************************************************************************************************************************
36: *
37: * The role of an aggregate object, that is an object which contains other named objects.
38: *
39: * @stereotype Role
40: *
41: * @author Fabrizio Giudici
42: *
43: **************************************************************************************************************************************************************/
44: @FunctionalInterface
45: public interface Aggregate<T>
46: {
47: /** Shortcut for {@link it.tidalwave.util.As}. */
48: public static final Class<Aggregate> _Aggregate_ = Aggregate.class;
49:
50: /***********************************************************************************************************************************************************
51: * Returns an object given its name.
52: * @param name the name
53: * @return the object
54: **********************************************************************************************************************************************************/
55: @Nonnull
56: public Optional<T> getByName (@Nonnull String name);
57:
58: /***********************************************************************************************************************************************************
59: * Returns the names of contained objects.
60: * @return the names of the objects
61: * @since 3.1-ALPHA-8
62: **********************************************************************************************************************************************************/
63: @Nonnull
64: public default Set<String> getNames()
65: {
66: return Collections.emptySet();
67: }
68:
69: /***********************************************************************************************************************************************************
70: * Returns a new instance with the specified (name, value) pairs.
71: * @param <T> the static type of the value
72: * @param mapByName the map containing the pairs
73: * @return the new instance
74: * @since 3.2-ALPHA-1
75: **********************************************************************************************************************************************************/
76: @Nonnull
77: public static <T> Aggregate<T> of (@Nonnull final Map<String, T> mapByName)
78: {
79: return new MapAggregate<>(mapByName);
80: }
81:
82: /***********************************************************************************************************************************************************
83: * Returns a new empty instance that will be populated by means of {@link #with(String, Object)}.
84: * @param <T> the static type of the aggregate
85: * @return the new instance
86: * @since 3.2-ALPHA-2
87: **********************************************************************************************************************************************************/
88: @Nonnull
89: public static <T> Aggregate<T> newInstance()
90: {
91: return new MapAggregate<>();
92: }
93:
94: /***********************************************************************************************************************************************************
95: * Returns a new instance with the specified (name, value) pair.
96: * @param <T> the static type of the aggregate
97: * @param name the name in the pair
98: * @param value the value in the pair
99: * @return the new instance
100: * @since 3.2-ALPHA-1
101: **********************************************************************************************************************************************************/
102: @Nonnull
103: public static <T> Aggregate<T> of (@Nonnull final String name, @Nonnull final T value)
104: {
105: return new MapAggregate<T>().with(name, value);
106: }
107:
108: /***********************************************************************************************************************************************************
109: * Returns a new instance with the specified (name, value) pair.
110: * @param name the name in the pair
111: * @param value the value in the pair
112: * @return the new instance
113: * @since 3.2-ALPHA-1
114: **********************************************************************************************************************************************************/
115: @Nonnull
116: public default Aggregate<T> with (@Nonnull final String name, @Nonnull final T value)
117: {
118: return new MapAggregate<T>().with(name, value);
119: }
120: }