OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 180
Line 11... Line 11...
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.utils;
14
 package org.openconcerto.utils;
15
 
15
 
-
 
16
import org.openconcerto.utils.cc.I2ExnFactory;
-
 
17
 
16
import java.util.Map;
18
import java.util.Map;
-
 
19
import java.util.function.Supplier;
17
 
20
 
18
/**
21
/**
19
 * Null can be ambiguous, e.g. {@link Map#get(Object)}. This class allows to avoid the problem.
22
 * Null can be ambiguous, e.g. {@link Map#get(Object)}. This class allows to avoid the problem.
20
 * 
23
 * 
21
 * @author Sylvain
24
 * @author Sylvain
Line 155... Line 158...
155
            return this.getValue();
158
            return this.getValue();
156
        else
159
        else
157
            return def;
160
            return def;
158
    }
161
    }
159
 
162
 
-
 
163
    public final Value<V> asSome(final V def) {
-
 
164
        if (this.hasValue())
-
 
165
            return this;
-
 
166
        else
-
 
167
            return getSome(def);
-
 
168
    }
-
 
169
 
-
 
170
    // Same method names as Optional
-
 
171
 
-
 
172
    public final V orElse(final V def) {
-
 
173
        return this.getValue(def);
-
 
174
    }
-
 
175
 
-
 
176
    public final V orGet(final Supplier<? extends V> def) {
-
 
177
        if (this.hasValue())
-
 
178
            return this.getValue();
-
 
179
        else
-
 
180
            return def.get();
-
 
181
    }
-
 
182
 
-
 
183
    public final <X extends Exception, X2 extends Exception> V orThrowingGet(final I2ExnFactory<? extends V, X, X2> def) throws X, X2 {
-
 
184
        if (this.hasValue())
-
 
185
            return this.getValue();
-
 
186
        else
-
 
187
            return def.createChecked();
-
 
188
    }
-
 
189
 
160
    /**
190
    /**
161
     * Return <code>null</code> if and only if this has no value.
191
     * Return <code>null</code> if and only if this has no value.
162
     * 
192
     * 
163
     * @return non <code>null</code> {@link #getValue()} if {@link #hasValue()}, otherwise
193
     * @return non <code>null</code> {@link #getValue()} if {@link #hasValue()}, otherwise
164
     *         <code>null</code>.
194
     *         <code>null</code>.