Skip to content

Package: OperationImplementation

OperationImplementation

nameinstructionbranchcomplexitylinemethod
OperationImplementation()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
bind(Operation)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
canHandle(Operation)
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%
execute(EditableImage, Object)
M: 0 C: 25
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getFactory()
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%
setFactory(ImplementationFactory)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 4
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: * Mistral: open source imaging engine
5: * http://tidalwave.it/projects/mistral
6: *
7: * Copyright (C) 2003 - 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/mistral-src
23: * git clone https://github.com/tidalwave-it/mistral-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.image.op;
28:
29: import javax.annotation.Nonnull;
30: import it.tidalwave.image.EditableImage;
31: import lombok.Getter;
32: import lombok.Setter;
33: import lombok.extern.slf4j.Slf4j;
34:
35: /***********************************************************************************************************************
36: *
37: * @author Fabrizio Giudici
38: *
39: **********************************************************************************************************************/
40: @Slf4j
41: public abstract class OperationImplementation<Op extends Operation, Model extends Object>
42: {
43: /**
44: * The operation we are implementing.
45: */
46: private Op operation;
47:
48: @Getter @Setter
49: private ImplementationFactory factory;
50:
51: /*******************************************************************************************************************
52: *
53: * Executes this operation on the given model.
54: *
55: * @param model the image representation
56: *
57: ******************************************************************************************************************/
58: @Nonnull
59: public final Object execute (@Nonnull final EditableImage image, @Nonnull final Object model)
60: {
61: final var now = System.currentTimeMillis();
62: log.debug("executing {}", operation);
63: final Object result = execute(operation, image, (Model)model);
64: log.debug(">>>> {} done in {} msec", operation, (System.currentTimeMillis() - now));
65:
66: return result;
67: }
68:
69: /*******************************************************************************************************************
70: *
71: * Sometimes an implementation can't handle a specific set of parameters.
72: * In this case, this method must return false, so this implementation will
73: * be discarded.
74: * This method returns true by default, so subclasses with different
75: * behaviours should override it.
76: *
77: ******************************************************************************************************************/
78: public boolean canHandle (@Nonnull final Op operation)
79: {
80: return true;
81: }
82:
83: /*******************************************************************************************************************
84: *
85: *
86: ******************************************************************************************************************/
87: protected void bind (@Nonnull final Op operation)
88: {
89: this.operation = operation;
90: }
91:
92: /*******************************************************************************************************************
93: *
94: * The concrete implementation of this operation should be provided by
95: * overriding this method.
96: *
97: * @param operation the operation to implement
98: * @param model the image representation
99: *
100: ******************************************************************************************************************/
101: @Nonnull
102: protected abstract Model execute (@Nonnull final Op operation,
103: @Nonnull final EditableImage image,
104: @Nonnull final Model model);
105: }