/** * Returns true and moves to the next token if the current token matches the open list token. * * @return True if the current token matches the open list token, false otherwise. */ protected boolean matchesOpenList() { if (currentToken == getWktVariant().getOpenList()) { nextToken(); return true; } return false; }
/** * Returns the value of the current token and moves to the next token if the current token matches a number. * * @return The value of the current token if the current token matches a number. * @throws WktDecodeException if the current token does not match a number. */ protected double decodeNumber() { if (currentToken instanceof WktNumberToken) { double value = ((WktNumberToken) currentToken).getNumber(); nextToken(); return value; } throw new WktDecodeException("Expected a number ; received " + currentToken.toString()); }
/** * Returns the text and moves to the next token if the current token matches text, otherwise throws an exception. * * @return the matched text * @throws WktDecodeException when the current token does not match text. */ protected String decodeText() { if (currentToken instanceof WktTextToken) { String text = ((WktTextToken) currentToken).getText(); nextToken(); return text; } throw new WktDecodeException("Expected text token, received " + currentToken.toString()); }
/** * Returns true and moves to the next token if the current token matches the close list token. * * @return True if the current token matches the close list token, false otherwise. */ protected boolean matchesCloseList() { if (currentToken == getWktVariant().getCloseList()) { nextToken(); return true; } return false; }
protected int decodeInt() { if (currentToken instanceof WktNumberToken) { double num = ((WktNumberToken) currentToken).getNumber(); nextToken(); try { return (int)num; } catch (Exception e) { throw new WktDecodeException("Expected Integer, received " + currentToken.toString()); } } else if (currentToken instanceof WktTextToken) { String text = ((WktTextToken) currentToken).getText(); nextToken(); try { return Integer.parseInt(text); } catch (NumberFormatException e) { throw new WktDecodeException("Expected Integer, received " + currentToken.toString()); } } throw new WktDecodeException("Expected text token, received " + currentToken.toString()); }
/** * Returns true and moves to the next token if the current token matches the element separator token. * * @return True if the current token matches the element separator token, false otherwise. */ protected boolean matchesElementSeparator() { if (currentToken == getWktVariant().getElementSeparator()) { nextToken(); return true; } return false; }