Package: FinderWithIdMapSupport
FinderWithIdMapSupport
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FinderWithIdMapSupport() |
|
|
|
|
|
||||||||||||||||||||
FinderWithIdMapSupport(FinderWithIdMapSupport, Object) |
|
|
|
|
|
||||||||||||||||||||
findAll() |
|
|
|
|
|
||||||||||||||||||||
findById(Id) |
|
|
|
|
|
Coverage
1: /*
2: * *********************************************************************************************************************
3: *
4: * TheseFoolishThings: Miscellaneous utilities
5: * http://tidalwave.it/projects/thesefoolishthings
6: *
7: * Copyright (C) 2009 - 2024 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.util.spi;
28:
29: import javax.annotation.Nonnull;
30: import java.util.ArrayList;
31: import java.util.Collections;
32: import java.util.HashMap;
33: import java.util.List;
34: import java.util.Map;
35: import java.util.Optional;
36: import it.tidalwave.util.Id;
37: import lombok.RequiredArgsConstructor;
38:
39: /***********************************************************************************************************************
40: *
41: * An implementation of {@link FinderWithIdSupport} based on a {@link Map}.
42: *
43: * @param <T> the product abstract type
44: * @param <I> the product concrete type
45: * @param <F> the {@code Finder} type
46: * @since 3.2-ALPHA-15
47: *
48: * @author Fabrizio Giudici
49: * @it.tidalwave.javadoc.experimental
50: *
51: **********************************************************************************************************************/
52: @RequiredArgsConstructor
53: public class FinderWithIdMapSupport<T, I extends T, F extends ExtendedFinderSupport<T, F>>
54: extends FinderWithIdSupport<T, I, F>
55: {
56: private static final long serialVersionUID = 1L;
57:
58: @Nonnull
59: private final Map<Id, I> mapById;
60:
61: public FinderWithIdMapSupport()
62: {
63: mapById = Collections.emptyMap();
64: }
65:
66: public FinderWithIdMapSupport (@Nonnull final FinderWithIdMapSupport<T, I, F> other,
67: @Nonnull final Object override)
68: {
69: super(other, override);
70: final FinderWithIdMapSupport<T, I, F> source = getSource(FinderWithIdMapSupport.class, other, override);
71: mapById = new HashMap<>(source.mapById);
72: }
73:
74: @Override @Nonnull
75: protected List<T> findAll()
76: {
77: return new ArrayList<>(mapById.values());
78: }
79:
80: @Override @Nonnull
81: protected Optional<T> findById (@Nonnull final Id id)
82: {
83: return Optional.ofNullable(mapById.get(id));
84: }
85: }
86: