Coverage Report - org.wiztools.xml2spreadsheet.poiimpl.POIColor
 
Classes in this File Line Coverage Branch Coverage Complexity
POIColor
91% 
100% 
0
 
 1  
 /*
 2  
  * POIColor.java
 3  
  *
 4  
  * Created on April 11, 2005, 4:32 PM
 5  
  */
 6  
 
 7  
 package org.wiztools.xml2spreadsheet.poiimpl;
 8  
 
 9  
 import org.wiztools.xml2spreadsheet.exception.OperationException;
 10  
 import java.util.ArrayList;
 11  
 import java.util.Collection;
 12  
 import java.util.HashMap;
 13  
 import java.util.Map;
 14  
 import java.util.Set;
 15  
 import org.apache.poi.hssf.util.HSSFColor;
 16  
 
 17  
 /**
 18  
  *
 19  
  * @author subhash
 20  
  */
 21  
 public final class POIColor {
 22  
     
 23  
     private static POIColor poiColor;
 24  
     private Map<String, Integer> colorMap;
 25  
     private Collection<String> colorNames;
 26  
     
 27  
     /** Creates a new instance of POIColor */
 28  19
     private POIColor() {
 29  19
     }
 30  
     
 31  
     public static synchronized POIColor getInstance(){
 32  274
         if(poiColor == null){
 33  19
             poiColor = new POIColor();
 34  19
             poiColor.populateColor();
 35  
         }
 36  274
         return poiColor;
 37  
     }
 38  
     
 39  
     private void populateColor(){
 40  19
         colorMap = new HashMap<String, Integer>();
 41  19
         colorNames = new ArrayList<String>();
 42  19
         Map m = HSSFColor.getIndexHash();
 43  19
         Set s = m.keySet();
 44  19
         for(Object o: s){
 45  1045
             String className = m.get(o).getClass().getName();
 46  
             // Example className: org.apache.poi.hssf.util.HSSFColor$DARK_RED
 47  
             // For the above example, the color name would be: dark_red
 48  1045
             className = className.split("\\$")[1].toLowerCase();
 49  1045
             colorNames.add(className);
 50  1045
             colorMap.put(className ,(Integer)o);
 51  1045
         }
 52  19
     }
 53  
     
 54  
     public Collection<String> getSupportedColors(){
 55  0
         return colorNames;
 56  
     }
 57  
     
 58  
     public short getColor(final String str) throws OperationException{
 59  274
         Integer i = colorMap.get(str);
 60  274
         if(i == null){
 61  0
             throw new OperationException("Color value not found: "+str);
 62  
         }
 63  274
         return (short)i.intValue();
 64  
     }
 65  
 }
 66