1 /* Copyright 2013-2019 CS Systèmes d'Information
2 * Licensed to CS Systèmes d'Information (CS) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * CS licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.orekit.rugged.utils;
18
19 /** Selector for min value.
20 * <p>
21 * This selector considers {@code Double.NaN} values correspond
22 * to non-initialized data that should be ignored rather than
23 * selected.
24 * </p>
25 * @see MaxSelector
26 * @author Luc Maisonobe
27 */
28 public class MinSelector extends Selector {
29
30 /** Private constructor for singleton.
31 */
32 private MinSelector() {
33 }
34
35 /** Get the unique instance.
36 * @return unique instance of the min selector.
37 */
38 public static MinSelector getInstance() {
39 return LazyHolder.INSTANCE;
40 }
41
42 /** Check if first value should be selected.
43 * @param v1 first value
44 * @param v2 second value
45 * @return true if v1 is lower than v2, or if v2 is {@code Double.NaN}
46 */
47 @Override
48 public boolean selectFirst(final double v1, final double v2) {
49 return v1 < v2 || Double.isNaN(v2);
50 }
51
52 /** Holder for the min selector singleton.
53 * <p>
54 * We use the Initialization On Demand Holder Idiom to store
55 * the singletons, as it is both thread-safe, efficient (no
56 * synchronization) and works with all versions of java.
57 * </p>
58 */
59 private static class LazyHolder {
60
61 /** Unique instance. */
62 private static final MinSelector.html#MinSelector">MinSelector INSTANCE = new MinSelector();
63
64 /** Private constructor.
65 * <p>This class is a utility class, it should neither have a public
66 * nor a default constructor. This private constructor prevents
67 * the compiler from generating one automatically.</p>
68 */
69 private LazyHolder() {
70 }
71
72 }
73
74 }