public static class

DataTransferer.CharsetComparator

extends DataTransferer.IndexedComparator
java.lang.Object
   ↳ sun.awt.datatransfer.DataTransferer.IndexedComparator
     ↳ sun.awt.datatransfer.DataTransferer.CharsetComparator

Class Overview

An IndexedComparator which compares two String charsets. The comparison follows the rules outlined in DataFlavor.selectBestTextFlavor. In order to ensure that non-Unicode, non-ASCII, non-default charsets are sorted in alphabetical order, charsets are not automatically converted to their canonical forms.

Summary

[Expand]
Inherited Constants
From class sun.awt.datatransfer.DataTransferer.IndexedComparator
[Expand]
Inherited Fields
From class sun.awt.datatransfer.DataTransferer.IndexedComparator
Public Constructors
DataTransferer.CharsetComparator()
DataTransferer.CharsetComparator(boolean order)
Public Methods
int compare(Object obj1, Object obj2)
Compares two String objects.
Protected Methods
int compareCharsets(String charset1, String charset2)
Compares charsets.
static String getEncoding(String charset)
Returns encoding for the specified charset according to the following rules:
  • If the charset is null, then null will be returned.
[Expand]
Inherited Methods
From class sun.awt.datatransfer.DataTransferer.IndexedComparator
From class java.lang.Object
From interface java.util.Comparator

Public Constructors

public DataTransferer.CharsetComparator ()

public DataTransferer.CharsetComparator (boolean order)

Public Methods

public int compare (Object obj1, Object obj2)

Compares two String objects. Returns a negative integer, zero, or a positive integer as the first charset is worse than, equal to, or better than the second.

Parameters
obj1 the first charset to be compared
obj2 the second charset to be compared
Returns
  • a negative integer, zero, or a positive integer as the first argument is worse, equal to, or better than the second.
Throws
ClassCastException if either of the arguments is not instance of String
NullPointerException if either of the arguments is null.

Protected Methods

protected int compareCharsets (String charset1, String charset2)

Compares charsets. Returns a negative integer, zero, or a positive integer as the first charset is worse than, equal to, or better than the second.

Charsets are ordered according to the following rules:

  • All unsupported charsets are equal.
  • Any unsupported charset is worse than any supported charset.
  • Unicode charsets, such as "UTF-16", "UTF-8", "UTF-16BE" and "UTF-16LE", are considered best.
  • After them, platform default charset is selected.
  • "US-ASCII" is the worst of supported charsets.
  • For all other supported charsets, the lexicographically less one is considered the better.

Parameters
charset1 the first charset to be compared
charset2 the second charset to be compared.
Returns
  • a negative integer, zero, or a positive integer as the first argument is worse, equal to, or better than the second.

protected static String getEncoding (String charset)

Returns encoding for the specified charset according to the following rules:

  • If the charset is null, then null will be returned.
  • Iff the charset specifies an encoding unsupported by this JRE, UNSUPPORTED_CHARSET will be returned.
  • If the charset specifies an alias name, the corresponding canonical name will be returned iff the charset is a known Unicode, ASCII, or default charset.

Parameters
charset the charset.
Returns
  • an encoding for this charset.