/** * Checks whether a cast should succeed * @param castToType * @param <Q> */ protected <Q extends Position> void checkCast(Class<Q> castToType) { if (! castToType.isAssignableFrom(getPositionClass()) ) { throw new ClassCastException(format("Can't cast a %s to a %s", getPositionClass().getName(), castToType.getName())); } }
@Override @SuppressWarnings("unchecked") public boolean equals(Object o) { if (this == o) return true; if (o == null || !Geometry.class.isAssignableFrom(o.getClass())) return false; if (!this.getPositionClass().equals(((Geometry) o).getPositionClass())) return false; Geometry<P> otherGeometry = (Geometry<P>) o; //safe cast because we first check for position class equality return geomEq.equals(this, otherGeometry); }
protected <P extends Position> int getLRSDim(Geometry<P> geom) { if (Measured.class.isAssignableFrom(geom.getPositionClass())) { if (geom.getCoordinateDimension() == 3) { return 3; } else { return 4; } } return 0; }
private void startNewPointSequenceIfNotEmpty() { if (!sequenceIsEmpty) { positionSequences.add(currentBuilder.toPositionSequence()); currentBuilder = PositionSequenceBuilders.variableSized(this.geometry.getPositionClass()); sequenceIsEmpty = true; } }
@Override public <P extends C2D & Measured> Geometry<P> locateBetween(final Geometry<P> geometry, final double startMeasure, final double endMeasure) { if (geometry == null) throw new IllegalArgumentException("Null geometries not allowed."); if (geometry.isEmpty()) return new Point<P>(geometry.getCoordinateReferenceSystem()); if (C2D.class.isAssignableFrom(geometry.getPositionClass()) && Measured.class.isAssignableFrom(geometry.getPositionClass())) { MeasureInterpolatingVisitor visitor = new MeasureInterpolatingVisitor(geometry, startMeasure, endMeasure); geometry.accept((GeometryVisitor<P>) visitor); return (Geometry<P>) visitor.result(); } throw new IllegalArgumentException("Requires projected coordinates"); }
@Override public void visit(LineString<P> lineString) { currentBuilder = PositionSequenceBuilders.variableSized(this.geometry.getPositionClass()); P lastAddedPoint = null; LineSegments<P> segments = new LineSegments<P>(lineString.getPositions());