// Path: core/src/main/java/com/github/filosganga/geogson/model/positions/LinearPositions.java
// public class LinearPositions extends AbstractPositions<SinglePosition> {
// 
//     private static final long serialVersionUID = 1L;
// 
//     private final Boolean isClosed;
// 
//     private LinearPositions(List<SinglePosition> children, boolean isClosed) {
//         super(children);
//         this.isClosed = isClosed;
//     }
// 
//     public static LinearPositions.Builder builder() {
//         return new LinearPositions.Builder();
//     }
// 
//     public static LinearPositions.Builder builder(LinearPositions positions) {
//         return builder().addSinglePositions(positions.children);
//     }
// 
//     /**
//      * Merge this LinearPositions with another one. If the given {@link Positions} is:
//      *  - SinglePosition, it will return a new LinearPositions with the given SinglePosition appended.
//      *  - LinearPositions, it will return a new AreaPosition composed by this and the given LinearPositions.
//      *  - Any other, it delegates to the other the merge logic.
//      *
//      * @param other Positions instance to merge with.
//      *
//      * @return Positions results of merging.
//      */
//     @Override
//     public Positions merge(Positions other) {
//         if (other instanceof SinglePosition) {
//             SinglePosition that = (SinglePosition) other;
//             return builder().addSinglePosition(that).build();
//         } else if (other instanceof LinearPositions) {
//             LinearPositions that = (LinearPositions) other;
//             return AreaPositions.builder().addLinearPosition(this).addLinearPosition(that).build();
//         } else {
//             return other.merge(this);
//         }
//     }
// 
//     /**
//      * Returns if this LinearPosition:
//      *  - Is composed by at least 4 points
//      *  - The first and the last are the same.
//      *
//      * @return true if it is closed, false otherwise.
//      */
//     public boolean isClosed() {
//         return isClosed;
//     }
// 
//     public static class Builder implements PositionsBuilder {
// 
//         private LinkedList<SinglePosition> singlePositions = new LinkedList<>();
// 
//         private SinglePosition first = null;
//         private SinglePosition last = null;
//         private int size = 0;
// 
//         public Builder addSinglePosition(SinglePosition sp) {
//             singlePositions.add(sp);
//             if(first == null) {
//                 first = sp;
//             }
//             last = sp;
//             size++;
// 
//             return this;
//         }
// 
//         public Builder addSinglePositions(Iterable<SinglePosition> sps) {
//             sps.forEach(this::addSinglePosition);
//             return this;
//         }
// 
//         @Override
//         public PositionsBuilder addChild(Positions p) {
//             if(p instanceof SinglePosition) {
//                 return addSinglePosition((SinglePosition) p);
//             } else if (p instanceof LinearPositions) {
//                 return AreaPositions.builder().addChild(this.build()).addChild(p);
//             } else {
//                 throw new IllegalArgumentException("The position " + p +  "cannot be a child of LinearPositions");
//             }
//         }
// 
//         @Override
//         public LinearPositions build() {
//             Boolean isClosed = size >= 4 && first.equals(last);
//             return new LinearPositions(singlePositions, isClosed);
//         }
// 
//     }
// 
// 
// }
// 
// Path: core/src/main/java/com/github/filosganga/geogson/util/Preconditions.java
// public static <T> T checkArgument(T argument, Function<T, Boolean> predicate, Object errorMessage) {
//     if (!predicate.apply(argument)) {
//         throw new IllegalArgumentException(String.valueOf(errorMessage));
//     } else {
//         return argument;
//     }
// }


import com.github.filosganga.geogson.model.positions.LinearPositions;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.github.filosganga.geogson.util.Preconditions.checkArgument;
/*
 * Copyright 2013 Filippo De Luca - me@filippodeluca.com
 *
 * 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 com.github.filosganga.geogson.model;




/**
 * Specialization of LinearGeometry composed at least by 2 points.
 * <p>
 * JeoGson reference: @see http://geojson.org/geojson-spec.html#linestring.
 */
public class LineString extends LinearGeometry {

    private static final long serialVersionUID = 1L;

    public LineString(LinearPositions positions) {
// Path: core/src/main/java/com/github/filosganga/geogson/model/positions/LinearPositions.java
// public class LinearPositions extends AbstractPositions<SinglePosition> {
// 
//     private static final long serialVersionUID = 1L;
// 
//     private final Boolean isClosed;
// 
//     private LinearPositions(List<SinglePosition> children, boolean isClosed) {
//         super(children);
//         this.isClosed = isClosed;
//     }
// 
//     public static LinearPositions.Builder builder() {
//         return new LinearPositions.Builder();
//     }
// 
//     public static LinearPositions.Builder builder(LinearPositions positions) {
//         return builder().addSinglePositions(positions.children);
//     }
// 
//     /**
//      * Merge this LinearPositions with another one. If the given {@link Positions} is:
//      *  - SinglePosition, it will return a new LinearPositions with the given SinglePosition appended.
//      *  - LinearPositions, it will return a new AreaPosition composed by this and the given LinearPositions.
//      *  - Any other, it delegates to the other the merge logic.
//      *
//      * @param other Positions instance to merge with.
//      *
//      * @return Positions results of merging.
//      */
//     @Override
//     public Positions merge(Positions other) {
//         if (other instanceof SinglePosition) {
//             SinglePosition that = (SinglePosition) other;
//             return builder().addSinglePosition(that).build();
//         } else if (other instanceof LinearPositions) {
//             LinearPositions that = (LinearPositions) other;
//             return AreaPositions.builder().addLinearPosition(this).addLinearPosition(that).build();
//         } else {
//             return other.merge(this);
//         }
//     }
// 
//     /**
//      * Returns if this LinearPosition:
//      *  - Is composed by at least 4 points
//      *  - The first and the last are the same.
//      *
//      * @return true if it is closed, false otherwise.
//      */
//     public boolean isClosed() {
//         return isClosed;
//     }
// 
//     public static class Builder implements PositionsBuilder {
// 
//         private LinkedList<SinglePosition> singlePositions = new LinkedList<>();
// 
//         private SinglePosition first = null;
//         private SinglePosition last = null;
//         private int size = 0;
// 
//         public Builder addSinglePosition(SinglePosition sp) {
//             singlePositions.add(sp);
//             if(first == null) {
//                 first = sp;
//             }
//             last = sp;
//             size++;
// 
//             return this;
//         }
// 
//         public Builder addSinglePositions(Iterable<SinglePosition> sps) {
//             sps.forEach(this::addSinglePosition);
//             return this;
//         }
// 
//         @Override
//         public PositionsBuilder addChild(Positions p) {
//             if(p instanceof SinglePosition) {
//                 return addSinglePosition((SinglePosition) p);
//             } else if (p instanceof LinearPositions) {
//                 return AreaPositions.builder().addChild(this.build()).addChild(p);
//             } else {
//                 throw new IllegalArgumentException("The position " + p +  "cannot be a child of LinearPositions");
//             }
//         }
// 
//         @Override
//         public LinearPositions build() {
//             Boolean isClosed = size >= 4 && first.equals(last);
//             return new LinearPositions(singlePositions, isClosed);
//         }
// 
//     }
// 
// 
// }
// 
// Path: core/src/main/java/com/github/filosganga/geogson/util/Preconditions.java
// public static <T> T checkArgument(T argument, Function<T, Boolean> predicate, Object errorMessage) {
//     if (!predicate.apply(argument)) {
//         throw new IllegalArgumentException(String.valueOf(errorMessage));
//     } else {
//         return argument;
//     }
// }


// Path: core/src/main/java/com/github/filosganga/geogson/model/LineString.java
import com.github.filosganga.geogson.model.positions.LinearPositions;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.github.filosganga.geogson.util.Preconditions.checkArgument;

/*
 * Copyright 2013 Filippo De Luca - me@filippodeluca.com
 *
 * 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 com.github.filosganga.geogson.model;




/**
 * Specialization of LinearGeometry composed at least by 2 points.
 * <p>
 * JeoGson reference: @see http://geojson.org/geojson-spec.html#linestring.
 */
public class LineString extends LinearGeometry {

    private static final long serialVersionUID = 1L;

    public LineString(LinearPositions positions) {
        super(checkArgument(positions, toCheck -> toCheck.size() >= 2, "LineString must be composed by a minimum of 2 points."));