package com.zky.pub; import java.io.Serializable; import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; import java.util.Vector; /** * * @author dy * */ public class HashFmlBuf implements Serializable { private Hashtable hm = new Hashtable(); private String Key = ""; private String Value = ""; private int RowCount = -1; private int ResultRowCount = -1;//最终结果行数,自己手工设置 public Vector keys(int row) { Enumeration tmp; String tk = ""; Vector res = new Vector(); if (row > RowCount || row <= 0) return null; tmp = hm.keys(); while (tmp.hasMoreElements()) { tk = (String) tmp.nextElement(); int p = tk.indexOf("_" + String.valueOf(row)); if (p != -1) { res.add(tk.substring(0, p)); } } return res; } private void fdel(String field, int pos) { Key = new StringBuffer(field.trim()).append("_").append( Integer.toString(pos)).toString(); hm.remove(Key); } /** * 该方法模拟的tuxedo FML 函数中的 Fchg * * @param field * @param pos * @param value */ public void fchg(String field, int pos, String value) { Key = new StringBuffer((field.toUpperCase()).trim()).append("_") .append(Integer.toString(pos)).toString(); hm.put(Key, Common.convertNull(value)); if (pos >= RowCount) { RowCount = pos + 1; } } /** * 该方法模拟的tuxedo FML 函数中的 Fget * * @param field * @param pos * @return String * @throws FieldNotFoundException */ public String fget(String field, int pos) /* throws FieldNotFoundException */{ Key = new StringBuffer((field.toUpperCase()).trim()).append("_") .append(Integer.toString(pos)).toString(); Value = (String) hm.get(Key); return Value; } /** * 该方法模拟的tuxedo FML 函数中的 Finit * */ public void finit() { hm.clear(); } /** * 搜索一个域中是否存在某个值 * * @param field * @param value * @return -1表示没有搜索到 否则返回该值所在的行数 */ public int find(String field, String value) { int i; field = field.toUpperCase(); for (i = 0; i < RowCount; i++) { Key = new StringBuffer(field.trim()).append("_").append( Integer.toString(i)).toString(); Value = (String) hm.get(Key); if (Value == null) { continue; } if (Value.equals(value)) { return i; } } return -1; } public int find(String field) { int i; int ret = 0; for (i = 0; i < RowCount; i++) { Key = new StringBuffer(field.trim()).append("_").append( Integer.toString(i)).toString(); Value = (String) hm.get(Key); if (Value == null) { ret = 0; continue; } ret = 1; } return ret; } public void setRowCount(int rc) { this.RowCount = rc; } public int getRowCount() { return RowCount; } public void setResultRowCount(int rc) { this.ResultRowCount = rc; } public int getResultRowCount() { return ResultRowCount; } public void add(String train_address, Object query) { } }