ObservableValueDecorator.java
01 /*
02  * SPDX-License-Identifier: Apache-2.0
03  *
04  * Copyright 2008-2017 the original author or authors.
05  *
06  * Licensed under the Apache License, Version 2.0 (the "License");
07  * you may not use this file except in compliance with the License.
08  * You may obtain a copy of the License at
09  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 package griffon.javafx.beans.binding;
19 
20 import javafx.beans.InvalidationListener;
21 import javafx.beans.value.ChangeListener;
22 import javafx.beans.value.ObservableValue;
23 
24 import javax.annotation.Nonnull;
25 
26 import static java.util.Objects.requireNonNull;
27 
28 /**
29  @author Andres Almiray
30  @since 2.11.0
31  */
32 public class ObservableValueDecorator<T> implements ObservableValue<T> {
33     private final ObservableValue<T> delegate;
34 
35     public ObservableValueDecorator(@Nonnull ObservableValue<T> delegate) {
36         this.delegate = requireNonNull(delegate, "Argument 'delegate' must not be null");
37     }
38 
39     @Nonnull
40     protected final ObservableValue<T> getDelegate() {
41         return delegate;
42     }
43 
44     @Override
45     public void addListener(ChangeListener<? super T> listener) {
46         delegate.addListener(listener);
47     }
48 
49     @Override
50     public void removeListener(ChangeListener<? super T> listener) {
51         delegate.removeListener(listener);
52     }
53 
54     @Override
55     public T getValue() {
56         return delegate.getValue();
57     }
58 
59     @Override
60     public void addListener(InvalidationListener listener) {
61         delegate.addListener(listener);
62     }
63 
64     @Override
65     public void removeListener(InvalidationListener listener) {
66         delegate.removeListener(listener);
67     }
68 
69     @Override
70     public boolean equals(Object o) {
71         return this == o || delegate.equals(o);
72     }
73 
74     @Override
75     public int hashCode() {
76         return delegate.hashCode();
77     }
78 
79     @Override
80     public String toString() {
81         return getClass().getName() ":" + delegate.toString();
82     }
83 }