📄 tscolumn.java
字号:
floatValue = (float)0.0;
} else {
if ( argColumn.type == Types.INTEGER )
floatValue += new Integer(argColumn.intValue).floatValue();
else
floatValue += argColumn.floatValue;
}
}
} else if ( functionName.equals("MAX") | functionName.equals("MIN") ) {
argColumn = (tsColumn)functionArgs.elementAt(0);
argColumn.updateFunctions();
if ( argColumn.isValueSet() ) valueSet = true;
if ( argColumn.notNull )
{
notNull = true;
if ( argColumn.type == Types.CHAR | argColumn.type == Types.DATE )
{
if ( stringValue == null )
{
stringValue = argColumn.stringValue;
} else {
/*
* Update the max and min based upon string comparisions.
*/
if ( functionName.equals("MAX") &
( argColumn.stringValue.compareTo(stringValue) > 0 ) )
{
stringValue = argColumn.stringValue;
} else if ( functionName.equals("MIN") &
( argColumn.stringValue.compareTo(stringValue) < 0 ) ) {
stringValue = argColumn.stringValue;
}
}
} else if ( argColumn.type == Types.INTEGER ) {
/*
* Update max and min based upon numeric values.
*/
if ( intValue == Integer.MIN_VALUE )
{
intValue = argColumn.intValue;
} else {
if ( functionName.equals("MIN") &
argColumn.intValue < intValue )
intValue = argColumn.intValue;
else if ( functionName.equals("MAX") &
argColumn.intValue > intValue )
intValue = argColumn.intValue;
}
} else if ( argColumn.type == Types.FLOAT ) {
if ( floatValue == Float.MIN_VALUE )
{
floatValue = argColumn.floatValue;
} else {
if ( functionName.equals("MIN") &
argColumn.floatValue < floatValue )
floatValue = argColumn.floatValue;
else if ( functionName.equals("MAX") &
argColumn.floatValue > floatValue )
floatValue = argColumn.floatValue;
}
}
}
}
}
public boolean isGroupedColumn()
{
return groupedColumn;
}
public boolean isValueSet()
{
return valueSet;
}
public boolean isNotNull()
{
return notNull;
}
public boolean isNull()
{
return !notNull;
}
/*
* The following function compares this column to the input using
* a "like" comparison using % as the wildcard.
*/
public boolean like(tsColumn inputColumn) throws tinySQLException
{
FieldTokenizer ft;
String nextField,firstField,lastField;
boolean like;
int foundAt;
if ( !Utils.isCharColumn(type) | !Utils.isCharColumn(inputColumn.type) )
throw new tinySQLException("Column " + name + " or "
+ inputColumn.name + " is not character.");
ft = new FieldTokenizer(inputColumn.stringValue,'%',true);
like = true;
foundAt = 0;
firstField = (String)null;
lastField = (String)null;
while ( ft.hasMoreFields() )
{
nextField = ft.nextField();
lastField = nextField;
/*
* If the first matching field is not the wildcare character
* then the test field must start with this string.
*/
if ( firstField == (String)null )
{
firstField = nextField;
if ( !firstField.equals("%") & !stringValue.startsWith(firstField) )
{
like = false;
break;
}
}
if ( !nextField.equals("%") )
{
if ( stringValue.indexOf(nextField,foundAt) < 0 )
{
like = false;
break;
}
foundAt = stringValue.indexOf(nextField,foundAt) + 1;
}
}
if ( !lastField.equals("%") & !stringValue.endsWith(lastField) )
like = false;
if ( tinySQLGlobals.DEBUG )
System.out.println("Is " + getString() + " like " +
inputColumn.getString() + " ? " + like);
return like;
}
public Object clone() throws CloneNotSupportedException
{
return super.clone();
}
public int compareTo(Object inputObj) throws tinySQLException
{
String thisString,inputString,thisYMD,inputYMD;
tsColumn inputColumn;
tsRow inputRow;
int i,inputType,returnValue;
double thisValue,inputValue;
inputColumn = (tsColumn)inputObj;
inputType = inputColumn.type;
thisValue = Double.MIN_VALUE;
inputValue = Double.MIN_VALUE;
returnValue = 0;
if ( Utils.isCharColumn(type) )
{
/*
* Compare character types.
*/
if ( !Utils.isCharColumn(inputType) )
{
throw new tinySQLException("Type mismatch between "
+ getString() + " and " + inputColumn.getString());
} else if ( stringValue == (String)null |
inputColumn.stringValue == (String)null ) {
throw new tinySQLException("One of the values is NULL");
} else {
returnValue = stringValue.compareTo(inputColumn.stringValue);
}
} else if ( Utils.isDateColumn(type) ) {
/*
* Compare date types.
*/
if ( !Utils.isDateColumn(inputType) )
{
throw new tinySQLException("Type mismatch between "
+ getString() + " and " + inputColumn.getString());
} else if ( stringValue == (String)null |
inputColumn.stringValue == (String)null ) {
throw new tinySQLException("One of the values is NULL");
} else {
inputYMD = UtilString.toStandardDate(inputColumn.stringValue);
thisYMD = UtilString.toStandardDate(stringValue);
returnValue = thisYMD.compareTo(inputYMD);
}
} else if ( Utils.isNumberColumn(type) ) {
if ( type == Types.INTEGER ) thisValue = (double)intValue;
else if ( type == Types.FLOAT ) thisValue = (double)floatValue;
if ( inputType == Types.INTEGER )
inputValue = (double)inputColumn.intValue;
else if ( inputType == Types.FLOAT )
inputValue = (double)inputColumn.floatValue;
if ( thisValue > inputValue ) returnValue = 1;
else if ( thisValue < inputValue ) returnValue = -1;
} else {
System.out.println("Cannot sort unknown type");
}
if ( tinySQLGlobals.DEBUG )
System.out.println("Comparing " + getString() + " to " +
inputColumn.getString() + " gave " + returnValue);
return returnValue;
}
public void addContext(String inputContext)
{
if ( inputContext != (String)null )
{
contextList.addElement(inputContext);
}
}
/*
* This method checks to see if the column has the specified context.
*/
public String contextToString()
{
StringBuffer outputBuffer = new StringBuffer();
int i;
for ( i = 0; i < contextList.size(); i++ )
{
if ( i > 0 ) outputBuffer.append(",");
outputBuffer.append((String)contextList.elementAt(i));
}
return outputBuffer.toString();
}
/*
* This method returns the list of contexts as a string
*/
public boolean getContext(String inputContext)
{
String nextContext;
int i;
for ( i = 0; i < contextList.size(); i++ )
{
nextContext = (String)contextList.elementAt(i);
if ( nextContext == (String)null ) continue;
if ( nextContext.equals(inputContext) ) return true;
}
return false;
}
/*
* This method returns the value of the column as a string
*/
public String getString()
{
if ( !notNull ) return "null";
if ( type == Types.CHAR | type == Types.DATE | type == -1 ) {
return stringValue;
} else if ( type == Types.INTEGER ) {
if ( intValue == Integer.MIN_VALUE ) return (String)null;
return Integer.toString(intValue);
} else if ( type == Types.FLOAT ) {
if ( floatValue == Float.MIN_VALUE ) return (String)null;
return Float.toString(floatValue);
}
return (String)null;
}
public String toString()
{
int i;
StringBuffer outputBuffer = new StringBuffer();
if ( functionName == (String)null )
{
outputBuffer.append("-----------------------------------" + newLine
+ "Column Name: " + name + newLine
+ "Table: " + tableName + newLine
+ "IsNotNull: " + notNull + newLine
+ "valueSet: " + valueSet + newLine
+ "IsConstant: " + isConstant + newLine
+ "Type: " + type + newLine
+ "Size: " + size + newLine
+ "Context: " + contextToString() + newLine
+ "Value: " + getString());
} else {
outputBuffer.append("Function: " + functionName + newLine
+ "IsNotNull: " + notNull + newLine
+ "Type: " + type + newLine
+ "Size: " + size + newLine
+ "Value: " + getString());
for ( i = 0; i < functionArgs.size(); i++ )
{
outputBuffer.append(newLine + "Argument " + i + " follows" + newLine
+ ((tsColumn)functionArgs.elementAt(i)).toString() + newLine);
}
}
return outputBuffer.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -