    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.twod;
    019
    020    import java.io.Serializable;
    021
    022    import org.apache.commons.math3.geometry.Space;
    023    import org.apache.commons.math3.geometry.euclidean.oned.Euclidean1D;
    024
    025    /**
    026     * This class implements a three-dimensional space.
    027     * @version $Id: Euclidean2D.java 1416643 2012-12-03 19:37:14Z tn $
    028     * @since 3.0
    029     */
    030    public class Euclidean2D implements Serializable, Space {
    031
    032        /** Serializable version identifier. */
    033        private static final long serialVersionUID = 4793432849757649566L;
    034
    035        /** Private constructor for the singleton.
    036         */
    037        private Euclidean2D() {
    038        }
    039
    040        /** Get the unique instance.
    041         * @return the unique instance
    042         */
    043        public static Euclidean2D getInstance() {
    044            return LazyHolder.INSTANCE;
    045        }
    046
    047        /** {@inheritDoc} */
    048        public int getDimension() {
    049            return 2;
    050        }
    051
    052        /** {@inheritDoc} */
    053        public Euclidean1D getSubSpace() {
    054            return Euclidean1D.getInstance();
    055        }
    056
    057        // CHECKSTYLE: stop HideUtilityClassConstructor
    058        /** Holder for the instance.
    059         * <p>We use here the Initialization On Demand Holder Idiom.</p>
    060         */
    061        private static class LazyHolder {
    062            /** Cached field instance. */
    063            private static final Euclidean2D INSTANCE = new Euclidean2D();
    064        }
    065        // CHECKSTYLE: resume HideUtilityClassConstructor
    066
    067        /** Handle deserialization of the singleton.
    068         * @return the singleton instance
    069         */
    070        private Object readResolve() {
    071            // return the singleton instance
    072            return LazyHolder.INSTANCE;
    073        }
    074
    075    }