1 21 22 package com.ice.text; 23 24 import java.lang.*; 25 import java.text.*; 26 import java.util.*; 27 28 36 37 public class 38 HexNumberFormat extends Format 39 { 40 static public final String RCS_ID = "$Id: HexNumberFormat.java,v 1.1 2002/03/14 09:55:00 deniger Exp $"; 41 static public final String RCS_REV = "$Revision: 1.1 $"; 42 43 private static char[] lowChars; 44 private static char[] uprChars; 45 46 private int count; 47 private String pattern; 48 private static char[] hexChars; 49 50 static 51 { 52 HexNumberFormat.lowChars = new char[20]; 53 HexNumberFormat.uprChars = new char[20]; 54 55 HexNumberFormat.uprChars[0] = HexNumberFormat.lowChars[0] = '0'; 56 HexNumberFormat.uprChars[1] = HexNumberFormat.lowChars[1] = '1'; 57 HexNumberFormat.uprChars[2] = HexNumberFormat.lowChars[2] = '2'; 58 HexNumberFormat.uprChars[3] = HexNumberFormat.lowChars[3] = '3'; 59 HexNumberFormat.uprChars[4] = HexNumberFormat.lowChars[4] = '4'; 60 HexNumberFormat.uprChars[5] = HexNumberFormat.lowChars[5] = '5'; 61 HexNumberFormat.uprChars[6] = HexNumberFormat.lowChars[6] = '6'; 62 HexNumberFormat.uprChars[7] = HexNumberFormat.lowChars[7] = '7'; 63 HexNumberFormat.uprChars[8] = HexNumberFormat.lowChars[8] = '8'; 64 HexNumberFormat.uprChars[9] = HexNumberFormat.lowChars[9] = '9'; 65 HexNumberFormat.uprChars[10] = 'A'; HexNumberFormat.lowChars[10] = 'a'; 66 HexNumberFormat.uprChars[11] = 'B'; HexNumberFormat.lowChars[11] = 'b'; 67 HexNumberFormat.uprChars[12] = 'C'; HexNumberFormat.lowChars[12] = 'c'; 68 HexNumberFormat.uprChars[13] = 'D'; HexNumberFormat.lowChars[13] = 'd'; 69 HexNumberFormat.uprChars[14] = 'E'; HexNumberFormat.lowChars[14] = 'e'; 70 HexNumberFormat.uprChars[15] = 'F'; HexNumberFormat.lowChars[15] = 'f'; 71 } 72 73 static public final HexNumberFormat 74 getInstance() 75 { 76 return new HexNumberFormat( "XXXXXXXX" ); 77 } 78 79 public 80 HexNumberFormat( String pattern ) 81 { 82 super(); 83 this.pattern = pattern; 84 this.count = pattern.length(); 85 this.hexChars = 86 ( pattern.charAt(0) == 'X' 87 ? HexNumberFormat.uprChars 88 : HexNumberFormat.lowChars ); 89 } 90 91 public String 92 format( int hexNum ) 93 throws IllegalArgumentException 94 { 95 FieldPosition pos = new FieldPosition(0); 96 StringBuffer hexBuf = new StringBuffer (8); 97 98 this.format( new Integer ( hexNum ), hexBuf, pos ); 99 100 return hexBuf.toString(); 101 } 102 103 public StringBuffer 104 format( Object hexInt, StringBuffer appendTo, FieldPosition fieldPos ) 105 throws IllegalArgumentException 106 { 107 char[] hexBuf = new char[16]; 108 109 int end = fieldPos.getEndIndex(); 110 int beg = fieldPos.getBeginIndex(); 111 112 int hexNum = ((Integer ) hexInt).intValue(); 113 114 for ( int i = 7 ; i >= 0 ; --i ) 115 { 116 hexBuf[i] = this.hexChars[ (hexNum & 0x0F) ]; 117 hexNum = hexNum >> 4; 118 } 119 120 for ( int i = (8 - this.count) ; i < 8 ; ++i ) 121 { 122 appendTo.append( hexBuf[i] ); 123 } 124 125 return appendTo; 126 } 127 128 public int 129 parse( String source ) 130 throws ParseException 131 { 132 throw new ParseException( "unimplemented!", 0 ); 133 } 134 135 public Object 136 parseObject( String source, ParsePosition pos ) 137 { 138 return null; 139 } 140 141 } 142 143 | Popular Tags |