/** * Return true if the variables of a ModelVariable are equal. * @param object ModelVariable to test equality. * @return true if the variables of a ModelVariable are equal. */ public boolean equals(Object object) { if (object == null) return false; if (object == this) return true; if (!(object instanceof ModelVariable)) return false; ModelVariable modelVar = (ModelVariable)object; return variable.equals(modelVar.variable); }
/** * METHOD TO DO * * @param resultSet PARAMETER TO DO * @return RETURNED VALUE TO DO * @throws SQLException EXCEPTION TO DO */ 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)); } return variables; } }
/** * Get all constraints which are variables. This * method uses the fourth element of the triple. * * @return A set containing all variable constraints. */ public Set<Variable> getVariables() { if (variables == null) { Set<Variable> v = new HashSet<Variable>(); for (int i = 0; i < 4; i++) { if (element[i] instanceof Variable && !((Variable)element[i]).getName().startsWith("_")) { v.add((Variable)element[i]); } } variables = Collections.unmodifiableSet(v); } return variables; }
/** * The text representation of the URI. * @return the text representation of the URI. */ public String toString() { return variable.toString(); }
/** * Returns the hashCode of a Variable. * @return the hashCode of a Variable. */ public int hashCode() { return variable.hashCode(); }
public static String toString(Variable[] varArray) { if (varArray == null) { return "NULL"; } StringBuffer buffer = new StringBuffer("V["); for (int i = 0; i < varArray.length; i++) { buffer.append(" "); buffer.append(varArray[i].toString()); } buffer.append(" ]"); return buffer.toString(); }
public LiteralTuples(String[] variableNames, boolean sorted) { List vars = new ArrayList(); for (int i = 0; i < variableNames.length; i++) { Variable v = new Variable(variableNames[i]); assert!vars.contains(v); vars.add(v); } init((Variable[]) vars.toArray(new Variable[0]), sorted); }
/** * Get all constraints which are variables. For back-compatibility, this * method currently ignores the fourth element of the triple. * * @return A set containing all variable constraints. */ public Set<Variable> getVariables() { if (variables == null) { Set<Variable> v = new HashSet<Variable>(); Variable e = getVariable(); if (!e.getName().startsWith("_")) v.add(e); if (element[3] instanceof Variable && !((Variable)element[3]).getName().startsWith("_")) { v.add((Variable)element[3]); } variables = Collections.unmodifiableSet(v); } return variables; }
public int getColumnIndex(Variable variable) throws TuplesException { if (variable == null) { throw new IllegalArgumentException("variable is null"); } if (variable.equals(variables[0])) { // The variable matches the one and only column. return 0; } throw new TuplesException( "variable doesn't match any column: " + variable ); }
/** * Gets the internal column number for a column with the given name * @param name The name of the column to search for. * @return The column number for the column with the given name. */ public int getInternalColumnIndex(String name) { try { return tuples.getColumnIndex(new Variable(name)); } catch (Exception te) { // TuplesException return NOT_BOUND; } }
/** * Get all constraints which are variables. This * method now uses the fourth element of the triple. * * @return A set containing all variable constraints. */ public Set<Variable> getVariables() { if (variables == null) { Set<Variable> v = new HashSet<Variable>(); Variable e = getVariable(); if (!e.getName().startsWith("_")) v.add(e); // now check the graph if (element[3] instanceof Variable && !((Variable)element[3]).getName().startsWith("_")) { v.add((Variable)element[3]); } variables = Collections.unmodifiableSet(v); } return variables; }
for (int i = 0; i < variables.length; i++) { buffer.append(variables[i]); for (int j = 0; j < (6 - variables[i].toString().length()); j++) { buffer.append(" ");
public int getColumnIndex(Variable column) throws TuplesException { // Validate "column" parameter if (column == null) { 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; } } // Couldn't find the requested variable throw new TuplesException("No such column " + column); }
/** * Gets the variables name of the answer object - starting at 0. * * @param column the column number columns start at 0. * @return the {@link Variable}s bound within this answer. * @throws TuplesException if there was an error accessing the variable. */ 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); } }
/** * Return the column with a given name. This only applies to variables. * @see org.mulgara.resolver.GlobalizedAnswer#getObject(java.lang.String) * @return The bound value for the variable column with that name, or <code>null</code> * if that variable is unbound. * @throws TuplesException If there is no variable with that name. */ public Object getObject(String columnName) throws TuplesException { for (Variable v: unboundVars) if (v.getName().equals(columnName)) return null; for (Variable v: variables) if (v.getName().equals(columnName)) return super.getObject(super.getColumnIndex(v)); throw new TuplesException("Variable not found"); }