/** * Returns the next word in the stream. * * @return the next word in the stream as uppercase text * @throws ParseException if the next token is not a word * @throws IOException if an I/O error occurs */ private String getNextWord() throws IOException, ParseException { int type = tokenizer.nextToken(); switch (type) { case StreamTokenizer.TT_WORD: String word = tokenizer.sval; if (word.equalsIgnoreCase(EMPTY)) return EMPTY; return word; case '(': return L_PAREN; case ')': return R_PAREN; case ',': return COMMA; } parseError("word"); return null; }
/** * Returns the next R_PAREN or COMMA in the stream. * * @return the next R_PAREN or COMMA in the stream * @throws ParseException if the next token is not R_PAREN or COMMA * @throws IOException if an I/O error occurs */ private String getNextCloserOrComma() throws IOException, ParseException { String nextWord = getNextWord(); if (nextWord.equals(COMMA) || nextWord.equals(R_PAREN)) { return nextWord; } parseError(COMMA + " or " + R_PAREN); return null; }
/** * Returns the next EMPTY or L_PAREN in the stream as uppercase text. * * @return the next EMPTY or L_PAREN in the stream as uppercase text. * @throws ParseException if the next token is not EMPTY or L_PAREN * @throws IOException if an I/O error occurs */ private String getNextEmptyOrOpener() throws IOException, ParseException { String nextWord = getNextWord(); if (nextWord.equals(EMPTY) || nextWord.equals(L_PAREN)) { return nextWord; } parseError(EMPTY + " or " + L_PAREN); return null; }
/** * Returns the next R_PAREN in the stream. * * @return the next R_PAREN in the stream * @throws ParseException if the next token is not R_PAREN * @throws IOException if an I/O error occurs */ private String getNextCloser() throws IOException, ParseException { String nextWord = getNextWord(); if (nextWord.equals(R_PAREN)) { return nextWord; } parseError(R_PAREN); return null; }
/** * Parses the next number in the stream. Numbers with exponents are handled. <tt>NaN</tt> values * are handled correctly, and the case of the "NaN" token is not significant. * * @param tokenizer tokenizer over a stream of text in Well-known Text format. The next token * must be a number. * @return the next number in the stream * @throws ParseException if the next token is not a valid number * @throws IOException if an I/O error occurs */ private double getNextNumber() throws IOException, ParseException { int type = tokenizer.nextToken(); switch (type) { case StreamTokenizer.TT_WORD: { if (tokenizer.sval.equalsIgnoreCase(NAN_SYMBOL)) { return Double.NaN; } else { try { return Double.parseDouble(tokenizer.sval); } catch (NumberFormatException ex) { throw new ParseException("Invalid number: " + tokenizer.sval); } } } } parseError("number"); return 0.0; }
private Polygon readCurvePolygonText() throws IOException, ParseException { String nextToken = getNextEmptyOrOpener(); if (nextToken.equals(EMPTY)) { return geometryFactory.createCurvePolygon( geometryFactory.createLinearRing(new Coordinate[] {}), new LinearRing[] {}); } if (!nextToken.equals(L_PAREN)) { parseError("Ring expected"); } LinearRing shell = readCurvedLinearRingText(); ArrayList holes = new ArrayList(); nextToken = getNextCloserOrComma(); while (nextToken.equals(COMMA)) { LinearRing hole = readCurvedLinearRingText(); holes.add(hole); nextToken = getNextCloserOrComma(); } LinearRing[] array = new LinearRing[holes.size()]; return geometryFactory.createCurvePolygon(shell, (LinearRing[]) holes.toArray(array)); }
/** * This method will read a LineString, CircularString or CompoundCurve and return the result as * a LinearRing. * * @return LinearRing * <p>This method expects either "EMPTY", "(", "CIRCULARSTRING", or "COMPOIUNDCURVE" to * start out with. * @throws IOException * @throws ParseException */ private LinearRing readCurvedLinearRingText() throws IOException, ParseException { String nextWord = getNextWord(); if (nextWord.equals(L_PAREN)) { List<Coordinate> coords = getCoordinateList(false); return new LinearRing( new CoordinateArraySequence(coords.toArray(new Coordinate[coords.size()])), geometryFactory); } else if (nextWord.equalsIgnoreCase("CIRCULARSTRING")) { return (LinearRing) readCircularStringText(); } else if (nextWord.equalsIgnoreCase("COMPOUNDCURVE")) { return (LinearRing) readCompoundCurveText(); } else { parseError(L_PAREN + ", CIRCULARSTRING or COMPOUNDCURVE"); return null; } }
/** * Returns the next word in the stream. * *@return the next word in the stream as uppercase text *@throws ParseException * if the next token is not a word *@throws IOException * if an I/O error occurs */ private String getNextWord() throws IOException, ParseException { int type = tokenizer.nextToken(); switch (type) { case StreamTokenizer.TT_WORD: String word = tokenizer.sval; if (word.equalsIgnoreCase(EMPTY)) return EMPTY; return word; case '(': return L_PAREN; case ')': return R_PAREN; case ',': return COMMA; } parseError("word"); return null; }
/** * Returns the next EMPTY or L_PAREN in the stream as uppercase text. * *@return the next EMPTY or L_PAREN in the stream as uppercase text. *@throws ParseException * if the next token is not EMPTY or L_PAREN *@throws IOException * if an I/O error occurs */ private String getNextEmptyOrOpener() throws IOException, ParseException { String nextWord = getNextWord(); if (nextWord.equals(EMPTY) || nextWord.equals(L_PAREN)) { return nextWord; } parseError(EMPTY + " or " + L_PAREN); return null; }
/** * Returns the next R_PAREN or COMMA in the stream. * *@return the next R_PAREN or COMMA in the stream *@throws ParseException * if the next token is not R_PAREN or COMMA *@throws IOException * if an I/O error occurs */ private String getNextCloserOrComma() throws IOException, ParseException { String nextWord = getNextWord(); if (nextWord.equals(COMMA) || nextWord.equals(R_PAREN)) { return nextWord; } parseError(COMMA + " or " + R_PAREN); return null; }
/** * Returns the next R_PAREN in the stream. * *@return the next R_PAREN in the stream *@throws ParseException * if the next token is not R_PAREN *@throws IOException * if an I/O error occurs */ private String getNextCloser() throws IOException, ParseException { String nextWord = getNextWord(); if (nextWord.equals(R_PAREN)) { return nextWord; } parseError(R_PAREN); return null; }
parseError("number"); return 0.0;
private Polygon readCurvePolygonText() throws IOException, ParseException { String nextToken = getNextEmptyOrOpener(); if (nextToken.equals(EMPTY)) { return geometryFactory.createPolygon(geometryFactory .createLinearRing(new Coordinate[] {}), new LinearRing[] {}); } if( !nextToken.equals( L_PAREN )){ parseError("Ring expected"); } LinearRing shell = readCurvedLinearRingText(); ArrayList holes = new ArrayList(); nextToken = getNextCloserOrComma(); while (nextToken.equals(COMMA)) { LinearRing hole = readCurvedLinearRingText(); holes.add(hole); nextToken = getNextCloserOrComma(); } LinearRing[] array = new LinearRing[holes.size()]; return geometryFactory.createPolygon(shell, (LinearRing[]) holes.toArray(array)); } /**
parseError(L_PAREN + ", CIRCULARSTRING or COMPOUNDCURVE");