[Mulgara-svn] r1073 - trunk/src/jar/query/java/org/mulgara/query
pag at mulgara.org
pag at mulgara.org
Wed Jul 9 22:15:52 UTC 2008
Author: pag
Date: 2008-07-09 15:15:51 -0700 (Wed, 09 Jul 2008)
New Revision: 1073
Modified:
trunk/src/jar/query/java/org/mulgara/query/AnswerImpl.java
Log:
Reformat and remove warnings
Modified: trunk/src/jar/query/java/org/mulgara/query/AnswerImpl.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/AnswerImpl.java 2008-07-09 04:13:06 UTC (rev 1072)
+++ trunk/src/jar/query/java/org/mulgara/query/AnswerImpl.java 2008-07-09 22:15:51 UTC (rev 1073)
@@ -68,45 +68,30 @@
*/
static final long serialVersionUID = -8022357347937695884L;
- /**
- * Description of the Field
- */
+ /** Description of the Field */
private final static TestResultSet ZERO;
- /**
- * Description of the Field
- */
+ /** Description of the Field */
public final static Answer EMPTY;
- /**
- * Logger. This is named after the class.
- */
+ /** Logger. This is named after the class. */
private final static Logger logger = Logger.getLogger(AnswerImpl.class);
static {
-
try {
ZERO = new TestResultSet(new String[] {});
EMPTY = new AnswerImpl(ZERO);
- }
- catch (TuplesException e) {
-
+ } catch (TuplesException e) {
throw new ExceptionInInitializerError(e);
- }
- catch (SQLException e) {
-
+ } catch (SQLException e) {
throw new ExceptionInInitializerError(e);
}
}
- /**
- * The columns of the result set.
- */
+ /** The columns of the result set. */
public Variable[] variables;
- /**
- * The wrapped {@link ResultSet}.
- */
+ /** The wrapped {@link ResultSet}. */
private ResultSet resultSet;
/**
@@ -119,23 +104,18 @@
public AnswerImpl(Answer answer) throws TuplesException {
// Validate "answer" parameter
- if (answer == null) {
- throw new IllegalArgumentException("Null \"answer\" parameter");
- }
+ if (answer == null) throw new IllegalArgumentException("Null \"answer\" parameter");
logger.debug("Creating AnswerImpl ");
// Copy the variables
variables = answer.getVariables();
// Convert variables to column name array
String[] columnNames = new String[variables.length];
- for (int i=0; i<variables.length; i++) {
- columnNames[i] = variables[i].getName();
- }
+ for (int i=0; i<variables.length; i++) columnNames[i] = variables[i].getName();
// Copy the content
- if (logger.isDebugEnabled()) {
- logger.debug("Adding "+answer.getRowCount()+" rows");
- }
+ if (logger.isDebugEnabled()) logger.debug("Adding "+answer.getRowCount()+" rows");
+
try {
resultSet = new TestResultSet(columnNames);
answer.beforeFirst();
@@ -166,18 +146,14 @@
throw re;
}
logger.debug("Adding a row");
- ((TestResultSet) resultSet).addRow(
- new ResultSetRow(columnNames, columnValues)
- );
+ ((TestResultSet)resultSet).addRow(new ResultSetRow(columnNames, columnValues));
}
logger.debug("Finished iterating answer");
} catch (SQLException e) {
logger.warn("Failed to copy content", e);
throw new TuplesException("Couldn't copy answer", e);
}
- if (logger.isDebugEnabled()) {
- logger.warn("Completed construction of " + getRowCount() + " rows");
- }
+ if (logger.isDebugEnabled()) logger.warn("Completed construction of " + getRowCount() + " rows");
}
/**
@@ -187,22 +163,18 @@
* @param variableList a list of {@link Variable}s
* @throws IllegalArgumentException if <var>variableList</var> is <code>null</code>
*/
- public AnswerImpl(List variableList) {
+ public AnswerImpl(List<Variable> variableList) {
String[] columns = new String[variableList.size()];
int j = 0;
- for (Iterator i = variableList.iterator(); i.hasNext(); j++) {
-
- columns[j++] = ( (Variable) i.next()).getName();
+ for (Iterator<Variable> i = variableList.iterator(); i.hasNext(); j++) {
+ columns[j++] = i.next().getName();
}
try {
-
resultSet = new TestResultSet(columns);
- }
- catch (SQLException e) {
-
+ } catch (SQLException e) {
throw new Error("Inexplicable constructor failure", e);
}
}
@@ -215,20 +187,13 @@
*/
public AnswerImpl(ResultSet resultSet) throws TuplesException {
- if (resultSet == null) {
+ if (resultSet == null) throw new IllegalArgumentException("Null \"resultSet\" parameter");
- throw new IllegalArgumentException("Null \"resultSet\" parameter");
- }
-
try {
-
this.variables = resultSetToVariables(resultSet);
-
// this.resultSet = new TestResultSet(resultSet);
this.resultSet = resultSet;
- }
- catch (SQLException e) {
-
+ } catch (SQLException e) {
throw new TuplesException("Couldn't create answer", e);
}
}
@@ -239,16 +204,14 @@
*
*/
protected AnswerImpl() {
-
variables = new Variable[] {};
resultSet = ZERO;
}
/**
- * @deprecated The internal result set shouldn't really be exposed
- */
- public ResultSet getResultSet()
- {
+ * @deprecated The internal result set shouldn't really be exposed
+ */
+ public ResultSet getResultSet() {
return resultSet;
}
@@ -256,13 +219,11 @@
// Methods implementing the Answer interface
//
- public long getRowUpperBound() throws TuplesException
- {
+ public long getRowUpperBound() throws TuplesException {
return getRowCount();
}
- public int getRowCardinality() throws TuplesException
- {
+ public int getRowCardinality() throws TuplesException {
switch ((int)getRowCount()) {
case 0:
return Cursor.ZERO;
@@ -279,8 +240,7 @@
* @return the number of minterms (rows) in this sum of products
* @throws TuplesException if the number of rows cannot be determined
*/
- public long getRowCount() throws TuplesException
- {
+ public long getRowCount() throws TuplesException {
try {
int row = resultSet.getRow();
@@ -315,11 +275,8 @@
public Object getObject(int column) throws TuplesException {
try {
-
return resultSet.getObject(column+1);
- }
- catch (SQLException e) {
-
+ } catch (SQLException e) {
throw new TuplesException("Couldn't read field", e);
}
}
@@ -334,11 +291,8 @@
public Object getObject(String columnName) throws TuplesException {
try {
-
return resultSet.getObject(columnName);
- }
- catch (SQLException e) {
-
+ } catch (SQLException e) {
throw new TuplesException("Couldn't read field: " + columnName, e);
}
}
@@ -353,14 +307,10 @@
public Variable getVariable(int column) throws TuplesException {
try {
-
return new Variable(resultSet.getMetaData().getColumnName(column + 1));
+ } catch (SQLException e) {
+ throw new TuplesException("Couldn't get variable for column " + (column + 1), e);
}
- catch (SQLException e) {
-
- throw new TuplesException("Couldn't get variable for column " +
- (column + 1), e);
- }
}
/**
@@ -369,7 +319,6 @@
* @return the {@link Variable}s bound within this answer.
*/
public Variable[] getVariables() {
-
return variables;
}
@@ -379,14 +328,8 @@
* @return the number of variables in a tuples.
*/
public int getNumberOfVariables() {
-
int noVars = 0;
-
- if (variables != null) {
-
- noVars = variables.length;
- }
-
+ if (variables != null) noVars = variables.length;
return noVars;
}
@@ -400,7 +343,6 @@
* @throws TuplesException EXCEPTION TO DO
*/
public boolean isUnconstrained() throws TuplesException {
-
return (getVariables().length == 0) && (getRowCardinality() > Cursor.ZERO);
}
@@ -418,18 +360,11 @@
public int getColumnIndex(Variable column) throws TuplesException {
// Validate "column" parameter
- if (column == null) {
+ if (column == null) throw new IllegalArgumentException("Null \"column\" parameter");
- throw new IllegalArgumentException("Null \"column\" parameter");
- }
-
// Look for the requested variable in the "variables" array
for (int i = 0; i < variables.length; i++) {
-
- if (column.equals(variables[i])) {
-
- return i;
- }
+ if (column.equals(variables[i])) return i;
}
// Couldn't find the requested variable
@@ -437,16 +372,15 @@
}
/**
- * METHOD TO DO
+ * Reset the cursor. Calling {@link #next()} after calling this method will move to the first row.
*
- * @throws TuplesException EXCEPTION TO DO
+ * @throws TuplesException There was an error accessing the underlying data.
*/
public void beforeFirst() throws TuplesException {
try {
resultSet.beforeFirst();
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
throw new TuplesException("Couldn't rewind solution", e);
}
}
@@ -458,11 +392,9 @@
* @throws TuplesException EXCEPTION TO DO
*/
public boolean next() throws TuplesException {
-
try {
return resultSet.next();
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
throw new TuplesException("Couldn't advance cursor", e);
}
}
@@ -478,25 +410,22 @@
* @return whether <var>object</var> is equal to this instance; the order of
* both columns and rows is significant
*/
- public boolean equals(Object object)
- {
+ public boolean equals(Object object) {
// Gotta be non-null and of matching type
if ((object != null) && (object instanceof Answer)) {
try {
return AnswerOperations.equal(this, (Answer) object);
- }
- catch (TuplesException e) {
+ } catch (TuplesException e) {
logger.fatal("Couldn't test equality of answers", e);
}
}
-
return false;
}
/**
* Generate a legible representation of the answer.
*
- * @return RETURNED VALUE TO DO
+ * @return a string representation of the results.
*/
public String toString() {
@@ -504,48 +433,41 @@
}
/**
- * METHOD TO DO
+ * Creates a copy of this object and its resources.
*
- * @return RETURNED VALUE TO DO
+ * @return A new, independent copy of this object.
*/
public Object clone() {
-
try {
-
return new AnswerImpl(new TestResultSet(resultSet));
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
throw new RuntimeException(e);
- }
- catch (TuplesException e) {
+ } catch (TuplesException e) {
throw new RuntimeException(e);
}
}
/**
- * METHOD TO DO
+ * Release all resources associated with this object
*/
public void close() {
-
// resultSet = null;
// variables = null;
}
/**
- * METHOD TO DO
+ * Convert the column names of a result set to an array of Variables.
*
- * @param resultSet PARAMETER TO DO
- * @return RETURNED VALUE TO DO
- * @throws SQLException EXCEPTION TO DO
+ * @param resultSet The ResultSet to convert.
+ * @return An array of variables corresponding to the columns resultSet.
+ * @throws SQLException An error accessing the ResultSet metadata.
*/
- private Variable[] resultSetToVariables(ResultSet resultSet) throws
- SQLException {
+ private Variable[] resultSetToVariables(ResultSet resultSet) throws SQLException {
ResultSetMetaData rsmd = resultSet.getMetaData();
Variable[] variables = new Variable[rsmd.getColumnCount()];
for (int i = 0; i < rsmd.getColumnCount(); i++) {
-
variables[i] = new Variable(rsmd.getColumnName(i + 1));
}
More information about the Mulgara-svn
mailing list