Euclidean3D.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.  *      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.apache.commons.math3.geometry.euclidean.threed;

  18. import java.io.Serializable;

  19. import org.apache.commons.math3.geometry.Space;
  20. import org.apache.commons.math3.geometry.euclidean.twod.Euclidean2D;

  21. /**
  22.  * This class implements a three-dimensional space.
  23.  * @since 3.0
  24.  */
  25. public class Euclidean3D implements Serializable, Space {

  26.     /** Serializable version identifier. */
  27.     private static final long serialVersionUID = 6249091865814886817L;

  28.     /** Private constructor for the singleton.
  29.      */
  30.     private Euclidean3D() {
  31.     }

  32.     /** Get the unique instance.
  33.      * @return the unique instance
  34.      */
  35.     public static Euclidean3D getInstance() {
  36.         return LazyHolder.INSTANCE;
  37.     }

  38.     /** {@inheritDoc} */
  39.     public int getDimension() {
  40.         return 3;
  41.     }

  42.     /** {@inheritDoc} */
  43.     public Euclidean2D getSubSpace() {
  44.         return Euclidean2D.getInstance();
  45.     }

  46.     // CHECKSTYLE: stop HideUtilityClassConstructor
  47.     /** Holder for the instance.
  48.      * <p>We use here the Initialization On Demand Holder Idiom.</p>
  49.      */
  50.     private static class LazyHolder {
  51.         /** Cached field instance. */
  52.         private static final Euclidean3D INSTANCE = new Euclidean3D();
  53.     }
  54.     // CHECKSTYLE: resume HideUtilityClassConstructor

  55.     /** Handle deserialization of the singleton.
  56.      * @return the singleton instance
  57.      */
  58.     private Object readResolve() {
  59.         // return the singleton instance
  60.         return LazyHolder.INSTANCE;
  61.     }

  62. }