All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.eBusx.geo.GeoLineString Maven / Gradle / Ivy

//
// Copyright 2021 Charles W. Rapp
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package net.sf.eBusx.geo;

import java.util.Objects;
import net.sf.eBus.util.Validator;

/**
 * Array of two or more positions. Positions may cross. Contains
 * a single {@link LineString} instance.
 *
 * @author Charles W. Rapp
 */

public final class GeoLineString
    extends GeoObject
{
//---------------------------------------------------------------
// Member data.
//

    //-----------------------------------------------------------
    // Constants.
    //

    /**
     * Serialization version identifier.
     */
    private static final long serialVersionUID = 0x050700L;

    //-----------------------------------------------------------
    // Locals.
    //

    /**
     * Actual line string instance contained in this GeoJSON
     * object.
     */
    public final LineString lineString;

//---------------------------------------------------------------
// Member methods.
//

    //-----------------------------------------------------------
    // Constructors.
    //

    /**
     * Constructor is private because line string instances may
     * only be created using a {@code GeoLineString.Builder}
     * instance.
     * @param builder builder containing valid line string
     * configuration.
     */
    private GeoLineString(final Builder builder)
    {
        super (builder);

        this.lineString = builder.mLineString;
    } // end of GeoLineString(Builder)

    //
    // end of Constructors.
    //-----------------------------------------------------------

    //-----------------------------------------------------------
    // Object Method Overrides.
    //

    /**
     * Returns human-readable textual representation of a
     * GeoJSON line string.
     * @return GeoJSON line string as text.
     */
    @Override
    public String toString()
    {
        final StringBuilder retval = new StringBuilder();

        retval.append('[').append(super.toString())
              .append(", line=").append(lineString)
              .append(']');

        return (retval.toString());
    } // end of toString()

    //
    // end of Object Method Overrides.
    //-----------------------------------------------------------

    /**
     * Returns a new GeoJSON line string builder instance.
     * @return {@code GeoLineString} builder instance.
     */
    public static Builder builder()
    {
        return (new Builder());
    } // end of builder()

//---------------------------------------------------------------
// Inner classes.
//

    /**
     * Builder used to create {@code GeoLineString} instance.
     * {@code Builder} instance is obtained by calling
     * {@link #builder()}. It is recommended that a new builder
     * instance be used to create each {@code GeoLineString}
     * instance.
     */
    public static final class Builder
        extends GeoObject.GeoBuilder
    {
    //-----------------------------------------------------------
    // Member data.
    //

        //-------------------------------------------------------
        // Locals.
        //

        private LineString mLineString;

    //-----------------------------------------------------------
    // Member methods.
    //

        //-------------------------------------------------------
        // Constructors.
        //

        private Builder()
        {
            super (GeoLineString.class, GeoType.LINE_STRING);
        } // end of Builder()

        //
        // end of Constructors.
        //-------------------------------------------------------

        //-------------------------------------------------------
        // Builder Method Overrides.
        //

        /**
         * Checks if line string is set.
         * @param problems add each detected problem to this
         * validator.
         * @return {@code problems}.
         */
        @Override
        protected Validator validate(Validator problems)
        {
            return (super.validate(problems)
                         .requireNotNull(mLineString, "lineString"));
        } // end of validate(Validator)

        /**
         * Returns a new GeoJSON line string instance based on
         * this builder's settings.
         * @return new {@code GeoLineString} instance.
         */
        @Override
        protected GeoLineString buildImpl()
        {
            return (new GeoLineString(this));
        } // end of buildImpl()

        //
        // end of Builder Method Overrides.
        //-------------------------------------------------------

        //-------------------------------------------------------
        // Set Methods.
        //

        /**
         * Sets line string. Returns
         * {@code this Builder} instance so that builder method
         * calls can be chained.
         * @param ls line string.
         * @return {@code this Builder} instance.
         * @throws NullPointerException
         * if {@code ls} is {@code null}.
         */
        public Builder lineString(final LineString ls)
        {
            mLineString =
                Objects.requireNonNull(ls, "lineString is null");

            return (this);
        } // end of lineString(LineString)

        //
        // end of Set Methods.
        //-------------------------------------------------------
    } // end of class Builder
} // end of class GeoLineString




© 2015 - 2024 Weber Informatics LLC | Privacy Policy