System.err.println("Usage: java examples/TestParser dburl user pass");
System.exit(1);
// Signal the compiler that code flow ends here.
- throw new AssertionError();
+ return;
}
System.out.println("Driver version: " + Driver.getVersion());
- int major = Integer.parseInt(Driver.getVersion().trim().split(" ")[1].split("\\.")[0]);
+ int major = Integer.parseInt(PGgeometry.splitAtFirst(PGgeometry.splitAtFirst(Driver.getVersion().trim(),' ')[1],'.')[0]);
if (major < 8) {
System.out.println("Your pgdjbc " + major
+ ".X is too old, it does not support autoregistration!");
import org.postgis.PGbox2d;
import org.postgis.PGbox3d;
import org.postgresql.util.PGobject;
+import org.postgresql.util.PGtokenizer;
import java.sql.Connection;
import java.sql.DriverManager;
/** Our apps entry point */
public static void main(String[] args) throws SQLException, ClassNotFoundException {
- String[] dburls;
+ PGtokenizer dburls;
String dbuser = null;
String dbpass = null;
if (args.length == 1 && args[0].equalsIgnoreCase("offline")) {
System.out.println("Performing only offline tests");
- dburls = new String[0];
+ dburls = new PGtokenizer("", ';');
} else if (args.length == 3) {
System.out.println("Performing offline and online tests");
- dburls = args[0].split(";");
+
+ dburls = new PGtokenizer(args[0], ';');
dbuser = args[1];
dbpass = args[2];
} else {
System.err.println("tablename is 'jdbc_test' by default.");
System.exit(1);
// Signal the compiler that code flow ends here.
- throw new AssertionError();
+ return;
}
Connection[] conns;
- conns = new Connection[dburls.length];
- for (int i = 0; i < dburls.length; i++) {
- System.out.println("Creating JDBC connection to " + dburls[i]);
- conns[i] = connect(dburls[i], dbuser, dbpass);
+ conns = new Connection[dburls.getSize()];
+ for (int i = 0; i < dburls.getSize(); i++) {
+ System.out.println("Creating JDBC connection to " + dburls.getToken(i));
+ conns[i] = connect(dburls.getToken(i), dbuser, dbpass);
}
System.out.println("Performing tests...");
import org.postgis.Geometry;
import org.postgis.PGgeometry;
+import org.postgresql.util.PGtokenizer;
import java.sql.Connection;
import java.sql.DriverManager;
/** Our apps entry point */
public static void main(String[] args) throws SQLException, ClassNotFoundException {
- String[] dburls;
+ PGtokenizer dburls;
String dbuser = null;
String dbpass = null;
if (args.length == 1 && args[0].equalsIgnoreCase("offline")) {
System.out.println("Performing only offline tests");
- dburls = new String[0];
+ dburls = new PGtokenizer("",';');
} else if (args.length == 3) {
System.out.println("Performing offline and online tests");
- dburls = args[0].split(";");
+ dburls = new PGtokenizer(args[0],';');
+
dbuser = args[1];
dbpass = args[2];
} else {
System.err.println("tablename is 'jdbc_test' by default.");
System.exit(1);
// Signal the compiler that code flow ends here.
- throw new AssertionError();
+ return;
}
Connection[] conns;
- conns = new Connection[dburls.length];
- for (int i = 0; i < dburls.length; i++) {
- System.out.println("Creating JDBC connection to " + dburls[i]);
- conns[i] = connect(dburls[i], dbuser, dbpass);
+ conns = new Connection[dburls.getSize()];
+ for (int i = 0; i < dburls.getSize(); i++) {
+ System.out.println("Creating JDBC connection to " + dburls.getToken(i));
+ conns[i] = connect(dburls.getToken(i), dbuser, dbpass);
}
System.out.println("Performing tests...");
int srid = -1;
value = value.trim();
if (value.startsWith("SRID=")) {
- String[] temp = value.split(";", 2);
+ String[] temp = PGgeometry.splitAtFirst(value,';');
value = temp[1].trim();
srid = Integer.parseInt(temp[0].substring(5));
}
import org.postgis.binary.BinaryParser;
import org.postgresql.util.PGobject;
-import org.postgresql.util.PGtokenizer;
import java.sql.SQLException;
value = value.trim();
int srid = -1;
+
if (value.startsWith("SRID")) {
//break up geometry into srid and wkt
- PGtokenizer t = new PGtokenizer(value, ';');
- value = t.getToken(1).trim();
-
- srid = Integer.parseInt(t.getToken(0).split("=")[1]);
+ String[] parts = PGgeometry.splitAtFirst(value, ';');
+ value = parts[1];
+ srid = Integer.parseInt(PGgeometry.splitAtFirst(parts[0], '=')[1]);
}
Geometry result;
return obj;
}
+ /**
+ * Splits a String at the first occurrence of border charachter.
+ *
+ * Poor man's String.split() replacement, as String.split() was invented at
+ * jdk1.4, and the Debian PostGIS Maintainer had problems building the woody
+ * backport of his package using DFSG-free compilers. In all the cases we
+ * used split() in the org.postgis package, we only needed to split at the
+ * first occurence, and thus this code could even be faster.
+ */
+ public static String[] splitAtFirst(String whole, char border) {
+ int index = whole.indexOf(border);
+ if (index == -1) {
+ return new String[]{whole};
+ } else {
+ return new String[]{
+ whole.substring(0, index),
+ whole.substring(index + 1)};
+ }
+ }
}
\ No newline at end of file
tz = this.z - other.z;
return Math.sqrt(tx * tx + ty * ty + tz * tz);
default :
- throw new AssertionError("Illegal dimension of Point" + this.dimension);
+ throw new IllegalArgumentException("Illegal dimension of Point" + this.dimension);
}
}
}
\ No newline at end of file