Created
April 12, 2012 11:44
-
-
Save btolfa/2366735 to your computer and use it in GitHub Desktop.
GetMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package myPack; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
import java.io.FileInputStream; | |
import java.math.BigDecimal; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Set; | |
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |
import org.apache.poi.ss.usermodel.*; | |
import com.thoughtworks.xstream.XStream; | |
import com.thoughtworks.xstream.io.xml.DomDriver; | |
//создаёт представление и выводит значение по ключу для проверки | |
public class GetMap { | |
public HashMap<Integer, TypePos> genTmpHM(ObjectPars opr) | |
throws IOException { | |
HashMap<Integer, TypePos> hm = new HashMap<Integer, TypePos>(); | |
TypePos tp; | |
for (Param p : opr.getList()) { | |
tp = new TypePos(p.getX(), p.getY()); | |
hm.put(parseId(p.getId()), tp); | |
} | |
System.out.println("tempHM подготовленна.."); | |
return hm; | |
} | |
private Integer parseId(String s) { | |
int id; | |
if (s.charAt(0) == '-') { | |
id = 0; | |
} else { | |
id = Integer.parseInt(s); | |
} | |
return id; | |
} | |
private BigDecimal checkCell(Cell cl) throws FileNotFoundException, | |
IOException { | |
BigDecimal bigD = null; | |
int cellType = cl.getCellType(); | |
switch (cellType) { | |
case Cell.CELL_TYPE_STRING: | |
// System.out.print("(" + cl.getStringCellValue() + ")"); | |
System.out.print("Проскочила Стринг"); | |
break; | |
case Cell.CELL_TYPE_NUMERIC: | |
// System.out.print(cl.getNumericCellValue() + " --- "); | |
bigD = new BigDecimal(cl.getNumericCellValue()); | |
break; | |
case Cell.CELL_TYPE_FORMULA: | |
// System.out.print("[" + cl.getNumericCellValue() + "]"); | |
System.out.print("Проскочила Формула"); | |
break; | |
default: | |
// System.out.print("!"); | |
System.out.print("Проскочила Иная Вещь"); | |
break; | |
} | |
return bigD; | |
} | |
public ObjectPars xmlToClass(FileInputStream way) { | |
XStream xs = new XStream(new DomDriver()); | |
xs.autodetectAnnotations(true); | |
xs.alias("Root", ObjectPars.class); | |
ObjectPars op; | |
op = (ObjectPars) xs.fromXML(way); | |
System.out.println("xml прочитанна.."); | |
return (op); | |
} | |
@SuppressWarnings("unchecked") | |
public HashMap<Integer, BigDecimal> getMyHM(FileInputStream way, | |
HashMap<Integer, TypePos> tmpHM) throws FileNotFoundException, | |
IOException { | |
HSSFWorkbook wb = null; | |
try { | |
wb = new HSSFWorkbook(way); | |
} catch (FileNotFoundException ex) { | |
ex.printStackTrace(); | |
} | |
Sheet shtB = wb.getSheetAt(0); | |
// возвращаемый объект | |
HashMap<Integer, BigDecimal> hm = new HashMap<Integer, BigDecimal>(); | |
Set<?> st = tmpHM.entrySet(); | |
Map.Entry<Integer, TypePos> me; | |
for (Object obj : st) { | |
me = (Map.Entry<Integer, TypePos>) obj; // получить<Id,Adr> | |
Cell cl = shtB.getRow(me.getValue().getPosX() - 1).getCell( | |
me.getValue().getPosY() - 1); // взять Знач | |
hm.put(me.getKey(), checkCell(cl)); | |
// System.out.println(me.getKey()); | |
} | |
System.out.println("hm сгенерированна!!"); | |
return hm; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment