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