mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-20 20:19:32 +00:00
ICU-7125 Clean up API docs for M4.
X-SVN-Rev: 27377
This commit is contained in:
parent
385d4fb93f
commit
baf2429516
2 changed files with 97 additions and 15 deletions
|
@ -86,11 +86,10 @@ public class LocaleMatcher {
|
|||
|
||||
/**
|
||||
* Internal testing function; may expose API later.
|
||||
* @internal
|
||||
* @param languagePriorityList LocalePriorityList to match
|
||||
* @param matcherData Internal matching data
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only.
|
||||
*/
|
||||
public LocaleMatcher(LocalePriorityList languagePriorityList, LanguageMatcherData matcherData) {
|
||||
this.matcherData = matcherData;
|
||||
|
@ -121,14 +120,16 @@ public class LocaleMatcher {
|
|||
|
||||
|
||||
/**
|
||||
* Canonicalize a locale (language). Note that for now, it is canonicalizing according to CLDR conventions (he vs iw, etc), since that is what is needed for likelySubtags.
|
||||
* TODO Get the data from CLDR, use Java conventions.
|
||||
* Canonicalize a locale (language). Note that for now, it is canonicalizing
|
||||
* according to CLDR conventions (he vs iw, etc), since that is what is needed
|
||||
* for likelySubtags.
|
||||
* @param ulocale language/locale code
|
||||
* @return ULocale with remapped subtags.
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public ULocale canonicalize(ULocale ulocale) {
|
||||
// TODO Get the data from CLDR, use Java conventions.
|
||||
String lang = ulocale.getLanguage();
|
||||
String lang2 = canonicalMap.get(lang);
|
||||
String script = ulocale.getScript();
|
||||
|
@ -194,6 +195,11 @@ public class LocaleMatcher {
|
|||
return getBestMatchInternal(ulocale).get0();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{" + defaultLanguage + ", "
|
||||
|
@ -467,13 +473,17 @@ public class LocaleMatcher {
|
|||
/**
|
||||
* Only for testing and use by tools. Interface may change!!
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only.
|
||||
*/
|
||||
public static class LanguageMatcherData implements Freezable<LanguageMatcherData> {
|
||||
ScoreData languageScores = new ScoreData(Level.language);
|
||||
ScoreData scriptScores = new ScoreData(Level.script);
|
||||
ScoreData regionScores = new ScoreData(Level.region);
|
||||
|
||||
/** @internal */
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only.
|
||||
*/
|
||||
public double match(ULocale a, ULocale aMax, ULocale b, ULocale bMax) {
|
||||
double diff = 0;
|
||||
diff += languageScores.getScore(a, aMax, a.getLanguage(), aMax.getLanguage(), b, bMax, b.getLanguage(), bMax.getLanguage());
|
||||
|
@ -498,20 +508,23 @@ public class LocaleMatcher {
|
|||
* symmetric. We don't bother producing an equivalence class because there are
|
||||
* so few cases; this function depends on the other permutations being
|
||||
* added specifically.
|
||||
* @param desired
|
||||
* @param supported
|
||||
* @param distance
|
||||
* @param bidirectional TODO
|
||||
* @return
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only.
|
||||
*/
|
||||
private LanguageMatcherData addDistance(String desired, String supported, int percent) {
|
||||
return addDistance(desired, supported, percent, false, null);
|
||||
}
|
||||
/** @internal */
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only.
|
||||
*/
|
||||
public LanguageMatcherData addDistance(String desired, String supported, int percent, String comment) {
|
||||
return addDistance(desired, supported, percent, false, comment);
|
||||
}
|
||||
/** @internal */
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only.
|
||||
*/
|
||||
public LanguageMatcherData addDistance(String desired, String supported, int percent, boolean oneway) {
|
||||
return addDistance(desired, supported, percent, oneway, null);
|
||||
}
|
||||
|
@ -575,6 +588,8 @@ public class LocaleMatcher {
|
|||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only.
|
||||
*/
|
||||
public LanguageMatcherData cloneAsThawed() {
|
||||
LanguageMatcherData result;
|
||||
|
@ -594,6 +609,8 @@ public class LocaleMatcher {
|
|||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only.
|
||||
*/
|
||||
public LanguageMatcherData freeze() {
|
||||
return this;
|
||||
|
@ -601,6 +618,8 @@ public class LocaleMatcher {
|
|||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only.
|
||||
*/
|
||||
public boolean isFrozen() {
|
||||
return frozen;
|
||||
|
|
|
@ -18,8 +18,6 @@ import java.util.TreeMap;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
/**
|
||||
* Provides an immutable list of languages (locales) in priority order.
|
||||
* The string format is based on the Accept-Language format
|
||||
|
@ -65,6 +63,7 @@ import com.ibm.icu.util.ULocale;
|
|||
* ja;q=1.0</pre>
|
||||
* @author markdavis@google.com
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public class LocalePriorityList implements Iterable<ULocale> {
|
||||
private static final double D0 = 0.0d;
|
||||
|
@ -80,6 +79,8 @@ public class LocalePriorityList implements Iterable<ULocale> {
|
|||
*
|
||||
* @param languageCode locale/language to be added
|
||||
* @return internal builder, for chaining
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public static Builder add(ULocale languageCode) {
|
||||
return new Builder().add(languageCode);
|
||||
|
@ -91,6 +92,8 @@ public class LocalePriorityList implements Iterable<ULocale> {
|
|||
* @param languageCode locale/language to be added
|
||||
* @param weight value from 0.0 to 1.0
|
||||
* @return internal builder, for chaining
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public static Builder add(ULocale languageCode, final double weight) {
|
||||
return new Builder().add(languageCode, weight);
|
||||
|
@ -101,6 +104,8 @@ public class LocalePriorityList implements Iterable<ULocale> {
|
|||
*
|
||||
* @param languagePriorityList list to add all the members of
|
||||
* @return internal builder, for chaining
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public static Builder add(LocalePriorityList languagePriorityList) {
|
||||
return new Builder().add(languagePriorityList);
|
||||
|
@ -112,6 +117,8 @@ public class LocalePriorityList implements Iterable<ULocale> {
|
|||
*
|
||||
* @param acceptLanguageString String in rfc2616 format (but leniently parsed)
|
||||
* @return internal builder, for chaining
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public static Builder add(String acceptLanguageString) {
|
||||
return new Builder().add(acceptLanguageString);
|
||||
|
@ -123,11 +130,18 @@ public class LocalePriorityList implements Iterable<ULocale> {
|
|||
*
|
||||
* @param language to get weight of
|
||||
* @return weight
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public Double getWeight(ULocale language) {
|
||||
return languagesAndWeights.get(language);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder result = new StringBuilder();
|
||||
|
@ -144,10 +158,20 @@ public class LocalePriorityList implements Iterable<ULocale> {
|
|||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public Iterator<ULocale> iterator() {
|
||||
return languagesAndWeights.keySet().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
try {
|
||||
|
@ -158,6 +182,11 @@ public class LocalePriorityList implements Iterable<ULocale> {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return languagesAndWeights.hashCode();
|
||||
|
@ -173,6 +202,7 @@ public class LocalePriorityList implements Iterable<ULocale> {
|
|||
/**
|
||||
* Class used for building LanguagePriorityLists
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public static class Builder {
|
||||
/**
|
||||
|
@ -182,10 +212,27 @@ public class LocalePriorityList implements Iterable<ULocale> {
|
|||
private final Map<ULocale, Double> languageToWeight
|
||||
= new LinkedHashMap<ULocale, Double>();
|
||||
|
||||
/**
|
||||
* Creates a LocalePriorityList. This is equivalent to
|
||||
* {@link Builder#build(boolean) Builder.build(false)}.
|
||||
*
|
||||
* @return A LocalePriorityList
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public LocalePriorityList build() {
|
||||
return build(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a LocalePriorityList.
|
||||
*
|
||||
* @param preserveWeights when true, the weights originally came
|
||||
* from a language priority list specified by add() are preserved.
|
||||
* @return A LocalePriorityList
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public LocalePriorityList build(boolean preserveWeights) {
|
||||
// Walk through the input list, collecting the items with the same weights.
|
||||
final Map<Double, Set<ULocale>> doubleCheck = new TreeMap<Double, Set<ULocale>>(
|
||||
|
@ -209,6 +256,14 @@ public class LocalePriorityList implements Iterable<ULocale> {
|
|||
return new LocalePriorityList(Collections.unmodifiableMap(temp));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a LocalePriorityList
|
||||
*
|
||||
* @param languagePriorityList a LocalePriorityList
|
||||
* @return this, for chaining
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public Builder add(
|
||||
final LocalePriorityList languagePriorityList) {
|
||||
for (final ULocale language : languagePriorityList.languagesAndWeights
|
||||
|
@ -223,6 +278,8 @@ public class LocalePriorityList implements Iterable<ULocale> {
|
|||
*
|
||||
* @param languageCode to add with weight 1.0
|
||||
* @return this, for chaining
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public Builder add(final ULocale languageCode) {
|
||||
return add(languageCode, D1);
|
||||
|
@ -233,6 +290,8 @@ public class LocalePriorityList implements Iterable<ULocale> {
|
|||
*
|
||||
* @param languageCodes List of language codes.
|
||||
* @return this, for chaining.
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public Builder add(ULocale... languageCodes) {
|
||||
for (final ULocale languageCode : languageCodes) {
|
||||
|
@ -248,6 +307,8 @@ public class LocalePriorityList implements Iterable<ULocale> {
|
|||
* @param languageCode language/locale to add
|
||||
* @param weight value between 0.0 and 1.1
|
||||
* @return this, for chaining.
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public Builder add(final ULocale languageCode,
|
||||
double weight) {
|
||||
|
@ -268,6 +329,8 @@ public class LocalePriorityList implements Iterable<ULocale> {
|
|||
*
|
||||
* @param acceptLanguageList in rfc2616 format
|
||||
* @return this, for chaining.
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public Builder add(final String acceptLanguageList) {
|
||||
final String[] items = languageSplitter.split(acceptLanguageList.trim());
|
||||
|
|
Loading…
Add table
Reference in a new issue