/** * @param s Definition of the polygon in PostgreSQL's syntax * @throws SQLException on conversion failure */ public void setValue(String s) throws SQLException { PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(s), ','); int npoints = t.getSize(); points = new PGpoint[npoints]; for (int p = 0; p < npoints; p++) { points[p] = new PGpoint(t.getToken(p)); } }
/** * Removes ( and ) from the beginning and end of a string. * * @param s String to remove from * @return String without the ( or ) */ public static String removePara(String s) { return remove(s, "(", ")"); }
/** * @param s definition of the circle in PostgreSQL's syntax. * @throws SQLException on conversion failure */ @Override public void setValue(String s) throws SQLException { PGtokenizer t = new PGtokenizer(PGtokenizer.removeAngle(s), ','); if (t.getSize() != 2) { throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", type, s), PSQLState.DATA_TYPE_MISMATCH); } try { center = new PGpoint(t.getToken(0)); radius = Double.parseDouble(t.getToken(1)); } catch (NumberFormatException e) { throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", type, s), PSQLState.DATA_TYPE_MISMATCH, e); } }
/** * <p>This returns a new tokenizer based on one of our tokens.</p> * * <p>The geometric datatypes use this to process nested tokens (usually PGpoint).</p> * * @param n Token number ( 0 ... getSize()-1 ) * @param delim The delimiter to use * @return A new instance of PGtokenizer based on the token */ public PGtokenizer tokenizeToken(int n, char delim) { return new PGtokenizer(getToken(n), delim); }
/** * @param s Definition of this point in PostgreSQL's syntax * @throws SQLException on conversion failure */ @Override public void setValue(String s) throws SQLException { PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(s), ','); try { x = Double.parseDouble(t.getToken(0)); y = Double.parseDouble(t.getToken(1)); } catch (NumberFormatException e) { throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", type, s), PSQLState.DATA_TYPE_MISMATCH, e); } }
/** * This method sets the value of this object. It should be overidden, * but still called by subclasses. * * @param value a string representation of the value of the object * @exception SQLException thrown if value is invalid for this type */ public void setValue(String value) throws SQLException { PGtokenizer t = new PGtokenizer(value, ','); if (t.getSize() != 2) throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", new Object[]{type,value}), PSQLState.DATA_TYPE_MISMATCH); point[0] = new PGpoint(t.getToken(0)); point[1] = new PGpoint(t.getToken(1)); }
PGtokenizer t = new PGtokenizer( v, ':' ); if( ( t.getSize() == 6 ) || ( t.getSize() == 2 ) ) t = new PGtokenizer( v, '-' ); if( ( t.getSize() == 2 ) || ( t.getSize() == 6 ) ) t = new PGtokenizer( v, '.' ); if( t.getSize() == 3 )
private String trimMoney(String s) { if (s == null) { return null; } // if we don't have at least 2 characters it can't be money. if (s.length() < 2) { return s; } // Handle Money char ch = s.charAt(0); // optimise for non-money type: return immediately with one check // if the first char cannot be '(', '$' or '-' if (ch > '-') { return s; } if (ch == '(') { s = "-" + PGtokenizer.removePara(s).substring(1); } else if (ch == '$') { s = s.substring(1); } else if (ch == '-' && s.charAt(1) == '$') { s = "-" + s.substring(2); } return s; }
/** * <p>Create a tokeniser.</p> * * <p>We could have used StringTokenizer to do this, however, we needed to handle nesting of '(' ')' * '[' ']' '<' and '>' as these are used by the geometric data types.</p> * * @param string containing tokens * @param delim single character to split the tokens */ public PGtokenizer(String string, char delim) { tokenize(string, delim); }
/** * This method sets the value of this object. It should be overidden, but still called by * subclasses. * * @param value a string representation of the value of the object * @throws SQLException thrown if value is invalid for this type */ @Override public void setValue(String value) throws SQLException { PGtokenizer t = new PGtokenizer(value, ','); if (t.getSize() != 2) { throw new PSQLException( GT.tr("Conversion to type {0} failed: {1}.", type, value), PSQLState.DATA_TYPE_MISMATCH); } point[0] = new PGpoint(t.getToken(0)); point[1] = new PGpoint(t.getToken(1)); }
/** * @param s Definition of this point in PostgreSQL's syntax * @exception SQLException on conversion failure */ public void setValue(String s) throws SQLException { PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(s), ','); try { x = Double.valueOf(t.getToken(0)).doubleValue(); y = Double.valueOf(t.getToken(1)).doubleValue(); } catch (NumberFormatException e) { throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", new Object[]{type,s}), PSQLState.DATA_TYPE_MISMATCH, e); } }
public PGtokenizer tokenizeToken(int n, char delim) { return new PGtokenizer(getToken(n), delim); }
public void setValue(String s) throws SQLException { try { String s1; boolean negative; negative = (s.charAt(0) == '('); // Remove any () (for negative) & currency symbol s1 = PGtokenizer.removePara(s).substring(1); // Strip out any , in currency int pos = s1.indexOf(','); while (pos != -1) { s1 = s1.substring(0, pos) + s1.substring(pos + 1); pos = s1.indexOf(','); } val = Double.parseDouble(s1); val = negative ? -val : val; } catch (NumberFormatException e) { throw new PSQLException(GT.tr("Conversion of money failed."), PSQLState.NUMERIC_CONSTANT_OUT_OF_RANGE, e); } }
public PGtokenizer(String string, char delim) { tokenize(string, delim); }
/** * @param s Definition of the polygon in PostgreSQL's syntax * @exception SQLException on conversion failure */ public void setValue(String s) throws SQLException { PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(s), ','); int npoints = t.getSize(); points = new PGpoint[npoints]; for (int p = 0;p < npoints;p++) points[p] = new PGpoint(t.getToken(p)); }
/** * This parameter takes a string representation of an inet address with * optional netmask and returns the host portion without the netmask * as a string. * * @param v The full network address with optional /netmask. addr/netmask * @return The addr portion of the string with the optional netmask removed. * @exception PSQLException This is thrown if the string v is not a valid * network address. */ protected String getHostPortion( String v ) throws PSQLException { PGtokenizer t = new PGtokenizer( v, '/' ); int size = t.getSize(); if( ( size != 1 ) && ( size != 2 ) ) { throw( new PSQLException( GT.tr( "Conversion to type {0} failed: {1}.", new Object[]{ type, v } ), PSQLState.DATA_TYPE_MISMATCH ) ); } return( t.getToken( 0 ) ); }
/** * @param s definition of the circle in PostgreSQL's syntax. * @exception SQLException on conversion failure */ public void setValue(String s) throws SQLException { PGtokenizer t = new PGtokenizer(PGtokenizer.removeAngle(s), ','); if (t.getSize() != 2) throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", new Object[]{type,s}), PSQLState.DATA_TYPE_MISMATCH); try { center = new PGpoint(t.getToken(0)); radius = Double.valueOf(t.getToken(1)).doubleValue(); } catch (NumberFormatException e) { throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", new Object[]{type,s}), PSQLState.DATA_TYPE_MISMATCH, e); } }
/** * @param s Definition of this point in PostgreSQL's syntax * @exception SQLException on conversion failure */ public void setValue(String s) throws SQLException { PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(s), ','); try { x = Double.valueOf(t.getToken(0)).doubleValue(); y = Double.valueOf(t.getToken(1)).doubleValue(); } catch (NumberFormatException e) { throw new PSQLException(GT.tr("Conversion to type {0} failed: {1}.", new Object[]{type,s}), PSQLState.DATA_TYPE_MISMATCH, e); } }
/** * Removes [ and ] from the beginning and end of all tokens. */ public void removeBox() { remove("[", "]"); }
public PGtokenizer tokenizeToken(int n, char delim) { return new PGtokenizer(getToken(n), delim); }