tablerow.java

来自「工厂版本管理系统,STRUTS2框架,用于管理商品的版本,便于有效的控制版本」· Java 代码 · 共 148 行

JAVA
148
字号
package com.utstar.fcs.domain.workinstruction.field;

import java.lang.reflect.Method;

public class TableRow implements Cloneable{
	private Long id;
	private TableField field = new TableField();
	private String col0;
	private String col1;
	private String col2;
	private String col3;
	private String col4;
	

	public TableRow() {

	}

	public TableRow(String... col) {
		for (int i = 0; i < col.length; i++) {
			setCol(i, col[i]);
		}
	}
	
	@Override
	protected Object clone() throws CloneNotSupportedException {
		
		TableRow tr = (TableRow)super.clone();
		tr.setId(null);
		
		
		tr.field = field;
		tr.col0 = col0;
		tr.col1 = col1;
		tr.col2 = col2;
		tr.col3 = col3;
		tr.col4 = col4;
		
		
		return tr;
	}
	
	public void loadFromString(String[] col){
		for (int i = 0; i < col.length; i++) {
			setCol(i, col[i]);
		}
	}

	public void setCol(int index, String value) {
		String methodName = String.format("setCol%d", index);
		try {
			Method method = this.getClass().getMethod(methodName, String.class);
			method.invoke(this, value);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public String getCol(int index) {
		String methodName = String.format("getCol%d", index);
		try {
			Method method = this.getClass().getMethod(methodName);
			return (String) method.invoke(this,new Object[] {});
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return null;
	}

	@Override
	public String toString() {

		return col0 + "," + col1 + "," + col2 + "," + col3 + "," + col4;
	}

	public boolean isEmpty(){
		for(int i=0;i<5;i++)
		{
			//just if any cell is not null
			if(getCol(i)!=null && getCol(i).trim().length()>0)
				return false;			
		}
	
		return true;
		
	}
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public TableField getField() {
		return field;
	}

	public void setField(TableField field) {
		this.field = field;
	}

	public String getCol1() {
		return col1;
	}

	public void setCol1(String col1) {
		this.col1 = col1;
	}

	public String getCol2() {
		return col2;
	}

	public void setCol2(String col2) {
		this.col2 = col2;
	}

	public String getCol3() {
		return col3;
	}

	public void setCol3(String col3) {
		this.col3 = col3;
	}

	public String getCol4() {
		return col4;
	}

	public void setCol4(String col4) {
		this.col4 = col4;
	}

	public String getCol0() {
		return col0;
	}

	public void setCol0(String col0) {
		this.col0 = col0;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?