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