1 2 17 18 19 package org.apache.poi.hdf.generator; 20 21 import org.apache.poi.generator.RecordUtil; 22 23 26 public class HDFRecordUtil extends RecordUtil 27 { 28 29 public HDFRecordUtil() 30 { 31 } 32 33 public static String getType(String size, String type, int padTo) 34 { 35 36 return type; 37 } 38 39 public static String getType1stCap(String size, String type, int padTo) 40 { 41 StringBuffer result = new StringBuffer (); 42 result.append(type); 43 result = pad(result, padTo); 44 result.setCharAt(0, Character.toUpperCase(result.charAt(0))); 45 46 return result.toString(); 47 } 48 49 public static String getBitFieldFunction(String name, String bitMask, String parentType, String withType) 50 { 51 String type = getBitFieldType(name, bitMask, parentType); 52 53 String retVal = new String (); 54 if(withType.equals("true")) 55 { 56 retVal = type + " "; 57 } 58 if(type.equals("boolean")) 59 { 60 retVal += "is" + getFieldName1stCap(name, 0); 61 } 62 else 63 { 64 retVal +="get" + getFieldName1stCap(name, 0); 65 } 66 return retVal; 67 68 } 69 70 public static String getBitFieldGet(String name, String bitMask, String parentType, String parentField) 71 { 72 String type = getBitFieldType(name, bitMask, parentType); 73 74 String retVal = null; 75 76 if(type.equals("boolean")) 77 retVal = name + ".isSet(" + parentField + ");"; 78 else 79 retVal = "( " + type + " )" + name + ".getValue(" + parentField + ");"; 80 81 return retVal; 82 83 } 84 public static String getBitFieldSet(String name, String bitMask, String parentType, String parentField) 85 { 86 String type = getBitFieldType(name, bitMask, parentType); 87 88 String retVal = null; 89 90 if(type.equals("boolean")) 91 retVal = "(" + parentType + ")" + getFieldName(name, 0) + ".setBoolean(" + parentField + ", value)"; 92 else 93 retVal = "(" + parentType + ")" + getFieldName(name, 0) + ".setValue(" + parentField + ", value)"; 94 return retVal; 95 } 96 97 public static String getBitFieldType(String name, String bitMask, String parentType) 98 { 99 byte parentSize = 0; 100 byte numBits = 0; 101 int mask = (int)Long.parseLong(bitMask.substring(2), 16); 102 103 if (parentType.equals("byte")) 104 parentSize = 8; 105 else if (parentType.equals("short")) 106 parentSize = 16; 107 else if (parentType.equals("int")) 108 parentSize = 32; 109 110 for (int x = 0; x < parentSize; x++) 111 { 112 int temp = mask; 113 numBits += (temp >> x) & 0x1; 114 } 115 116 if(numBits == 1) 117 { 118 return "boolean"; 119 } 120 else if (numBits < 8) 121 { 122 return "byte"; 123 } 124 else if (numBits < 16) 125 { 126 return "short"; 127 } 128 else 129 { 130 return "int"; 131 } 132 } 133 134 135 } 136 | Popular Tags |