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