📄 generalaggregatevo.java
字号:
package quanquanqi;
import java.util.*;
import java.io.*;
//
public class GeneralAggregateVO implements Serializable
{
Vector rows = new Vector();//所有行的Vector,包含一组对象,每个对象是一个表示一行的Vector。
Vector currentRecord = new Vector();//当前行的Vector
Vector updateFlags = new Vector();//每行的update status
Hashtable updateCols = new Hashtable();//每行的update columns
Hashtable colKeys = new Hashtable();//列名到列号的映射
Hashtable colNums = new Hashtable();//列号到列名的映射
int currentRow = 0;//当前行号
int rowCount = 0;//maintain counts
int columnCount = 0;//maintain counts
//------------------------------------------------------------------------------
public GeneralAggregateVO()
{//构造函数
}
//------------------------------------------------------------------------------
public void setColKey(String name,int pos)
{//构造列名列号Hashtable
colKeys.put(name, new Integer(pos));
colNums.put(new Integer(pos), name);
columnCount++;
}
//------------------------------------------------------------------------------
public void setObject( int col, Object obj)
{//以列号设定列值
currentRecord.set( col, obj);
}
//----------
public void setObject( String keyName, Object obj)//重载
{//以列名设定列值
int pos = ((Integer) colKeys.get(keyName)).intValue();
setObject( pos,obj);
}
//------------------------------------------------------------------------------
public void addObject( Object obj )
{//加入对象
if ( currentRecord.size() < columnCount ) //加入对象是否超过限制的列数
currentRecord.add(obj);
else
System.out.println("Attempt to get beyond number of columns in VO.");
}
//------------------------------------------------------------------------------
public void addRow()
{//加入一行
rows.add( (Object) currentRecord );
updateFlags.add( new String( "" ) );//空白窜表示该行没有任何更新
currentRecord = new Vector();
currentRow++;//当前行下移
rowCount++;//总行增加
}
//------------------------------------------------------------------------------
public void clearCurrentRow()
{//清除当前行的内容
currentRecord.removeAllElements();
}
//------------------------------------------------------------------------------
public void deleteRow()
{//删除当前行
rows.remove(currentRow);
currentRow--;
rowCount--;
}
//------------------------------------------------------------------------------
public void appendRow()
{//在当前行后追加一行
updateFlags.add( new String( "" ) );
currentRecord =new Vector();//为新行创建一个新的Vector
for (int n=0; n < getColumnCount(); n++)//为每列创建对象
addObject( "new" );
rows.add( (Object) currentRecord );//加入尾部
rowCount++;
currentRow= rowCount-1;//当前位于最后一行,指向新加的行
updateFlags.set( getRowPos(), new String( "I" ));
}
//------------------------------------------------------------------------------
public void updateObject( int col, Object value)
{//将聚合值对象的当前行的列成员改为提供的对象引用的值,并维持正确的更新标志
HashSet colSet=null;
Integer rowPos=new Integer( getRowPos() );//储存当前行位置的变量
if ( !( getInsertStatus( getRowPos() )) )//检查行的插入状态
updateFlags.set( getRowPos(), new String("U") );//未插则执行
if (updateCols.containsKey( rowPos ) )//检查该行是否存在一组列更新标志
{
colSet= (HashSet) updateCols.get( rowPos );//检索已被更新的列的列表的Hashset
colSet.add(new Integer( col ));//把当前更新的列的整数值加入Hashset中
}
else
{
colSet= new HashSet();
colSet.add(new Integer( col ));
updateCols.put( rowPos,colSet );//添加该行的列更新标志到updateCols中
}
setObject( col, value );//更新列值
}
//------------------------------------------------------------------------------
public boolean getInsertStatus( int row )
{//返回指定行的插入状态
if ( ( (String) updateFlags.get(row) ).equals("I") )
return true;
else
return false;
}
//------------------------------------------------------------------------------
public boolean getUpdateStatus( int row, int col )
{//返回指定行和列的更新状态
boolean retVal= false;
if ( ((String) updateFlags.get(row)).toString().equals("I"))
retVal=true;
if ( ((String) updateFlags.get(row)).toString().equals("U"))
{
HashSet colSet = (HashSet) updateCols.get(new Integer(row));
retVal = colSet.contains( new Integer( col ) );
}
return retVal;
}
//------------------------------------------------------------------------------
public boolean getUpdateStatus()
{//重载,返回当前行的更新状态
if ( ((String) updateFlags.get( getRowPos() )) != null)
return true;
else
return false;
}
//------------------------------------------------------------------------------
public boolean getUpdateStatus(int row)
{//重载,返回指定行的状态
if ( ((String) updateFlags.get(row) )!=null )
return true;
else
return false;
}
//------------------------------------------------------------------------------
public int getRowCount()
{
return rowCount;
}
public int getColumnCount()
{
return columnCount;
}
public String getColumnName( int col )
{
return (String) colNums.get(new Integer(col));
}
public int getRowPos()
{
return currentRow;
}
public Object getObject( int col)
{
return currentRecord.get(col);
}
public Object getObject(String colName)
{
int pos = ((Integer) colKeys.get(colName)).intValue();
return getObject(pos);
}
//------------------------------------------------------------------------------
public void absolute( int pos )
{//绝对定位
currentRow= pos;
currentRecord= (Vector) rows.get(currentRow);
}
//------------------------------------------------------------------------------
public void relative (int pos)
{//相对定位
currentRow += pos;
currentRecord= (Vector) rows.get(currentRow);
}
//------------------------------------------------------------------------------
public void dumpContents()
{//遍历聚合值对象的内容
System.out.println("******************************************************");
System.out.println("Column Count: " + this.getColumnCount() );
System.out.println("Row Count: " + this.getRowCount() );
for (int n=0; n < this.getRowCount(); n++)
{
this.absolute(n);
System.out.println("*************************************************");
System.out.println("Row: " + n);
for (int z=0; z < this.getColumnCount(); z++)
System.out.println("Column Name: " + this.getColumnName(z) + "\t"
+"- Column Value: " + this.getObject(z) );
}
}
//------------------------------------------------------------------------------
public void clearUpdates()
{//清除聚合对象更新标志
for (int n=0; n < getRowCount(); n++)
updateFlags.set( n, new String( "" ));
}
//------------------------------------------------------------------------------
public void clear()
{//清除聚合对象内容
rows.removeAllElements();
updateFlags.removeAllElements();
currentRecord.removeAllElements();
colKeys = new Hashtable();
colNums = new Hashtable();
updateCols = new Hashtable();
currentRow = 0;
rowCount = 0;
columnCount = 0;
}
public void adeleteRow()
{//删除当前行
rows.remove(currentRow);
// currentRow++;
rowCount--;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -