Euclidean1D.java

  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.  * This is not the original file distributed by the Apache Software Foundation
  19.  * It has been modified by the Hipparchus project
  20.  */

  21. package org.hipparchus.geometry.euclidean.oned;

  22. import java.io.Serializable;

  23. import org.hipparchus.exception.MathRuntimeException;
  24. import org.hipparchus.geometry.LocalizedGeometryFormats;
  25. import org.hipparchus.geometry.Space;

  26. /**
  27.  * This class implements a one-dimensional space.
  28.  */
  29. public class Euclidean1D implements Serializable, Space {

  30.     /** Serializable version identifier. */
  31.     private static final long serialVersionUID = -1178039568877797126L;

  32.     /** Private constructor for the singleton.
  33.      */
  34.     private Euclidean1D() {
  35.     }

  36.     /** Get the unique instance.
  37.      * @return the unique instance
  38.      */
  39.     public static Euclidean1D getInstance() {
  40.         return LazyHolder.INSTANCE;
  41.     }

  42.     /** {@inheritDoc} */
  43.     @Override
  44.     public int getDimension() {
  45.         return 1;
  46.     }

  47.     /** {@inheritDoc}
  48.      * <p>
  49.      * As the 1-dimension Euclidean space does not have proper sub-spaces,
  50.      * this method always throws a {@link NoSubSpaceException}
  51.      * </p>
  52.      * @return nothing
  53.      * @throws NoSubSpaceException in all cases
  54.      */
  55.     @Override
  56.     public Space getSubSpace() throws NoSubSpaceException {
  57.         throw new NoSubSpaceException();
  58.     }

  59.     // CHECKSTYLE: stop HideUtilityClassConstructor
  60.     /** Holder for the instance.
  61.      * <p>We use here the Initialization On Demand Holder Idiom.</p>
  62.      */
  63.     private static class LazyHolder {
  64.         /** Cached field instance. */
  65.         private static final Euclidean1D INSTANCE = new Euclidean1D();
  66.     }
  67.     // CHECKSTYLE: resume HideUtilityClassConstructor

  68.     /** Handle deserialization of the singleton.
  69.      * @return the singleton instance
  70.      */
  71.     private Object readResolve() {
  72.         // return the singleton instance
  73.         return LazyHolder.INSTANCE;
  74.     }

  75.     /** Specialized exception for inexistent sub-space.
  76.      * <p>
  77.      * This exception is thrown when attempting to get the sub-space of a one-dimensional space
  78.      * </p>
  79.      */
  80.     public static class NoSubSpaceException extends MathRuntimeException {

  81.         /** Serializable UID. */
  82.         private static final long serialVersionUID = 20140225L;

  83.         /** Simple constructor.
  84.          */
  85.         public NoSubSpaceException() {
  86.             super(LocalizedGeometryFormats.NOT_SUPPORTED_IN_DIMENSION_N, 1);
  87.         }

  88.     }

  89. }