Package: UnaryBoundFunctionSupport
UnaryBoundFunctionSupport
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
UnaryBoundFunctionSupport(ChangingSource) |
|
|
|
|
|
||||||||||||||||||||
get() |
|
|
|
|
|
||||||||||||||||||||
onSourceChange(Object, Object) |
|
|
|
|
|
Coverage
1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * These Foolish Things - Miscellaneous utilities
6: * http://thesefoolishthings.tidalwave.it - git clone git@bitbucket.org:tidalwave/thesefoolishthings-src.git
7: * %%
8: * Copyright (C) 2009 - 2018 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: * $Id$
24: *
25: * *********************************************************************************************************************
26: * #L%
27: */
28: package it.tidalwave.role.ui.function;
29:
30: import javax.annotation.Nonnull;
31: import java.beans.PropertyChangeEvent;
32: import java.beans.PropertyChangeListener;
33: import it.tidalwave.role.ui.ChangingSource;
34:
35: /***********************************************************************************************************************
36: *
37: * @author Fabrizio Giudici
38: * @version $Id$
39: *
40: **********************************************************************************************************************/
41: public abstract class UnaryBoundFunctionSupport<DOMAIN_TYPE, CODOMAIN_TYPE>
42: extends BoundFunctionSupport<DOMAIN_TYPE, CODOMAIN_TYPE>
43: {
44: @Nonnull
45: protected final ChangingSource<DOMAIN_TYPE> source;
46:
47: protected CODOMAIN_TYPE value;
48:
49: protected UnaryBoundFunctionSupport (final @Nonnull ChangingSource<DOMAIN_TYPE> source)
50: {
51: this.source = source;
52: source.addPropertyChangeListener(new PropertyChangeListener()
53: {
54: @Override
55: public void propertyChange (final @Nonnull PropertyChangeEvent event)
56: {
57: onSourceChange((DOMAIN_TYPE)event.getOldValue(), (DOMAIN_TYPE)event.getNewValue());
58: }
59: });
60: }
61:
62: protected void onSourceChange (final @Nonnull DOMAIN_TYPE oldSourceValue, final @Nonnull DOMAIN_TYPE newSourceValue)
63: {
64: final CODOMAIN_TYPE oldValue = function(oldSourceValue);
65: value = function(newSourceValue);
66: fireValueChanged(oldValue, value);
67: }
68:
69: @Nonnull
70: protected abstract CODOMAIN_TYPE function (final DOMAIN_TYPE value);
71:
72: @Override @Nonnull
73: public final CODOMAIN_TYPE get()
74: {
75: return value;
76: }
77: }