OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
180 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.utils.function;
15
 
16
import java.util.Objects;
17
 
18
import net.jcip.annotations.Immutable;
19
 
20
/**
21
 * A supplier returning a constant value.
22
 *
23
 * @author sylvain
24
 * @param <T> the type of results supplied by this supplier.
25
 * @see FunctionalSupplier#getConstant(Object)
26
 */
27
@Immutable
28
public final class ConstantSupplier<T> extends FunctionalSupplier<T> {
29
    private final T value;
30
 
31
    ConstantSupplier(final T value) {
32
        super();
33
        this.value = value;
34
    }
35
 
36
    @Override
37
    public T get() {
38
        return this.value;
39
    }
40
 
41
    @Override
42
    public int hashCode() {
43
        return this.value == null ? 0 : this.value.hashCode();
44
    }
45
 
46
    @Override
47
    public boolean equals(Object obj) {
48
        if (this == obj)
49
            return true;
50
        if (obj == null)
51
            return false;
52
        if (getClass() != obj.getClass())
53
            return false;
54
        final ConstantSupplier<?> other = (ConstantSupplier<?>) obj;
55
        return Objects.equals(this.value, other.value);
56
    }
57
 
58
    @Override
59
    public String toString() {
60
        return this.getClass().getSimpleName() + " of " + this.get();
61
    }
62
}