Il metodo getClass(char c)
della classe Normalizer sembra mancare da Java 6 in poi.Sostituzione per il metodo Normalizer.getClass (c) in Java 6
Questo metodo è presente nel nostro codice legacy e viene utilizzato come mostrato di seguito. Dobbiamo migrarlo a Java 6. Qualche suggerimento su come può essere sostituito?
import sun.text.Normalizer;
/**
* Returns an array of strings that have all the possible
* permutations of the characters in the input string.
* This is used to get a list of all possible orderings
* of a set of combining marks. Note that some of the permutations
* are invalid because of combining class collisions, and these
* possibilities must be removed because they are not canonically
* equivalent.
*/
private String[] producePermutations(String input) {
if (input.length() == 1)
return new String[] {input};
if (input.length() == 2) {
if (getClass(input.charAt(1)) ==
getClass(input.charAt(0))) {
return new String[] {input};
}
String[] result = new String[2];
result[0] = input;
StringBuffer sb = new StringBuffer(2);
sb.append(input.charAt(1));
sb.append(input.charAt(0));
result[1] = sb.toString();
return result;
}
int length = 1;
for(int x=1; x<input.length(); x++)
length = length * (x+1);
String[] temp = new String[length];
int combClass[] = new int[input.length()];
for(int x=0; x<input.length(); x++)
combClass[x] = getClass(input.charAt(x));
// For each char, take it out and add the permutations
// of the remaining chars
int index = 0;
loop: for(int x=0; x<input.length(); x++) {
boolean skip = false;
for(int y=x-1; y>=0; y--) {
if (combClass[y] == combClass[x]) {
continue loop;
}
}
StringBuffer sb = new StringBuffer(input);
String otherChars = sb.delete(x, x+1).toString();
String[] subResult = producePermutations(otherChars);
String prefix = input.substring(x, x+1);
for(int y=0; y<subResult.length; y++)
temp[index++] = prefix + subResult[y];
}
String[] result = new String[index];
for (int x=0; x<index; x++)
result[x] = temp[x];
return result;
}
private int getClass(char c) {
return Normalizer.getClass(c);
}
Hai scritto sun.text.Normailer, ma collegato javadoc da java.text.Normalizer. È stato un errore o hai risposto alla tua domanda per caso? –
mi dispiace, rimosso il riferimento ora. – dazzle
Le classi del pacchetto 'sun' vengono unite a' java' nel tempo. 'CharSequence' è un altro esempio. –