001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.math3.geometry.spherical.oned; 019 020import java.io.Serializable; 021 022import org.apache.commons.math3.exception.MathUnsupportedOperationException; 023import org.apache.commons.math3.exception.util.LocalizedFormats; 024import org.apache.commons.math3.geometry.Space; 025 026/** 027 * This class implements a one-dimensional sphere (i.e. a circle). 028 * <p> 029 * We use here the topologists definition of the 1-sphere (see 030 * <a href="http://mathworld.wolfram.com/Sphere.html">Sphere</a> on 031 * MathWorld), i.e. the 1-sphere is the one-dimensional closed curve 032 * defined in 2D as x<sup>2</sup>+y<sup>2</sup>=1. 033 * </p> 034 * @since 3.3 035 */ 036public class Sphere1D implements Serializable, Space { 037 038 /** Serializable version identifier. */ 039 private static final long serialVersionUID = 20131218L; 040 041 /** Private constructor for the singleton. 042 */ 043 private Sphere1D() { 044 } 045 046 /** Get the unique instance. 047 * @return the unique instance 048 */ 049 public static Sphere1D getInstance() { 050 return LazyHolder.INSTANCE; 051 } 052 053 /** {@inheritDoc} */ 054 public int getDimension() { 055 return 1; 056 } 057 058 /** {@inheritDoc} 059 * <p> 060 * As the 1-dimension sphere does not have proper sub-spaces, 061 * this method always throws a {@link NoSubSpaceException} 062 * </p> 063 * @return nothing 064 * @throws NoSubSpaceException in all cases 065 */ 066 public Space getSubSpace() throws NoSubSpaceException { 067 throw new NoSubSpaceException(); 068 } 069 070 // CHECKSTYLE: stop HideUtilityClassConstructor 071 /** Holder for the instance. 072 * <p>We use here the Initialization On Demand Holder Idiom.</p> 073 */ 074 private static class LazyHolder { 075 /** Cached field instance. */ 076 private static final Sphere1D INSTANCE = new Sphere1D(); 077 } 078 // CHECKSTYLE: resume HideUtilityClassConstructor 079 080 /** Handle deserialization of the singleton. 081 * @return the singleton instance 082 */ 083 private Object readResolve() { 084 // return the singleton instance 085 return LazyHolder.INSTANCE; 086 } 087 088 /** Specialized exception for inexistent sub-space. 089 * <p> 090 * This exception is thrown when attempting to get the sub-space of a one-dimensional space 091 * </p> 092 */ 093 public static class NoSubSpaceException extends MathUnsupportedOperationException { 094 095 /** Serializable UID. */ 096 private static final long serialVersionUID = 20140225L; 097 098 /** Simple constructor. 099 */ 100 public NoSubSpaceException() { 101 super(LocalizedFormats.NOT_SUPPORTED_IN_DIMENSION_N, 1); 102 } 103 104 } 105 106}