Skip to content

Package: SimpleAsDelegateProvider$1

SimpleAsDelegateProvider$1

nameinstructionbranchcomplexitylinemethod
as(Class)
M: 1 C: 24
96%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 2
67%
M: 0 C: 1
100%
{...}
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

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.thesefoolishthings.examples.jpafinderexample;
28:
29: import javax.annotation.Nonnull;
30: import java.util.Arrays;
31: import java.util.Collection;
32: import java.util.Collections;
33: import java.util.List;
34: import it.tidalwave.util.spi.AsDelegate;
35: import it.tidalwave.util.spi.AsDelegateProvider;
36: import it.tidalwave.role.Removable;
37: import it.tidalwave.role.io.Persistable;
38: import it.tidalwave.thesefoolishthings.examples.jpafinderexample.impl.PersonJpaPersistable;
39: import it.tidalwave.thesefoolishthings.examples.jpafinderexample.role.Findable;
40: import it.tidalwave.thesefoolishthings.examples.person.Person;
41:
42: /***********************************************************************************************************************
43: *
44: * This example doesn't use Spring integration, so we provide a simple quick-n-dirty {@code AsDelegateProvider} that
45: * finds the unique role available. This class is instantiated by {@code META-INF/services}.
46: *
47: * @author Fabrizio Giudici
48: *
49: **********************************************************************************************************************/
50: public class SimpleAsDelegateProvider implements AsDelegateProvider
51: {
52: private static final List<Class<?>> ROLES = Arrays.asList(Persistable.class, Removable.class, Findable.class);
53:
54: @Override @Nonnull
55: public AsDelegate createAsDelegate (@Nonnull final Object datum)
56: {
57: return new AsDelegate()
58: {
59: @Nonnull @Override
60: public <T> Collection<? extends T> as (@Nonnull final Class<T> roleType)
61: {
62:• return ((datum instanceof Person) && ROLES.contains(roleType))
63: ? Arrays.asList(roleType.cast(new PersonJpaPersistable((Person)datum)))
64: : Collections.emptyList();
65: }
66: };
67: }
68: }