1 13 package com.tonbeller.jpivot.xmla; 14 15 import java.util.ArrayList ; 16 import java.util.HashMap ; 17 import java.util.Iterator ; 18 import java.util.List ; 19 import java.util.Map ; 20 21 import org.apache.log4j.Logger; 22 23 27 public class XMLA_PropValAssign { 28 29 private Map propMap = new HashMap (); 30 private int firstBit = 0; 31 static private int LASTBIT = 15; 33 static Logger logger = Logger.getLogger(XMLA_PropValAssign.class); 34 35 38 public void addProp(String prop, List values) { 39 int nValues = values.size(); 41 if (nValues == 0) 42 return; 43 int nBits = 1; 44 int n = (nValues - 1) / 2; 45 while (n > 0) { 46 ++nBits; 47 n = n / 2; 48 } 49 50 int mask = 1 << nBits; 51 mask = mask - 1; mask = mask << firstBit; 53 54 if (firstBit + nBits > LASTBIT) { 55 logger.error("could not encode property values " + prop + " #" + nValues); 57 return; 58 } 59 60 List vAssignList = new ArrayList (); 61 int iBitVal = 0; 62 for (Iterator iter = values.iterator(); iter.hasNext();) { 63 String val = (String ) iter.next(); 64 ValAssign vAssign = new ValAssign(); 65 vAssign.setVal(val); 66 vAssign.setBitMask(mask); 67 int bitVal = iBitVal << firstBit; 68 vAssign.setBitVal(bitVal); 69 vAssignList.add(vAssign); 70 ++iBitVal; 71 } 72 propMap.put(prop, vAssignList); 73 firstBit += nBits; 74 } 75 76 80 public List getValAssignList(String prop) { 81 return (List ) propMap.get(prop); 82 } 83 84 87 public Map getPropMap() { 88 return propMap; 89 } 90 91 94 public void setPropMap(Map map) { 95 propMap = map; 96 } 97 98 101 public int getFirstBit() { 102 return firstBit; 103 } 104 105 108 public void setFirstBit(int i) { 109 firstBit = i; 110 } 111 112 115 public static class ValAssign { 116 private String val; 117 private int bitMask; 118 private int bitVal; 119 120 123 public String getVal() { 124 return val; 125 } 126 127 130 public void setVal(String string) { 131 val = string; 132 } 133 134 137 public int getBitMask() { 138 return bitMask; 139 } 140 141 144 public void setBitMask(int bitMask) { 145 this.bitMask = bitMask; 146 } 147 148 151 public int getBitVal() { 152 return bitVal; 153 } 154 155 158 public void setBitVal(int i) { 159 bitVal = i; 160 } 161 162 } 164 165 } | Popular Tags |