1 package com.calipso.reportgenerator.reportcalculator; 2 3 import com.calipso.reportgenerator.common.InfoException; 4 5 import java.util.Iterator ; 6 import java.util.ArrayList ; 7 import java.util.Collection ; 8 9 15 public class BlockMatrix extends CollectionMatrix { 16 17 private int size; 18 private String baseFileName; 19 private ArrayList blocksFileNames = new ArrayList (); 20 private CollectionMatrix usedPart = new CollectionMatrix(); 21 private int blockSize; 22 private int index; 23 private boolean isSerialized = false; 26 27 public BlockMatrix(int blockSize, String baseFileName){ 28 this.blockSize = blockSize; 29 this.baseFileName = baseFileName; 30 } 31 32 public int size() { 33 return size; 34 } 35 36 public void add(Object [] row) throws InfoException { 37 size++; 38 if(usedPart.size() < blockSize){ 39 usedPart.add(row); 40 }else{ 41 serialize(usedPart); 42 usedPart = new CollectionMatrix(); 43 usedPart.add(row); 44 } 45 } 46 47 private void serialize(CollectionMatrix usedPart) { 48 String fileName = getFileName(); 49 blocksFileNames.add(index, fileName); 50 BlockSerializerThread blockSerializerThread = new BlockSerializerThread(fileName, usedPart); 51 blockSerializerThread.setPriority(Thread.NORM_PRIORITY - 2); 52 blockSerializerThread.start(); 53 index++; 54 } 55 56 private String getFileName() { 57 return baseFileName + "_" + index; 58 } 59 60 public Iterator iterator() throws InfoException { 61 try{ 62 if(!isSerialized){ 63 serialize(usedPart); 64 isSerialized = true; 65 } 66 System.gc(); 67 return new BlockMatrixIterator(this); 68 }catch(Exception e){ 69 throw new InfoException(e); 70 } 71 } 72 73 public boolean isEmpty() { 74 return blocksFileNames.size() == 0; 75 } 76 77 public ArrayList getFileNames() { 78 return blocksFileNames; 79 } 80 81 public String getFileName(int index) { 82 return (String )blocksFileNames.get(index); 83 } 84 85 public int getRowCount() { 86 return size; 87 } 88 89 public Object getValueAt(int i, int i1) throws IndexOutOfBoundsException { 90 throw new NoSuchMethodError (); 92 } 93 94 public Collection getColumValues(int i) throws IndexOutOfBoundsException { 95 throw new NoSuchMethodError (); 97 } 98 99 public Collection getRowValues(int i) throws IndexOutOfBoundsException { 100 throw new NoSuchMethodError (); 102 } 103 104 public void updateValueAt(int i, int i1, Object object) throws IndexOutOfBoundsException { 105 throw new NoSuchMethodError (); 107 } 108 109 } 110 | Popular Tags |