/** * Merge this Positions with another one. If the given {@link Positions} is: * - SinglePosition, it will raise an IllegalArgumentException. * - LinearPositions, it is a special case in which the given LinearPositions represent a * {@link com.github.filosganga.geogson.model.Polygon} with no holes. This is probably not compliant with the * GeoJson specifications, but it seems to happen quite frequently. It will be handled as the AreaPositions case. * - AreaPositions, it will return a new MultiDimensionalPositions by appending the given AreaPositions to this. * - Any other, it will raise an IllegalArgumentException * * @param other Positions instance to merge with. * * @return Positions results of merging. */ @Override public Positions merge(Positions other) { if (other instanceof SinglePosition) { throw new IllegalArgumentException("Cannot merge single position and multidimensional positions"); } else if (other instanceof LinearPositions) { // It can happen when a Polygon does not have holes and is represented by linear position see bug #19 return merge(AreaPositions.builder().addLinearPosition((LinearPositions) other).build()); } else if (other instanceof AreaPositions) { AreaPositions that = (AreaPositions) other; return new MultiDimensionalPositions.Builder().addAreaPositions(children).addAreaPosition(that).build(); } else { throw new IllegalArgumentException("Cannot merge with: " + other); } }
/** * Merge this Positions with another one. If the given {@link Positions} is: * - SinglePosition, it will raise an IllegalArgumentException. * - LinearPositions, it is a special case in which the given LinearPositions represent a * {@link com.github.filosganga.geogson.model.Polygon} with no holes. This is probably not compliant with the * GeoJson specifications, but it seems to happen quite frequently. It will be handled as the AreaPositions case. * - AreaPositions, it will return a new MultiDimensionalPositions by appending the given AreaPositions to this. * - Any other, it will raise an IllegalArgumentException * * @param other Positions instance to merge with. * * @return Positions results of merging. */ @Override public Positions merge(Positions other) { if (other instanceof SinglePosition) { throw new IllegalArgumentException("Cannot merge single position and multidimensional positions"); } else if (other instanceof LinearPositions) { // It can happen when a Polygon does not have holes and is represented by linear position see bug #19 return merge(AreaPositions.builder().addLinearPosition((LinearPositions) other).build()); } else if (other instanceof AreaPositions) { AreaPositions that = (AreaPositions) other; return new MultiDimensionalPositions.Builder().addAreaPositions(children).addAreaPosition(that).build(); } else { throw new IllegalArgumentException("Cannot merge with: " + other); } }
public static MultiDimensionalPositions.Builder builder(MultiDimensionalPositions positions) { return builder().addAreaPositions(positions.children); }
public static MultiDimensionalPositions.Builder builder(MultiDimensionalPositions positions) { return builder().addAreaPositions(positions.children); }