1 50 51 package com.lowagie.text.factories; 52 53 58 public class RomanAlphabetFactory { 59 60 65 public static final String getString(int index) { 66 if (index < 1) throw new NumberFormatException ( 67 "You can't translate a negative number into an alphabetical value."); 68 69 index--; 70 int bytes = 1; 71 int start = 0; 72 int symbols = 26; 73 while(index >= symbols + start) { 74 bytes++; 75 start += symbols; 76 symbols *= 26; 77 } 78 79 int c = index - start; 80 char[] value = new char[bytes]; 81 while(bytes > 0) { 82 value[--bytes] = (char)( 'a' + (c % 26)); 83 c /= 26; 84 } 85 86 return new String (value); 87 } 88 89 94 public static final String getLowerCaseString(int index) { 95 return getString(index); 96 } 97 98 103 public static final String getUpperCaseString(int index) { 104 return getString(index).toUpperCase(); 105 } 106 107 108 113 public static final String getString(int index, boolean lowercase) { 114 if (lowercase) { 115 return getLowerCaseString(index); 116 } 117 else { 118 return getUpperCaseString(index); 119 } 120 } 121 122 125 public static void main(String [] args) { 126 for (int i = 1; i < 32000; i++) { 127 System.out.println(getString(i)); 128 } 129 } 130 } | Popular Tags |