⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 collator.java

📁 java源代码 请看看啊 提点宝贵的意见
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            try {                result = new RuleBasedCollator( CollationRules.DEFAULTRULES );            } catch (ParseException bar) {                // do nothing            }        }        // Now that RuleBasedCollator adds expansions for pre-composed characters        // into their decomposed equivalents, the default collators don't need        // to have decomposition turned on.  Laura, 5/5/98, bug 4114077        result.setDecomposition(NO_DECOMPOSITION);                cache.put(desiredLocale,result);        return (Collator)result.clone();    }    /**     * Compares the source string to the target string according to the     * collation rules for this Collator.  Returns an integer less than,     * equal to or greater than zero depending on whether the source String is     * less than, equal to or greater than the target string.  See the Collator     * class description for an example of use.     * <p>     * For a one time comparison, this method has the best performance. If a     * given String will be involved in multiple comparisons, CollationKey.compareTo     * has the best performance. See the Collator class description for an example     * using CollationKeys.     * @param source the source string.     * @param target the target string.     * @return Returns an integer value. Value is less than zero if source is less than     * target, value is zero if source and target are equal, value is greater than zero     * if source is greater than target.     * @see java.text.CollationKey     * @see java.text.Collator#getCollationKey     */    public abstract int compare(String source, String target);    /**     * Compares its two arguments for order.  Returns a negative integer,     * zero, or a positive integer as the first argument is less than, equal     * to, or greater than the second.     * <p>     * This implementation merely returns     *  <code> compare((String)o1, (String)o2) </code>.     *      * @return a negative integer, zero, or a positive integer as the     *         first argument is less than, equal to, or greater than the     *         second.      * @exception ClassCastException the arguments cannot be cast to Strings.     * @see java.util.Comparator     * @since   1.2     */    public int compare(Object o1, Object o2) {    return compare((String)o1, (String)o2);    }    /**     * Transforms the String into a series of bits that can be compared bitwise     * to other CollationKeys. CollationKeys provide better performance than     * Collator.compare when Strings are involved in multiple comparisons.     * See the Collator class description for an example using CollationKeys.     * @param source the string to be transformed into a collation key.     * @return the CollationKey for the given String based on this Collator's collation     * rules. If the source String is null, a null CollationKey is returned.     * @see java.text.CollationKey     * @see java.text.Collator#compare     */    public abstract CollationKey getCollationKey(String source);    /**     * Convenience method for comparing the equality of two strings based on     * this Collator's collation rules.     * @param source the source string to be compared with.     * @param target the target string to be compared with.     * @return true if the strings are equal according to the collation     * rules.  false, otherwise.     * @see java.text.Collator#compare     */    public boolean equals(String source, String target)    {        return (compare(source, target) == Collator.EQUAL);    }    /**     * Returns this Collator's strength property.  The strength property determines     * the minimum level of difference considered significant during comparison.     * See the Collator class description for an example of use.     * @return this Collator's current strength property.     * @see java.text.Collator#setStrength     * @see java.text.Collator#PRIMARY     * @see java.text.Collator#SECONDARY     * @see java.text.Collator#TERTIARY     * @see java.text.Collator#IDENTICAL     */    public synchronized int getStrength()    {        return strength;    }    /**     * Sets this Collator's strength property.  The strength property determines     * the minimum level of difference considered significant during comparison.     * See the Collator class description for an example of use.     * @param newStrength  the new strength value.     * @see java.text.Collator#getStrength     * @see java.text.Collator#PRIMARY     * @see java.text.Collator#SECONDARY     * @see java.text.Collator#TERTIARY     * @see java.text.Collator#IDENTICAL     * @exception  IllegalArgumentException If the new strength value is not one of     * PRIMARY, SECONDARY, TERTIARY or IDENTICAL.     */    public synchronized void setStrength(int newStrength) {        if ((newStrength != PRIMARY) &&            (newStrength != SECONDARY) &&            (newStrength != TERTIARY) &&            (newStrength != IDENTICAL))            throw new IllegalArgumentException("Incorrect comparison level.");        strength = newStrength;    }    /**     * Get the decomposition mode of this Collator. Decomposition mode     * determines how Unicode composed characters are handled. Adjusting     * decomposition mode allows the user to select between faster and more     * complete collation behavior.     * <p>The three values for decomposition mode are:     * <UL>     * <LI>NO_DECOMPOSITION,     * <LI>CANONICAL_DECOMPOSITION     * <LI>FULL_DECOMPOSITION.     * </UL>     * See the documentation for these three constants for a description     * of their meaning.     * @return the decomposition mode     * @see java.text.Collator#setDecomposition     * @see java.text.Collator#NO_DECOMPOSITION     * @see java.text.Collator#CANONICAL_DECOMPOSITION     * @see java.text.Collator#FULL_DECOMPOSITION     */    public synchronized int getDecomposition()    {        return decmp;    }    /**     * Set the decomposition mode of this Collator. See getDecomposition     * for a description of decomposition mode.     * @param decompositionMode  the new decomposition mode.     * @see java.text.Collator#getDecomposition     * @see java.text.Collator#NO_DECOMPOSITION     * @see java.text.Collator#CANONICAL_DECOMPOSITION     * @see java.text.Collator#FULL_DECOMPOSITION     * @exception IllegalArgumentException If the given value is not a valid decomposition     * mode.     */    public synchronized void setDecomposition(int decompositionMode) {        if ((decompositionMode != NO_DECOMPOSITION) &&            (decompositionMode != CANONICAL_DECOMPOSITION) &&            (decompositionMode != FULL_DECOMPOSITION))            throw new IllegalArgumentException("Wrong decomposition mode.");        decmp = decompositionMode;    }    /**     * Get the set of Locales for which Collators are installed.     * @return the list of available locales which collators are installed.     */    public static synchronized Locale[] getAvailableLocales() {        return LocaleData.getAvailableLocales("CollationElements");    }    /**     * Overrides Cloneable     */    public Object clone()    {        try {            return (Collator)super.clone();        } catch (CloneNotSupportedException e) {            throw new InternalError();        }    }    /**     * Compares the equality of two Collators.     * @param that the Collator to be compared with this.     * @return true if this Collator is the same as that Collator;     * false otherwise.     */    public boolean equals(Object that)    {        if (this == that) return true;        if (that == null) return false;        if (getClass() != that.getClass()) return false;        Collator other = (Collator) that;        return ((strength == other.strength) &&                (decmp == other.decmp));    }    /**     * Generates the hash code for this Collator.     */    abstract public int hashCode();    /**     * Default constructor.  This constructor is     * protected so subclasses can get access to it. Users typically create     * a Collator sub-class by calling the factory method getInstance.     * @see java.text.Collator#getInstance     */    protected Collator()    {        strength = TERTIARY;        decmp = CANONICAL_DECOMPOSITION;    }    private int strength = 0;    private int decmp = 0;    private static SoftCache cache = new SoftCache();    //    // FIXME: These three constants should be removed.    //    /**     * LESS is returned if source string is compared to be less than target     * string in the compare() method.     * @see java.text.Collator#compare     */    final static int LESS = -1;    /**     * EQUAL is returned if source string is compared to be equal to target     * string in the compare() method.     * @see java.text.Collator#compare     */    final static int EQUAL = 0;    /**     * GREATER is returned if source string is compared to be greater than     * target string in the compare() method.     * @see java.text.Collator#compare     */    final static int GREATER = 1; }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -