class CoordinateSequences extends com.vividsolutions.jts.geom.CoordinateSequences {

    public static int coordinateDimension(Geometry g)
    {
        // common fast cases
        if (g instanceof CurvedGeometry<?>) {
            return ((CurvedGeometry<?>) g).getCoordinatesDimension();
        }
        if (g instanceof Point)
            return coordinateDimension(((Point) g).getCoordinateSequence());
        if (g instanceof LineString)
            return coordinateDimension(((LineString) g).getCoordinateSequence());
        if (g instanceof Polygon)
            return coordinateDimension(((Polygon) g).getExteriorRing()
                    .getCoordinateSequence());
    
        // dig down to find a CS
        CoordinateSequence cs = CoordinateSequenceFinder.find(g);
        return coordinateDimension(cs);
    }

}