Java中的 Collator setDecomposition() 方法与示例
Java.text.Collator 类的setdecomposition()方法用来设置这个collator 的分解方式。
句法:
public void setDecomposition(int decompositionMode)
参数:此方法以整数值作为参数,表示此整理器的等效分解模式。
返回值:此方法没有任何返回值。
下面是说明setDecomposition()方法的示例:
示例 1:
Java
// Java program to demonstrate
// setDecomposition() method
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
try {
// Creating and initializing new simple rule
String simple = "< a < b < c < d";
// Creating and initializing
// new RuleBasedCollator Object
RuleBasedCollator col
= new RuleBasedCollator(simple);
// setting decomposition mode
// into the Collator object
// using setDecomposition() method
col.setDecomposition(
Collator.CANONICAL_DECOMPOSITION);
// getting decomposition mode
int mode = col.getDecomposition();
// display result
if (mode == 0)
System.out.println(
"decompostiton mode"
+ " is :- NO_DECOMPOSITION");
else if (mode == 1)
System.out.println(
"decompostiton mode is"
+ " :- CANONICAL_DECOMPOSITION");
else
System.out.println(
"decompostiton mode is "
+ ":- FULL_DECOMPOSITION. ");
}
catch (ClassCastException e) {
System.out.println("Exception thrown : " + e);
}
catch (ParseException e) {
System.out.println("Exception thrown : " + e);
}
}
}
Java
// Java program to demonstrate
// setDecomposition() method
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
try {
// Creating and initializing new simple rule
String simple = "< a < b < c < d";
// Creating and initializing
// new RuleBasedCollator Object
RuleBasedCollator col
= new RuleBasedCollator(simple);
// setting decomposition mode
// into the Collator object
// using setDecomposition() method
col.setDecomposition(
Collator.CANONICAL_DECOMPOSITION);
// getting decomposition mode
int mode = col.getDecomposition();
// display result
if (mode == 0)
System.out.println(
"decompostiton mode"
+ " is :- NO_DECOMPOSITION");
else if (mode == 1)
System.out.println(
"decompostiton mode is"
+ " :- CANONICAL_DECOMPOSITION");
else
System.out.println(
"decompostiton mode is "
+ ":- FULL_DECOMPOSITION. ");
}
catch (ClassCastException e) {
System.out.println("Exception thrown : " + e);
}
catch (ParseException e) {
System.out.println("Exception thrown : " + e);
}
}
}
输出:
decompostiton mode is :- CANONICAL_DECOMPOSITION
示例 2:
Java
// Java program to demonstrate
// setDecomposition() method
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
try {
// Creating and initializing new simple rule
String simple = "< a < b < c < d";
// Creating and initializing
// new RuleBasedCollator Object
RuleBasedCollator col
= new RuleBasedCollator(simple);
// setting decomposition mode
// into the Collator object
// using setDecomposition() method
col.setDecomposition(
Collator.CANONICAL_DECOMPOSITION);
// getting decomposition mode
int mode = col.getDecomposition();
// display result
if (mode == 0)
System.out.println(
"decompostiton mode"
+ " is :- NO_DECOMPOSITION");
else if (mode == 1)
System.out.println(
"decompostiton mode is"
+ " :- CANONICAL_DECOMPOSITION");
else
System.out.println(
"decompostiton mode is "
+ ":- FULL_DECOMPOSITION. ");
}
catch (ClassCastException e) {
System.out.println("Exception thrown : " + e);
}
catch (ParseException e) {
System.out.println("Exception thrown : " + e);
}
}
}
输出:
decompostiton mode is :- FULL_DECOMPOSITION.
参考: https://docs.oracle.com/javase/9/docs/api/ Java/text/Collator.html#setDecomposition-int-