83fc5830fff4a789278b7d5d1eda9710f9219e9c.svn-base 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. package UIB.UIB03.ZBS;
  2. import java.util.ArrayList;
  3. import java.util.Stack;
  4. import org.apache.commons.collections.list.TreeList;
  5. import sun.reflect.generics.tree.Tree;
  6. /**
  7. * @desc 存放数据集合,并按照存入顺序取出数据,主键可重复
  8. * 每一个DataRowList均为一个钢卷的成分(材质)与卷号、重量、交货状态等信息
  9. * @author meiguiping
  10. * @date 2010 7:41:40 PM
  11. */
  12. public class DataRowList
  13. {
  14. private ArrayList key;//主键。存储钢卷号的字段名、元素名、材质代码信息、温度、位置方向,主键不可重复。
  15. private ArrayList value;//值。钢卷号、元素值、材质实绩值
  16. private ArrayList smallName;//小中文名,材质小中文名称
  17. private ArrayList bigName;//大中文名,材质大中文名称,如屈服、抗拉统称拉力
  18. private ArrayList extCode;//补充码,扩展码,如冲击的A1,拉力的Rel,Rt0.5
  19. private int len;//存入数据长度
  20. public DataRowList()
  21. {
  22. len = 0;
  23. key = new ArrayList(10);
  24. value = new ArrayList(10);
  25. smallName = new ArrayList(10);
  26. bigName = new ArrayList(10);
  27. extCode = new ArrayList();
  28. }
  29. /**
  30. * @desc 获取录入数据长度
  31. * @return
  32. */
  33. public int size()
  34. {
  35. return len;
  36. }
  37. public void put(Object key , Object value)
  38. {
  39. try
  40. {
  41. if(null == key)
  42. {
  43. throw new Exception("DataRowList主键不可为null,请检查。");
  44. }
  45. else if("".equals(key.toString().trim()))
  46. {
  47. throw new Exception("DataRowList主键不可为空,清检查。");
  48. }
  49. else if(keyExist(key))
  50. {
  51. throw new Exception("DataRowList主键重复,请检查。");
  52. }
  53. }
  54. catch(Exception ex)
  55. {
  56. ex.printStackTrace();
  57. return;
  58. }
  59. this.key.add(key);
  60. this.value.add(value==null?"":value);
  61. this.smallName.add("");
  62. this.bigName.add("");
  63. this.extCode.add("");
  64. len++;
  65. }
  66. public void put(Object key , Object value , Object extCode)
  67. {
  68. try
  69. {
  70. if(keyExist(key))
  71. {
  72. throw new Exception("DataRowList主键重复,请检查");
  73. }
  74. }
  75. catch(Exception ex)
  76. {
  77. ex.printStackTrace();
  78. return;
  79. }
  80. this.key.add(key);
  81. this.value.add(value);
  82. this.smallName.add("");
  83. this.bigName.add("");
  84. this.extCode.add(extCode);
  85. len++;
  86. }
  87. public void put(Object key , Object value , Object smallName , Object bigName , Object extCode)
  88. {
  89. try
  90. {
  91. if(keyExist(key))
  92. {
  93. throw new Exception("DataRowList主键重复增加,请检查。");
  94. }
  95. }
  96. catch(Exception ex)
  97. {
  98. ex.printStackTrace();
  99. return;
  100. }
  101. this.key.add(key);
  102. this.value.add(value);
  103. this.smallName.add(smallName);
  104. this.bigName.add(bigName);
  105. this.extCode.add(extCode);
  106. len++;
  107. }
  108. /**
  109. * @desc 修改制定位置主键所对应的其它所有值
  110. * @param key
  111. * @param value
  112. * @param smallName
  113. * @param bigName
  114. * @param extCode
  115. */
  116. public void set(Object key , Object value , Object smallName , Object bigName , Object extCode)
  117. {
  118. int keyIndex = -1;
  119. for(int index = 0; index < len ; index++)
  120. {
  121. if(this.key.get(index).equals(key))
  122. {
  123. keyIndex = index;
  124. break;
  125. }
  126. }
  127. if(keyIndex != -1)//若主键存在,则修改value、smallName、bigName、extCode的值
  128. {
  129. this.value.set(keyIndex, value);
  130. this.smallName.set(keyIndex, smallName);
  131. this.bigName.set(keyIndex, bigName);
  132. this.extCode.set(keyIndex, extCode);
  133. }
  134. }
  135. /**
  136. * @desc 在指定位置增加
  137. * @param index
  138. * @param key
  139. * @param value
  140. * @param smallName
  141. * @param bigName
  142. * @param extCode
  143. */
  144. public void add(int index , Object key , Object value , Object smallName , Object bigName , Object extCode)
  145. {
  146. try
  147. {
  148. if(keyExist(key))
  149. {
  150. throw new Exception("DataRowList主键重复增加,请检查。");
  151. }
  152. }
  153. catch(Exception ex)
  154. {
  155. ex.printStackTrace();
  156. return;
  157. }
  158. this.key.add(index, key);
  159. this.value.add(index, value);
  160. this.smallName.add(index, smallName);
  161. this.bigName.add(index, bigName);
  162. this.extCode.add(index, extCode);
  163. len++;
  164. }
  165. /**
  166. * @desc 判断主键是否重复
  167. * @param key
  168. * @return
  169. */
  170. public boolean keyExist(Object key)
  171. {
  172. boolean flag = false;
  173. for(int i = 0 ; i < len ; i++)
  174. {
  175. if( this.key.get(i).equals(key) )
  176. {
  177. flag = true;
  178. break;
  179. }
  180. }
  181. return flag;
  182. }
  183. public Object getKey(int index)
  184. {
  185. Object o = null;
  186. try
  187. {
  188. if(index >= len )
  189. throw new Exception("DataRowList数组越界!");
  190. o = key.get(index);
  191. }catch(Exception ex)
  192. {
  193. ex.printStackTrace();
  194. }
  195. return o;
  196. }
  197. public Object getValue(int index)
  198. {
  199. Object o = null;
  200. o = value.get(index);
  201. return o;
  202. }
  203. public Object getSmallName(int index)
  204. {
  205. Object o = null;
  206. o = smallName.get(index);
  207. return o;
  208. }
  209. public Object getBigName(int index)
  210. {
  211. Object o = null;
  212. o = bigName.get(index);
  213. return o;
  214. }
  215. public Object getExtCode(int index)
  216. {
  217. Object o = null;
  218. o = extCode.get(index);
  219. return o;
  220. }
  221. public Object getValue(Object key)
  222. {
  223. Object o = null;
  224. for(int index =0; index < len ; index++)
  225. {
  226. if(key.equals(this.key.get(index)))
  227. {
  228. o = value.get(index);
  229. break;
  230. }
  231. }
  232. return o;
  233. }
  234. public Object getSmallName(Object key)
  235. {
  236. Object o = null;
  237. for(int index =0; index < len ; index++)
  238. {
  239. if(key.equals(this.key.get(index)))
  240. {
  241. o = smallName.get(index);
  242. break;
  243. }
  244. }
  245. return o;
  246. }
  247. public Object getBigName(Object key)
  248. {
  249. Object o = null;
  250. for(int index =0; index < len ; index++)
  251. {
  252. if(key.equals(this.key.get(index)))
  253. {
  254. o = bigName.get(index);
  255. break;
  256. }
  257. }
  258. return o;
  259. }
  260. public Object getExtCode(Object key)
  261. {
  262. Object o = null;
  263. for(int index =0; index < len ; index++)
  264. {
  265. if(key.equals(this.key.get(index)))
  266. {
  267. o = extCode.get(index);
  268. break;
  269. }
  270. }
  271. return o;
  272. }
  273. public void print()
  274. {
  275. for(int i = 0; i < len ; i++)
  276. {
  277. System.out.println("key="+key.get(i)+" value="+value.get(i)+" smallName="+smallName.get(i)+" bigName="+bigName.get(i)+" extCode="+extCode.get(i));
  278. }
  279. }
  280. }