1 13 package com.tonbeller.jpivot.xmla; 14 15 import com.tonbeller.jpivot.olap.model.NumberFormat; 16 import com.tonbeller.jpivot.olap.model.impl.CellBase; 17 import com.tonbeller.jpivot.util.NumSeparators; 18 19 22 public class XMLA_Cell extends CellBase { 23 24 private Object value = null; 25 private int ordinal; 26 private XMLA_Model model; 27 28 public XMLA_Cell(int ordinal,XMLA_Model model) { 30 this.model = model; 31 this.ordinal = ordinal; 32 formattedValue = "(null)"; 33 } 34 35 38 public Object getValue() { 39 return value; 40 } 41 42 46 public void setValue(Object value) { 47 this.value = value; 48 } 49 50 54 public int getOrdinal() { 55 return ordinal; 56 } 57 58 61 public boolean isNull() { 62 return (value == null); 63 } 64 65 68 public NumberFormat getFormat() { 69 71 if (this.getValue()==null) 72 return null; 73 74 if (this.getValue() instanceof Number ) { 75 } else 77 return null; 78 79 boolean isPercent = formattedValue.indexOf('%') >= 0; 80 boolean isGrouping = false; 81 NumSeparators sep = NumSeparators.instance(model.getLocale()); 82 83 int fractionDigits = 0; 84 if (formattedValue.indexOf(sep.thouSep) >= 0) 85 isGrouping = true; 86 int i = formattedValue.indexOf(sep.decimalSep); 87 if (i > 0) { 88 while (++i < formattedValue.length() && Character.isDigit(formattedValue.charAt(i))) 89 ++fractionDigits; 90 } 91 92 return new NumFmt(isGrouping, fractionDigits, isPercent); 93 94 } 95 96 99 public XMLA_Model getModel() { 100 return model; 101 } 102 105 public void setModel(XMLA_Model model) { 106 this.model = model; 107 } 108 } 110 114 class NumFmt implements NumberFormat{ 115 116 private boolean isGrouping; 117 private int fractionDigits; 118 private boolean isPercent; 119 public NumFmt(boolean isGrouping, int fractionDigits, boolean isPercent) { 120 this.isGrouping = isGrouping; 121 this.fractionDigits = fractionDigits; 122 this.isPercent = isPercent; 123 } 124 125 126 public int getFractionDigits() { 127 return fractionDigits; 128 } 129 130 public void setFractionDigits(int fractionDigits) { 131 this.fractionDigits = fractionDigits; 132 } 133 134 public boolean isGrouping() { 135 return isGrouping; 136 } 137 138 public void setGrouping(boolean isGrouping) { 139 this.isGrouping = isGrouping; 140 } 141 142 public boolean isPercent() { 143 return isPercent; 144 } 145 146 public void setPercent(boolean isPercent) { 147 this.isPercent = isPercent; 148 } 149 } | Popular Tags |