Skip to content

Commit

Permalink
Stop using deprecated Locale constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
akurtakov committed Dec 17, 2024
1 parent cdc1958 commit 3e41618
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -46,10 +46,10 @@ public synchronized Object start(IApplicationContext context) throws Exception {
}
Locale locale;
if (localeStr.length() >= 5) {
locale = new Locale(localeStr.substring(0, 2), localeStr.substring(3, 5));
locale = Locale.of(localeStr.substring(0, 2), localeStr.substring(3, 5));
}
else {
locale = new Locale(localeStr.substring(0, 2), ""); //$NON-NLS-1$
locale = Locale.of(localeStr.substring(0, 2), ""); //$NON-NLS-1$
}
preindex(directory, locale);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the
* accompanying materials are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -53,7 +53,7 @@ public DefaultAnalyzer(String localeString) {
}
if (locale == null && userLocale.getDisplayVariant().length() > 0) {
// Check if the locale without variant is supported by BreakIterator
Locale countryLocale = new Locale(userLocale.getLanguage(), userLocale.getCountry());
Locale countryLocale = Locale.of(userLocale.getLanguage(), userLocale.getCountry());
for (Locale availableLocale : availableLocales) {
if (countryLocale.equals(availableLocale)) {
locale = countryLocale;
Expand All @@ -63,7 +63,7 @@ public DefaultAnalyzer(String localeString) {
}
if (locale == null && userLocale.getCountry().length() > 0) {
// Check if at least the language is supported by BreakIterator
Locale language = new Locale(userLocale.getLanguage(), ""); //$NON-NLS-1$
Locale language = Locale.of(userLocale.getLanguage(), ""); //$NON-NLS-1$
for (Locale availableLocale : availableLocales) {
if (language.equals(availableLocale)) {
locale = language;
Expand All @@ -79,7 +79,7 @@ public DefaultAnalyzer(String localeString) {
+ localeString
+ ", or Java Virtual Machine needs to be upgraded to version with proper support for locale {0}.", //$NON-NLS-1$
null);
locale = new Locale("en", "US"); //$NON-NLS-1$ //$NON-NLS-2$
locale = Locale.of("en", "US"); //$NON-NLS-1$ //$NON-NLS-2$
}
}

Expand All @@ -95,11 +95,11 @@ private Locale getLocale(String clientLocale) {
// break the string into tokens to get the Locale object
StringTokenizer locales = new StringTokenizer(clientLocale, "_"); //$NON-NLS-1$
if (locales.countTokens() == 1)
return new Locale(locales.nextToken(), ""); //$NON-NLS-1$
return Locale.of(locales.nextToken(), ""); //$NON-NLS-1$
else if (locales.countTokens() == 2)
return new Locale(locales.nextToken(), locales.nextToken());
return Locale.of(locales.nextToken(), locales.nextToken());
else if (locales.countTokens() == 3)
return new Locale(locales.nextToken(), locales.nextToken(), locales.nextToken());
return Locale.of(locales.nextToken(), locales.nextToken(), locales.nextToken());
else
return Locale.getDefault();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,20 +14,28 @@
* Sopot Cela - Bug 466829
*******************************************************************************/
package org.eclipse.help.internal.search;
import java.io.*;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;

import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.index.*;
import org.apache.lucene.search.*;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.BooleanQuery.Builder;
import org.eclipse.help.internal.base.*;
import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.Query;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.base.HelpBasePlugin;
/**
* Build query acceptable by the search engine.
*/
Expand Down Expand Up @@ -57,10 +65,9 @@ public QueryBuilder(String searchWords, AnalyzerDescriptor analyzerDesc) {
this.searchWords = searchWords;
String language = analyzerDesc.getLang();
if (language.length() >= 5) {
this.locale = new Locale(language.substring(0, 2), language
.substring(3, 5));
this.locale = Locale.of(language.substring(0, 2), language.substring(3, 5));
} else {
this.locale = new Locale(language.substring(0, 2), ""); //$NON-NLS-1$
this.locale = Locale.of(language.substring(0, 2), ""); //$NON-NLS-1$
}
this.analyzerDesc = analyzerDesc;
this.analyzer = analyzerDesc.getAnalyzer();
Expand Down Expand Up @@ -297,8 +304,7 @@ private List<Query> getRequiredQueries(List<QueryWordsToken> tokens, String[] fi
}
private Query orQueries(Collection<Query> queries) {
Builder builder = new BooleanQuery.Builder();
for (Iterator<Query> it = queries.iterator(); it.hasNext();) {
Query q = it.next();
for (Query q : queries) {
builder.add(q, BooleanClause.Occur.SHOULD);
}
return builder.build();
Expand Down

0 comments on commit 3e41618

Please sign in to comment.