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    
018    package org.apache.commons.math3.geometry.euclidean.oned;
019    
020    import java.io.Serializable;
021    
022    import org.apache.commons.math3.exception.MathUnsupportedOperationException;
023    import org.apache.commons.math3.exception.util.LocalizedFormats;
024    import org.apache.commons.math3.geometry.Space;
025    
026    /**
027     * This class implements a one-dimensional space.
028     * @version $Id: Euclidean1D.java 1416643 2012-12-03 19:37:14Z tn $
029     * @since 3.0
030     */
031    public class Euclidean1D implements Serializable, Space {
032    
033        /** Serializable version identifier. */
034        private static final long serialVersionUID = -1178039568877797126L;
035    
036        /** Private constructor for the singleton.
037         */
038        private Euclidean1D() {
039        }
040    
041        /** Get the unique instance.
042         * @return the unique instance
043         */
044        public static Euclidean1D getInstance() {
045            return LazyHolder.INSTANCE;
046        }
047    
048        /** {@inheritDoc} */
049        public int getDimension() {
050            return 1;
051        }
052    
053        /** {@inheritDoc}
054         * <p>
055         * As the 1-dimension Euclidean space does not have proper sub-spaces,
056         * this method always throws a {@link MathUnsupportedOperationException}
057         * </p>
058         * @return nothing
059         * @throws MathUnsupportedOperationException in all cases
060         */
061        public Space getSubSpace() throws MathUnsupportedOperationException {
062            throw new MathUnsupportedOperationException(LocalizedFormats.NOT_SUPPORTED_IN_DIMENSION_N, 1);
063        }
064    
065        // CHECKSTYLE: stop HideUtilityClassConstructor
066        /** Holder for the instance.
067         * <p>We use here the Initialization On Demand Holder Idiom.</p>
068         */
069        private static class LazyHolder {
070            /** Cached field instance. */
071            private static final Euclidean1D INSTANCE = new Euclidean1D();
072        }
073        // CHECKSTYLE: resume HideUtilityClassConstructor
074    
075        /** Handle deserialization of the singleton.
076         * @return the singleton instance
077         */
078        private Object readResolve() {
079            // return the singleton instance
080            return LazyHolder.INSTANCE;
081        }
082    
083    }