From 6f8ff70a79490691e1ced06611ed3c71729b7226 Mon Sep 17 00:00:00 2001
From: Mark Taylor <m.b.taylor@bristol.ac.uk>
Date: Tue, 19 May 2015 12:31:08 +0100
Subject: [PATCH] replace references to since-J2SE6 methods in ADQL lib

Replace uses of String.isEmpty and Arrays.copyOf methods
(both introduced in java 6) with equivalent code that makes
use of only methods available in the java 5 runtime.
This allows the ADQL library, if cross-compiled for java 5,
to run without errors on a java 5 runtime.
---
 src/adql/db/DBChecker.java                                | 7 +++++--
 src/adql/db/exception/UnresolvedIdentifiersException.java | 8 ++++----
 src/adql/parser/ADQLParser.java                           | 2 +-
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/adql/db/DBChecker.java b/src/adql/db/DBChecker.java
index 92a59e5..5aeefc4 100644
--- a/src/adql/db/DBChecker.java
+++ b/src/adql/db/DBChecker.java
@@ -215,7 +215,9 @@ public class DBChecker implements QueryChecker {
 					tmp[cnt++] = udf;
 			}
 			// make a copy of the array:
-			this.allowedUdfs = Arrays.copyOf(tmp, cnt, FunctionDef[].class);
+                        this.allowedUdfs = new FunctionDef[cnt];
+                        System.arraycopy(tmp, 0, this.allowedUdfs, 0, cnt);
+
 			tmp = null;
 			// sort the values:
 			Arrays.sort(this.allowedUdfs);
@@ -318,7 +320,8 @@ public class DBChecker implements QueryChecker {
 		}
 
 		// Make an adjusted array copy:
-		String[] copy = Arrays.copyOf(tmp, cnt);
+		String[] copy = new String[cnt];
+                System.arraycopy(tmp, 0, copy, 0, cnt);
 
 		// Sort the values:
 		Arrays.sort(copy);
diff --git a/src/adql/db/exception/UnresolvedIdentifiersException.java b/src/adql/db/exception/UnresolvedIdentifiersException.java
index 2a6c89c..7a7ef3b 100644
--- a/src/adql/db/exception/UnresolvedIdentifiersException.java
+++ b/src/adql/db/exception/UnresolvedIdentifiersException.java
@@ -66,15 +66,15 @@ public class UnresolvedIdentifiersException extends ParseException implements It
 			exceptions.add(pe);
 			if (pe instanceof UnresolvedColumnException){
 				String colName = ((UnresolvedColumnException)pe).getColumnName();
-				if (colName != null && !colName.trim().isEmpty())
+				if (colName != null && colName.trim().length()>0)
 					addIdentifierName(colName + " " + pe.getPosition());
 			}else if (pe instanceof UnresolvedTableException){
 				String tableName = ((UnresolvedTableException)pe).getTableName();
-				if (tableName != null && !tableName.trim().isEmpty())
+				if (tableName != null && tableName.trim().length()>0)
 					addIdentifierName(tableName + " " + pe.getPosition());
 			}else if (pe instanceof UnresolvedFunctionException){
 				String fctName = (((UnresolvedFunctionException)pe).getFunction() == null) ? null : ((UnresolvedFunctionException)pe).getFunction().getName() + "(...)";
-				if (fctName != null && !fctName.trim().isEmpty())
+				if (fctName != null && fctName.trim().length()>0)
 					addIdentifierName(fctName /*+ " " + pe.getPosition()*/);	// TODO Add the position of the function in the ADQL query!
 			}else if (pe instanceof UnresolvedIdentifiersException)
 				addIdentifierName(((UnresolvedIdentifiersException)pe).unresolvedIdentifiers);
@@ -87,7 +87,7 @@ public class UnresolvedIdentifiersException extends ParseException implements It
 	 * @param name	Name (or description) of the identifier to add.
 	 */
 	private final void addIdentifierName(final String name){
-		if (name != null && !name.trim().isEmpty()){
+		if (name != null && name.trim().length()>0){
 			if (unresolvedIdentifiers == null)
 				unresolvedIdentifiers = "";
 			else
diff --git a/src/adql/parser/ADQLParser.java b/src/adql/parser/ADQLParser.java
index b454aad..c992291 100644
--- a/src/adql/parser/ADQLParser.java
+++ b/src/adql/parser/ADQLParser.java
@@ -398,7 +398,7 @@ public class ADQLParser implements ADQLParserConstants {
 
 		try{
 
-			if (file == null || file.isEmpty())
+			if (file == null || file.length()==0)
 				parser = new ADQLParser(System.in);
 			else if (file.matches(urlRegex))
 				parser = new ADQLParser((new java.net.URL(file)).openStream());
-- 
GitLab