@Override public Positions positions() { Positions positions = new SinglePosition(Double.NaN, Double.NaN, Double.NaN); for (Geometry<?> geometry : this.geometries) { positions.merge(geometry.positions()); } return positions; }
/** * Returns the underlying {@link Positions} size. * * @return int */ @Override public int size() { return positions.size(); }
@Override public void write(JsonWriter out, Positions value) throws IOException { if (value == null) { out.nullValue(); } else { out.beginArray(); if (value instanceof SinglePosition) { SinglePosition sp = (SinglePosition) value; out.value(sp.lon()); out.value(sp.lat()); if (!Double.isNaN(sp.alt())) { out.value(sp.alt()); } } else { for (Positions child : value.children()) { write(out, child); } } out.endArray(); } }
@Override public void write(JsonWriter out, Positions value) throws IOException { if (value == null) { out.nullValue(); } else { out.beginArray(); if (value instanceof SinglePosition) { SinglePosition sp = (SinglePosition) value; out.value(sp.lon()); out.value(sp.lat()); if (!Double.isNaN(sp.alt())) { out.value(sp.alt()); } } else { for (Positions child : value.children()) { write(out, child); } } out.endArray(); } }
@Override public Positions positions() { Positions positions = new SinglePosition(Double.NaN, Double.NaN, Double.NaN); for (Geometry<?> geometry : this.geometries) { positions.merge(geometry.positions()); } return positions; }
/** * Returns the underlying {@link Positions} size. * * @return int */ @Override public int size() { return positions.size(); }
/** * Merge this SinglePosition with another {@link Positions} instance. If the given {@link Positions} is: * - a SinglePosition, it returns a {@link LinearPositions} composed by this and the given positions, in order. * - any other {@link Positions}, it delegates to the given {@link Positions} merge. * * @param other Positions instance to merge with. * * @return Positions instance result of merge. */ @Override public Positions merge(Positions other) { if (other instanceof SinglePosition) { SinglePosition that = (SinglePosition) other; return LinearPositions.builder().addSinglePosition(this).addSinglePosition(that).build(); } else { return other.merge(this); } }
/** * Merge this SinglePosition with another {@link Positions} instance. If the given {@link Positions} is: * - a SinglePosition, it returns a {@link LinearPositions} composed by this and the given positions, in order. * - any other {@link Positions}, it delegates to the given {@link Positions} merge. * * @param other Positions instance to merge with. * * @return Positions instance result of merge. */ @Override public Positions merge(Positions other) { if (other instanceof SinglePosition) { SinglePosition that = (SinglePosition) other; return LinearPositions.builder().addSinglePosition(this).addSinglePosition(that).build(); } else { return other.merge(this); } }
/** * Merge this Positions with another one. If the given {@link Positions} is: * - SinglePosition, it will raise an IllegalArgumentException. * - LinearPositions, it will return a new AreaPosition by appending the given LinearPositions to this. * - AreaPositions, it will return a new MultiDimensionalPositions composed by this and the given AreaPositions, * in order. * - 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) { throw new IllegalArgumentException("Cannot merge single position and area children"); } else if (other instanceof LinearPositions) { LinearPositions that = (LinearPositions) other; return builder().addLinearPosition(that).build(); } else if (other instanceof AreaPositions) { AreaPositions that = (AreaPositions) other; return MultiDimensionalPositions.builder().addAreaPosition(this).addAreaPosition(that).build(); } else { return other.merge(this); } }
/** * Merge this Positions with another one. If the given {@link Positions} is: * - SinglePosition, it will raise an IllegalArgumentException. * - LinearPositions, it will return a new AreaPosition by appending the given LinearPositions to this. * - AreaPositions, it will return a new MultiDimensionalPositions composed by this and the given AreaPositions, * in order. * - 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) { throw new IllegalArgumentException("Cannot merge single position and area children"); } else if (other instanceof LinearPositions) { LinearPositions that = (LinearPositions) other; return builder().addLinearPosition(that).build(); } else if (other instanceof AreaPositions) { AreaPositions that = (AreaPositions) other; return MultiDimensionalPositions.builder().addAreaPosition(this).addAreaPosition(that).build(); } else { return other.merge(this); } }
/** * 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); } }
/** * 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); } }