Skip to content

Package: EntitySelectedEvent

EntitySelectedEvent

nameinstructionbranchcomplexitylinemethod
getEntity(Class)
M: 1 C: 14
93%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 1
100%
M: 0 C: 1
100%
of(FileEntity, Class, Supplier)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
of(MimeType, Class, Supplier)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toString()
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%

Coverage

1: package it.tidalwave.dam.ui.message;
2:
3: import jakarta.annotation.Nonnull;
4: import java.util.Optional;
5: import java.util.function.Supplier;
6: import it.tidalwave.dam.model.Entity;
7: import it.tidalwave.dam.model.MimeType;
8: import it.tidalwave.dam.model.io.FileEntity;
9: import lombok.Getter;
10: import lombok.RequiredArgsConstructor;
11: import static lombok.AccessLevel.PROTECTED;
12:
13: /***************************************************************************************************************************************************************
14: *
15: * A message that notifies that an {@link Entity} has been selected.
16: *
17: * @stereotype Message
18: * @author Fabrizio Giudici
19: *
20: **************************************************************************************************************************************************************/
21: @RequiredArgsConstructor(access = PROTECTED) @Getter
22: public class EntitySelectedEvent
23: {
24: @Nonnull
25: private final MimeType mimeType;
26:
27: @Getter @Nonnull
28: private final Class<? extends Entity> entityType;
29:
30: @Nonnull
31: private final Supplier<? extends Entity> entitySupplier;
32:
33: @Nonnull
34: public static <T extends Entity> EntitySelectedEvent of (@Nonnull final MimeType mimeType,
35: @Nonnull final Class<T> entityType,
36: @Nonnull final Supplier<T> entitySupplier)
37: {
38: return new EntitySelectedEvent(mimeType, entityType, entitySupplier);
39: }
40:
41: @Nonnull
42: public static <T extends Entity> EntitySelectedEvent of (@Nonnull final FileEntity file,
43: @Nonnull final Class<T> entityType,
44: @Nonnull final Supplier<T> entitySupplier)
45: {
46: return of(file.getMimeType().orElseThrow(), entityType, entitySupplier);
47: }
48:
49: @Nonnull
50: public final <T extends Entity> Optional<T> getEntity (@Nonnull final Class<T> type)
51: {
52:• return getEntityType().isAssignableFrom(type) ? Optional.of(type.cast(entitySupplier.get())) : Optional.empty();
53: }
54:
55: @Override @Nonnull
56: public String toString()
57: {
58: return String.format("%s(%s)", getClass().getSimpleName(), mimeType);
59: }
60: }