1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF 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 * https://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 18 /* 19 * This is not the original file distributed by the Apache Software Foundation 20 * It has been modified by the Hipparchus project 21 */ 22 23 package org.hipparchus.geometry.euclidean.oned; 24 25 import java.io.Serializable; 26 27 import org.hipparchus.exception.MathRuntimeException; 28 import org.hipparchus.geometry.LocalizedGeometryFormats; 29 import org.hipparchus.geometry.Space; 30 31 /** 32 * This class implements a one-dimensional space. 33 */ 34 public class Euclidean1D implements Serializable, Space { 35 36 /** Serializable version identifier. */ 37 private static final long serialVersionUID = -1178039568877797126L; 38 39 /** Private constructor for the singleton. 40 */ 41 private Euclidean1D() { 42 } 43 44 /** Get the unique instance. 45 * @return the unique instance 46 */ 47 public static Euclidean1D getInstance() { 48 return LazyHolder.INSTANCE; 49 } 50 51 /** {@inheritDoc} */ 52 @Override 53 public int getDimension() { 54 return 1; 55 } 56 57 /** {@inheritDoc} 58 * <p> 59 * As the 1-dimension Euclidean space does not have proper sub-spaces, 60 * this method always throws a {@link NoSubSpaceException} 61 * </p> 62 * @return nothing 63 * @throws NoSubSpaceException in all cases 64 */ 65 @Override 66 public Space getSubSpace() throws NoSubSpaceException { 67 throw new NoSubSpaceException(); 68 } 69 70 // CHECKSTYLE: stop HideUtilityClassConstructor 71 /** Holder for the instance. 72 * <p>We use here the Initialization On Demand Holder Idiom.</p> 73 */ 74 private static class LazyHolder { 75 /** Cached field instance. */ 76 private static final Euclidean1D INSTANCE = new Euclidean1D(); 77 } 78 // CHECKSTYLE: resume HideUtilityClassConstructor 79 80 /** Handle deserialization of the singleton. 81 * @return the singleton instance 82 */ 83 private Object readResolve() { 84 // return the singleton instance 85 return LazyHolder.INSTANCE; 86 } 87 88 /** Specialized exception for inexistent sub-space. 89 * <p> 90 * This exception is thrown when attempting to get the sub-space of a one-dimensional space 91 * </p> 92 */ 93 public static class NoSubSpaceException extends MathRuntimeException { 94 95 /** Serializable UID. */ 96 private static final long serialVersionUID = 20140225L; 97 98 /** Simple constructor. 99 */ 100 public NoSubSpaceException() { 101 super(LocalizedGeometryFormats.NOT_SUPPORTED_IN_DIMENSION_N, 1); 102 } 103 104 } 105 106 }