Make `static final Map` constants immutable (#13092)

This commit is contained in:
Dmitry Cherniachenko 2024-02-13 19:02:55 +01:00 committed by GitHub
parent a270acae01
commit 3768b2e1e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 271 additions and 242 deletions

View File

@ -258,6 +258,8 @@ Improvements
Tests are running with random byte order to ensure that the order does not affect correctness
of code. Native order was enabled for LZ4 compression. (Uwe Schindler)
* GITHUB#13092: `static final Map` constants have been made immutable (Dmitry Cherniachenko)
Optimizations
---------------------

View File

@ -17,103 +17,107 @@
package org.apache.lucene.analysis.ja.dict;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/** Utility class for english translations of morphological data, used only for debugging. */
public class ToStringUtil {
// a translation map for parts of speech, only used for reflectWith
private static final HashMap<String, String> posTranslations = new HashMap<>();
private static final Map<String, String> posTranslations;
static {
posTranslations.put("名詞", "noun");
posTranslations.put("名詞-一般", "noun-common");
posTranslations.put("名詞-固有名詞", "noun-proper");
posTranslations.put("名詞-固有名詞-一般", "noun-proper-misc");
posTranslations.put("名詞-固有名詞-人名", "noun-proper-person");
posTranslations.put("名詞-固有名詞-人名-一般", "noun-proper-person-misc");
posTranslations.put("名詞-固有名詞-人名-姓", "noun-proper-person-surname");
posTranslations.put("名詞-固有名詞-人名-名", "noun-proper-person-given_name");
posTranslations.put("名詞-固有名詞-組織", "noun-proper-organization");
posTranslations.put("名詞-固有名詞-地域", "noun-proper-place");
posTranslations.put("名詞-固有名詞-地域-一般", "noun-proper-place-misc");
posTranslations.put("名詞-固有名詞-地域-国", "noun-proper-place-country");
posTranslations.put("名詞-代名詞", "noun-pronoun");
posTranslations.put("名詞-代名詞-一般", "noun-pronoun-misc");
posTranslations.put("名詞-代名詞-縮約", "noun-pronoun-contraction");
posTranslations.put("名詞-副詞可能", "noun-adverbial");
posTranslations.put("名詞-サ変接続", "noun-verbal");
posTranslations.put("名詞-形容動詞語幹", "noun-adjective-base");
posTranslations.put("名詞-数", "noun-numeric");
posTranslations.put("名詞-非自立", "noun-affix");
posTranslations.put("名詞-非自立-一般", "noun-affix-misc");
posTranslations.put("名詞-非自立-副詞可能", "noun-affix-adverbial");
posTranslations.put("名詞-非自立-助動詞語幹", "noun-affix-aux");
posTranslations.put("名詞-非自立-形容動詞語幹", "noun-affix-adjective-base");
posTranslations.put("名詞-特殊", "noun-special");
posTranslations.put("名詞-特殊-助動詞語幹", "noun-special-aux");
posTranslations.put("名詞-接尾", "noun-suffix");
posTranslations.put("名詞-接尾-一般", "noun-suffix-misc");
posTranslations.put("名詞-接尾-人名", "noun-suffix-person");
posTranslations.put("名詞-接尾-地域", "noun-suffix-place");
posTranslations.put("名詞-接尾-サ変接続", "noun-suffix-verbal");
posTranslations.put("名詞-接尾-助動詞語幹", "noun-suffix-aux");
posTranslations.put("名詞-接尾-形容動詞語幹", "noun-suffix-adjective-base");
posTranslations.put("名詞-接尾-副詞可能", "noun-suffix-adverbial");
posTranslations.put("名詞-接尾-助数詞", "noun-suffix-classifier");
posTranslations.put("名詞-接尾-特殊", "noun-suffix-special");
posTranslations.put("名詞-接続詞的", "noun-suffix-conjunctive");
posTranslations.put("名詞-動詞非自立的", "noun-verbal_aux");
posTranslations.put("名詞-引用文字列", "noun-quotation");
posTranslations.put("名詞-ナイ形容詞語幹", "noun-nai_adjective");
posTranslations.put("接頭詞", "prefix");
posTranslations.put("接頭詞-名詞接続", "prefix-nominal");
posTranslations.put("接頭詞-動詞接続", "prefix-verbal");
posTranslations.put("接頭詞-形容詞接続", "prefix-adjectival");
posTranslations.put("接頭詞-数接続", "prefix-numerical");
posTranslations.put("動詞", "verb");
posTranslations.put("動詞-自立", "verb-main");
posTranslations.put("動詞-非自立", "verb-auxiliary");
posTranslations.put("動詞-接尾", "verb-suffix");
posTranslations.put("形容詞", "adjective");
posTranslations.put("形容詞-自立", "adjective-main");
posTranslations.put("形容詞-非自立", "adjective-auxiliary");
posTranslations.put("形容詞-接尾", "adjective-suffix");
posTranslations.put("副詞", "adverb");
posTranslations.put("副詞-一般", "adverb-misc");
posTranslations.put("副詞-助詞類接続", "adverb-particle_conjunction");
posTranslations.put("連体詞", "adnominal");
posTranslations.put("接続詞", "conjunction");
posTranslations.put("助詞", "particle");
posTranslations.put("助詞-格助詞", "particle-case");
posTranslations.put("助詞-格助詞-一般", "particle-case-misc");
posTranslations.put("助詞-格助詞-引用", "particle-case-quote");
posTranslations.put("助詞-格助詞-連語", "particle-case-compound");
posTranslations.put("助詞-接続助詞", "particle-conjunctive");
posTranslations.put("助詞-係助詞", "particle-dependency");
posTranslations.put("助詞-副助詞", "particle-adverbial");
posTranslations.put("助詞-間投助詞", "particle-interjective");
posTranslations.put("助詞-並立助詞", "particle-coordinate");
posTranslations.put("助詞-終助詞", "particle-final");
posTranslations.put("助詞-副助詞/並立助詞/終助詞", "particle-adverbial/conjunctive/final");
posTranslations.put("助詞-連体化", "particle-adnominalizer");
posTranslations.put("助詞-副詞化", "particle-adnominalizer");
posTranslations.put("助詞-特殊", "particle-special");
posTranslations.put("助動詞", "auxiliary-verb");
posTranslations.put("感動詞", "interjection");
posTranslations.put("記号", "symbol");
posTranslations.put("記号-一般", "symbol-misc");
posTranslations.put("記号-句点", "symbol-period");
posTranslations.put("記号-読点", "symbol-comma");
posTranslations.put("記号-空白", "symbol-space");
posTranslations.put("記号-括弧開", "symbol-open_bracket");
posTranslations.put("記号-括弧閉", "symbol-close_bracket");
posTranslations.put("記号-アルファベット", "symbol-alphabetic");
posTranslations.put("その他", "other");
posTranslations.put("その他-間投", "other-interjection");
posTranslations.put("フィラー", "filler");
posTranslations.put("非言語音", "non-verbal");
posTranslations.put("語断片", "fragment");
posTranslations.put("未知語", "unknown");
Map<String, String> translations = new HashMap<>();
translations.put("名詞", "noun");
translations.put("名詞-一般", "noun-common");
translations.put("名詞-固有名詞", "noun-proper");
translations.put("名詞-固有名詞-一般", "noun-proper-misc");
translations.put("名詞-固有名詞-人名", "noun-proper-person");
translations.put("名詞-固有名詞-人名-一般", "noun-proper-person-misc");
translations.put("名詞-固有名詞-人名-姓", "noun-proper-person-surname");
translations.put("名詞-固有名詞-人名-名", "noun-proper-person-given_name");
translations.put("名詞-固有名詞-組織", "noun-proper-organization");
translations.put("名詞-固有名詞-地域", "noun-proper-place");
translations.put("名詞-固有名詞-地域-一般", "noun-proper-place-misc");
translations.put("名詞-固有名詞-地域-国", "noun-proper-place-country");
translations.put("名詞-代名詞", "noun-pronoun");
translations.put("名詞-代名詞-一般", "noun-pronoun-misc");
translations.put("名詞-代名詞-縮約", "noun-pronoun-contraction");
translations.put("名詞-副詞可能", "noun-adverbial");
translations.put("名詞-サ変接続", "noun-verbal");
translations.put("名詞-形容動詞語幹", "noun-adjective-base");
translations.put("名詞-数", "noun-numeric");
translations.put("名詞-非自立", "noun-affix");
translations.put("名詞-非自立-一般", "noun-affix-misc");
translations.put("名詞-非自立-副詞可能", "noun-affix-adverbial");
translations.put("名詞-非自立-助動詞語幹", "noun-affix-aux");
translations.put("名詞-非自立-形容動詞語幹", "noun-affix-adjective-base");
translations.put("名詞-特殊", "noun-special");
translations.put("名詞-特殊-助動詞語幹", "noun-special-aux");
translations.put("名詞-接尾", "noun-suffix");
translations.put("名詞-接尾-一般", "noun-suffix-misc");
translations.put("名詞-接尾-人名", "noun-suffix-person");
translations.put("名詞-接尾-地域", "noun-suffix-place");
translations.put("名詞-接尾-サ変接続", "noun-suffix-verbal");
translations.put("名詞-接尾-助動詞語幹", "noun-suffix-aux");
translations.put("名詞-接尾-形容動詞語幹", "noun-suffix-adjective-base");
translations.put("名詞-接尾-副詞可能", "noun-suffix-adverbial");
translations.put("名詞-接尾-助数詞", "noun-suffix-classifier");
translations.put("名詞-接尾-特殊", "noun-suffix-special");
translations.put("名詞-接続詞的", "noun-suffix-conjunctive");
translations.put("名詞-動詞非自立的", "noun-verbal_aux");
translations.put("名詞-引用文字列", "noun-quotation");
translations.put("名詞-ナイ形容詞語幹", "noun-nai_adjective");
translations.put("接頭詞", "prefix");
translations.put("接頭詞-名詞接続", "prefix-nominal");
translations.put("接頭詞-動詞接続", "prefix-verbal");
translations.put("接頭詞-形容詞接続", "prefix-adjectival");
translations.put("接頭詞-数接続", "prefix-numerical");
translations.put("動詞", "verb");
translations.put("動詞-自立", "verb-main");
translations.put("動詞-非自立", "verb-auxiliary");
translations.put("動詞-接尾", "verb-suffix");
translations.put("形容詞", "adjective");
translations.put("形容詞-自立", "adjective-main");
translations.put("形容詞-非自立", "adjective-auxiliary");
translations.put("形容詞-接尾", "adjective-suffix");
translations.put("副詞", "adverb");
translations.put("副詞-一般", "adverb-misc");
translations.put("副詞-助詞類接続", "adverb-particle_conjunction");
translations.put("連体詞", "adnominal");
translations.put("接続詞", "conjunction");
translations.put("助詞", "particle");
translations.put("助詞-格助詞", "particle-case");
translations.put("助詞-格助詞-一般", "particle-case-misc");
translations.put("助詞-格助詞-引用", "particle-case-quote");
translations.put("助詞-格助詞-連語", "particle-case-compound");
translations.put("助詞-接続助詞", "particle-conjunctive");
translations.put("助詞-係助詞", "particle-dependency");
translations.put("助詞-副助詞", "particle-adverbial");
translations.put("助詞-間投助詞", "particle-interjective");
translations.put("助詞-並立助詞", "particle-coordinate");
translations.put("助詞-終助詞", "particle-final");
translations.put("助詞-副助詞/並立助詞/終助詞", "particle-adverbial/conjunctive/final");
translations.put("助詞-連体化", "particle-adnominalizer");
translations.put("助詞-副詞化", "particle-adnominalizer");
translations.put("助詞-特殊", "particle-special");
translations.put("助動詞", "auxiliary-verb");
translations.put("感動詞", "interjection");
translations.put("記号", "symbol");
translations.put("記号-一般", "symbol-misc");
translations.put("記号-句点", "symbol-period");
translations.put("記号-読点", "symbol-comma");
translations.put("記号-空白", "symbol-space");
translations.put("記号-括弧開", "symbol-open_bracket");
translations.put("記号-括弧閉", "symbol-close_bracket");
translations.put("記号-アルファベット", "symbol-alphabetic");
translations.put("その他", "other");
translations.put("その他-間投", "other-interjection");
translations.put("フィラー", "filler");
translations.put("非言語音", "non-verbal");
translations.put("語断片", "fragment");
translations.put("未知語", "unknown");
posTranslations = Collections.unmodifiableMap(translations);
}
/** Get the english form of a POS tag */
@ -122,67 +126,69 @@ public class ToStringUtil {
}
// a translation map for inflection types, only used for reflectWith
private static final HashMap<String, String> inflTypeTranslations = new HashMap<>();
private static final Map<String, String> inflTypeTranslations;
static {
inflTypeTranslations.put("*", "*");
inflTypeTranslations.put("形容詞・アウオ段", "adj-group-a-o-u");
inflTypeTranslations.put("形容詞・イ段", "adj-group-i");
inflTypeTranslations.put("形容詞・イイ", "adj-group-ii");
inflTypeTranslations.put("不変化型", "non-inflectional");
inflTypeTranslations.put("特殊・タ", "special-da");
inflTypeTranslations.put("特殊・ダ", "special-ta");
inflTypeTranslations.put("文語・ゴトシ", "classical-gotoshi");
inflTypeTranslations.put("特殊・ジャ", "special-ja");
inflTypeTranslations.put("特殊・ナイ", "special-nai");
inflTypeTranslations.put("五段・ラ行特殊", "5-row-cons-r-special");
inflTypeTranslations.put("特殊・ヌ", "special-nu");
inflTypeTranslations.put("文語・キ", "classical-ki");
inflTypeTranslations.put("特殊・タイ", "special-tai");
inflTypeTranslations.put("文語・ベシ", "classical-beshi");
inflTypeTranslations.put("特殊・ヤ", "special-ya");
inflTypeTranslations.put("文語・マジ", "classical-maji");
inflTypeTranslations.put("下二・タ行", "2-row-lower-cons-t");
inflTypeTranslations.put("特殊・デス", "special-desu");
inflTypeTranslations.put("特殊・マス", "special-masu");
inflTypeTranslations.put("五段・ラ行アル", "5-row-aru");
inflTypeTranslations.put("文語・ナリ", "classical-nari");
inflTypeTranslations.put("文語・リ", "classical-ri");
inflTypeTranslations.put("文語・ケリ", "classical-keri");
inflTypeTranslations.put("文語・ル", "classical-ru");
inflTypeTranslations.put("五段・カ行イ音便", "5-row-cons-k-i-onbin");
inflTypeTranslations.put("五段・サ行", "5-row-cons-s");
inflTypeTranslations.put("一段", "1-row");
inflTypeTranslations.put("五段・ワ行促音便", "5-row-cons-w-cons-onbin");
inflTypeTranslations.put("五段・マ行", "5-row-cons-m");
inflTypeTranslations.put("五段・タ行", "5-row-cons-t");
inflTypeTranslations.put("五段・ラ行", "5-row-cons-r");
inflTypeTranslations.put("サ変・−スル", "irregular-suffix-suru");
inflTypeTranslations.put("五段・ガ行", "5-row-cons-g");
inflTypeTranslations.put("サ変・−ズル", "irregular-suffix-zuru");
inflTypeTranslations.put("五段・バ行", "5-row-cons-b");
inflTypeTranslations.put("五段・ワ行ウ音便", "5-row-cons-w-u-onbin");
inflTypeTranslations.put("下二・ダ行", "2-row-lower-cons-d");
inflTypeTranslations.put("五段・カ行促音便ユク", "5-row-cons-k-cons-onbin-yuku");
inflTypeTranslations.put("上二・ダ行", "2-row-upper-cons-d");
inflTypeTranslations.put("五段・カ行促音便", "5-row-cons-k-cons-onbin");
inflTypeTranslations.put("一段・得ル", "1-row-eru");
inflTypeTranslations.put("四段・タ行", "4-row-cons-t");
inflTypeTranslations.put("五段・ナ行", "5-row-cons-n");
inflTypeTranslations.put("下二・ハ行", "2-row-lower-cons-h");
inflTypeTranslations.put("四段・ハ行", "4-row-cons-h");
inflTypeTranslations.put("四段・バ行", "4-row-cons-b");
inflTypeTranslations.put("サ変・スル", "irregular-suru");
inflTypeTranslations.put("上二・ハ行", "2-row-upper-cons-h");
inflTypeTranslations.put("下二・マ行", "2-row-lower-cons-m");
inflTypeTranslations.put("四段・サ行", "4-row-cons-s");
inflTypeTranslations.put("下二・ガ行", "2-row-lower-cons-g");
inflTypeTranslations.put("カ変・来ル", "kuru-kanji");
inflTypeTranslations.put("一段・クレル", "1-row-kureru");
inflTypeTranslations.put("下二・得", "2-row-lower-u");
inflTypeTranslations.put("カ変・クル", "kuru-kana");
inflTypeTranslations.put("ラ変", "irregular-cons-r");
inflTypeTranslations.put("下二・カ行", "2-row-lower-cons-k");
Map<String, String> translations = new HashMap<>();
translations.put("*", "*");
translations.put("形容詞・アウオ段", "adj-group-a-o-u");
translations.put("形容詞・イ段", "adj-group-i");
translations.put("形容詞・イイ", "adj-group-ii");
translations.put("不変化型", "non-inflectional");
translations.put("特殊・タ", "special-da");
translations.put("特殊・ダ", "special-ta");
translations.put("文語・ゴトシ", "classical-gotoshi");
translations.put("特殊・ジャ", "special-ja");
translations.put("特殊・ナイ", "special-nai");
translations.put("五段・ラ行特殊", "5-row-cons-r-special");
translations.put("特殊・ヌ", "special-nu");
translations.put("文語・キ", "classical-ki");
translations.put("特殊・タイ", "special-tai");
translations.put("文語・ベシ", "classical-beshi");
translations.put("特殊・ヤ", "special-ya");
translations.put("文語・マジ", "classical-maji");
translations.put("下二・タ行", "2-row-lower-cons-t");
translations.put("特殊・デス", "special-desu");
translations.put("特殊・マス", "special-masu");
translations.put("五段・ラ行アル", "5-row-aru");
translations.put("文語・ナリ", "classical-nari");
translations.put("文語・リ", "classical-ri");
translations.put("文語・ケリ", "classical-keri");
translations.put("文語・ル", "classical-ru");
translations.put("五段・カ行イ音便", "5-row-cons-k-i-onbin");
translations.put("五段・サ行", "5-row-cons-s");
translations.put("一段", "1-row");
translations.put("五段・ワ行促音便", "5-row-cons-w-cons-onbin");
translations.put("五段・マ行", "5-row-cons-m");
translations.put("五段・タ行", "5-row-cons-t");
translations.put("五段・ラ行", "5-row-cons-r");
translations.put("サ変・−スル", "irregular-suffix-suru");
translations.put("五段・ガ行", "5-row-cons-g");
translations.put("サ変・−ズル", "irregular-suffix-zuru");
translations.put("五段・バ行", "5-row-cons-b");
translations.put("五段・ワ行ウ音便", "5-row-cons-w-u-onbin");
translations.put("下二・ダ行", "2-row-lower-cons-d");
translations.put("五段・カ行促音便ユク", "5-row-cons-k-cons-onbin-yuku");
translations.put("上二・ダ行", "2-row-upper-cons-d");
translations.put("五段・カ行促音便", "5-row-cons-k-cons-onbin");
translations.put("一段・得ル", "1-row-eru");
translations.put("四段・タ行", "4-row-cons-t");
translations.put("五段・ナ行", "5-row-cons-n");
translations.put("下二・ハ行", "2-row-lower-cons-h");
translations.put("四段・ハ行", "4-row-cons-h");
translations.put("四段・バ行", "4-row-cons-b");
translations.put("サ変・スル", "irregular-suru");
translations.put("上二・ハ行", "2-row-upper-cons-h");
translations.put("下二・マ行", "2-row-lower-cons-m");
translations.put("四段・サ行", "4-row-cons-s");
translations.put("下二・ガ行", "2-row-lower-cons-g");
translations.put("カ変・来ル", "kuru-kanji");
translations.put("一段・クレル", "1-row-kureru");
translations.put("下二・得", "2-row-lower-u");
translations.put("カ変・クル", "kuru-kana");
translations.put("ラ変", "irregular-cons-r");
translations.put("下二・カ行", "2-row-lower-cons-k");
inflTypeTranslations = Collections.unmodifiableMap(translations);
}
/** Get the english form of inflection type */
@ -191,37 +197,39 @@ public class ToStringUtil {
}
// a translation map for inflection forms, only used for reflectWith
private static final HashMap<String, String> inflFormTranslations = new HashMap<>();
private static final Map<String, String> inflFormTranslations;
static {
inflFormTranslations.put("*", "*");
inflFormTranslations.put("基本形", "base");
inflFormTranslations.put("文語基本形", "classical-base");
inflFormTranslations.put("未然ヌ接続", "imperfective-nu-connection");
inflFormTranslations.put("未然ウ接続", "imperfective-u-connection");
inflFormTranslations.put("連用タ接続", "conjunctive-ta-connection");
inflFormTranslations.put("連用テ接続", "conjunctive-te-connection");
inflFormTranslations.put("連用ゴザイ接続", "conjunctive-gozai-connection");
inflFormTranslations.put("体言接続", "uninflected-connection");
inflFormTranslations.put("仮定形", "subjunctive");
inflFormTranslations.put("命令e", "imperative-e");
inflFormTranslations.put("仮定縮約1", "conditional-contracted-1");
inflFormTranslations.put("仮定縮約2", "conditional-contracted-2");
inflFormTranslations.put("ガル接続", "garu-connection");
inflFormTranslations.put("未然形", "imperfective");
inflFormTranslations.put("連用形", "conjunctive");
inflFormTranslations.put("音便基本形", "onbin-base");
inflFormTranslations.put("連用デ接続", "conjunctive-de-connection");
inflFormTranslations.put("未然特殊", "imperfective-special");
inflFormTranslations.put("命令i", "imperative-i");
inflFormTranslations.put("連用ニ接続", "conjunctive-ni-connection");
inflFormTranslations.put("命令yo", "imperative-yo");
inflFormTranslations.put("体言接続特殊", "adnominal-special");
inflFormTranslations.put("命令ro", "imperative-ro");
inflFormTranslations.put("体言接続特殊2", "uninflected-special-connection-2");
inflFormTranslations.put("未然レル接続", "imperfective-reru-connection");
inflFormTranslations.put("現代基本形", "modern-base");
inflFormTranslations.put("基本形-促音便", "base-onbin"); // not sure about this
Map<String, String> translations = new HashMap<>();
translations.put("*", "*");
translations.put("基本形", "base");
translations.put("文語基本形", "classical-base");
translations.put("未然ヌ接続", "imperfective-nu-connection");
translations.put("未然ウ接続", "imperfective-u-connection");
translations.put("連用タ接続", "conjunctive-ta-connection");
translations.put("連用テ接続", "conjunctive-te-connection");
translations.put("連用ゴザイ接続", "conjunctive-gozai-connection");
translations.put("体言接続", "uninflected-connection");
translations.put("仮定形", "subjunctive");
translations.put("命令e", "imperative-e");
translations.put("仮定縮約1", "conditional-contracted-1");
translations.put("仮定縮約2", "conditional-contracted-2");
translations.put("ガル接続", "garu-connection");
translations.put("未然形", "imperfective");
translations.put("連用形", "conjunctive");
translations.put("音便基本形", "onbin-base");
translations.put("連用デ接続", "conjunctive-de-connection");
translations.put("未然特殊", "imperfective-special");
translations.put("命令i", "imperative-i");
translations.put("連用ニ接続", "conjunctive-ni-connection");
translations.put("命令yo", "imperative-yo");
translations.put("体言接続特殊", "adnominal-special");
translations.put("命令ro", "imperative-ro");
translations.put("体言接続特殊2", "uninflected-special-connection-2");
translations.put("未然レル接続", "imperfective-reru-connection");
translations.put("現代基本形", "modern-base");
translations.put("基本形-促音便", "base-onbin"); // not sure about this
inflFormTranslations = Collections.unmodifiableMap(translations);
}
/** Get the english form of inflected form */

View File

@ -21,6 +21,7 @@ import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.text.ParseException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@ -67,7 +68,7 @@ public class ExpressionsBenchmark {
lookup.findStatic(
lookup.lookupClass(), "ident", MethodType.methodType(double.class, double.class)));
m.put("mh_identity", MethodHandles.identity(double.class));
return m;
return Collections.unmodifiableMap(m);
} catch (ReflectiveOperationException e) {
throw new AssertionError(e);
}

View File

@ -21,7 +21,6 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.xml.XMLConstants;
@ -68,7 +67,7 @@ public class EnwikiContentSource extends ContentSource {
private boolean stopped = false;
private String[] tuple;
private NoMoreDataException nmde;
private StringBuilder contents = new StringBuilder();
private final StringBuilder contents = new StringBuilder();
private String title;
private String body;
private String time;
@ -262,7 +261,6 @@ public class EnwikiContentSource extends ContentSource {
}
}
private static final Map<String, Integer> ELEMENTS = new HashMap<>();
private static final int TITLE = 0;
private static final int DATE = TITLE + 1;
private static final int BODY = DATE + 1;
@ -272,24 +270,24 @@ public class EnwikiContentSource extends ContentSource {
// should not be part of the tuple, we should define them after LENGTH.
private static final int PAGE = LENGTH + 1;
private static final Map<String, Integer> ELEMENTS =
Map.of(
"page", PAGE,
"text", BODY,
"timestamp", DATE,
"title", TITLE,
"id", ID);
private static final String[] months = {
"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
};
static {
ELEMENTS.put("page", Integer.valueOf(PAGE));
ELEMENTS.put("text", Integer.valueOf(BODY));
ELEMENTS.put("timestamp", Integer.valueOf(DATE));
ELEMENTS.put("title", Integer.valueOf(TITLE));
ELEMENTS.put("id", Integer.valueOf(ID));
}
/**
* Returns the type of the element if defined, otherwise returns -1. This method is useful in
* startElement and endElement, by not needing to compare the element qualified name over and
* over.
*/
private static final int getElementType(String elem) {
private static int getElementType(String elem) {
Integer val = ELEMENTS.get(elem);
return val == null ? -1 : val.intValue();
}
@ -297,7 +295,7 @@ public class EnwikiContentSource extends ContentSource {
private Path file;
private boolean keepImages = true;
private InputStream is;
private Parser parser = new Parser();
private final Parser parser = new Parser();
@Override
public void close() throws IOException {

View File

@ -18,6 +18,8 @@ package org.apache.lucene.benchmark.byTask.feeds;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@ -40,22 +42,28 @@ public abstract class TrecDocParser {
/** trec parser type used for unknown extensions */
public static final ParsePathType DEFAULT_PATH_TYPE = ParsePathType.GOV2;
static final Map<ParsePathType, TrecDocParser> pathType2parser = new HashMap<>();
static final Map<ParsePathType, TrecDocParser> pathType2Parser;
static {
pathType2parser.put(ParsePathType.GOV2, new TrecGov2Parser());
pathType2parser.put(ParsePathType.FBIS, new TrecFBISParser());
pathType2parser.put(ParsePathType.FR94, new TrecFR94Parser());
pathType2parser.put(ParsePathType.FT, new TrecFTParser());
pathType2parser.put(ParsePathType.LATIMES, new TrecLATimesParser());
pathType2Parser =
Collections.unmodifiableMap(
new EnumMap<>(
Map.of(
ParsePathType.GOV2, new TrecGov2Parser(),
ParsePathType.FBIS, new TrecFBISParser(),
ParsePathType.FR94, new TrecFR94Parser(),
ParsePathType.FT, new TrecFTParser(),
ParsePathType.LATIMES, new TrecLATimesParser())));
}
static final Map<String, ParsePathType> pathName2Type = new HashMap<>();
static final Map<String, ParsePathType> pathName2Type;
static {
Map<String, ParsePathType> name2Type = new HashMap<>();
for (ParsePathType ppt : ParsePathType.values()) {
pathName2Type.put(ppt.name().toUpperCase(Locale.ROOT), ppt);
name2Type.put(ppt.name().toUpperCase(Locale.ROOT), ppt);
}
pathName2Type = Collections.unmodifiableMap(name2Type);
}
/** max length of walk up from file to its ancestors when looking for a known path type */

View File

@ -32,6 +32,6 @@ public class TrecParserByPath extends TrecDocParser {
StringBuilder docBuf,
ParsePathType pathType)
throws IOException {
return pathType2parser.get(pathType).parse(docData, name, trecSrc, docBuf, pathType);
return pathType2Parser.get(pathType).parse(docData, name, trecSrc, docBuf, pathType);
}
}

View File

@ -23,7 +23,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.compress.compressors.CompressorException;
@ -70,15 +69,9 @@ public class StreamUtils {
}
}
private static final Map<String, Type> extensionToType = new HashMap<>();
static {
// these in are lower case, we will lower case at the test as well
extensionToType.put(".bz2", Type.BZIP2);
extensionToType.put(".bzip", Type.BZIP2);
extensionToType.put(".gz", Type.GZIP);
extensionToType.put(".gzip", Type.GZIP);
}
// these are in lower case, we will lower case at the test as well
private static final Map<String, Type> extensionToType =
Map.of(".bz2", Type.BZIP2, ".bzip", Type.BZIP2, ".gz", Type.GZIP, ".gzip", Type.GZIP);
/**
* Returns an {@link InputStream} over the requested file. This method attempts to identify the

View File

@ -21,6 +21,7 @@ import java.io.StreamTokenizer;
import java.io.StringReader;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@ -404,21 +405,23 @@ public class SimpleWKTShapeParser {
ENVELOPE("envelope"); // not part of the actual WKB spec
private final String shapeName;
private static final Map<String, ShapeType> shapeTypeMap = new HashMap<>();
private static final Map<String, ShapeType> shapeTypeMap;
private static final String BBOX = "BBOX";
static {
Map<String, ShapeType> shapeTypes = new HashMap<>();
for (ShapeType type : values()) {
shapeTypeMap.put(type.shapeName, type);
shapeTypes.put(type.shapeName, type);
}
shapeTypeMap.put(ENVELOPE.wktName().toLowerCase(Locale.ROOT), ENVELOPE);
shapeTypes.put(ENVELOPE.wktName().toLowerCase(Locale.ROOT), ENVELOPE);
shapeTypeMap = Collections.unmodifiableMap(shapeTypes);
}
ShapeType(String shapeName) {
this.shapeName = shapeName;
}
protected String typename() {
String typename() {
return shapeName;
}

View File

@ -820,7 +820,7 @@ public final class JavascriptCompiler {
*/
public static final Map<String, MethodHandle> DEFAULT_FUNCTIONS = loadDefaultFunctions();
private static final Map<String, MethodHandle> loadDefaultFunctions() {
private static Map<String, MethodHandle> loadDefaultFunctions() {
final Map<String, MethodHandle> map = new HashMap<>();
final Lookup publicLookup = MethodHandles.publicLookup();
try {
@ -852,7 +852,7 @@ public final class JavascriptCompiler {
} catch (ReflectiveOperationException | IOException e) {
throw new Error("Cannot resolve function", e);
}
return Map.copyOf(map);
return Collections.unmodifiableMap(map);
}
/** Check Method signature for compatibility. */

View File

@ -239,7 +239,7 @@ public class TestDiversifiedTopDocsCollector extends LuceneTestCase {
}
// Test data - format is artist, song, weeks at top of charts
private static String[] hitsOfThe60s = {
private static final String[] hitsOfThe60s = {
"1966\tSPENCER DAVIS GROUP\tKEEP ON RUNNING\t1",
"1966\tOVERLANDERS\tMICHELLE\t3",
"1966\tNANCY SINATRA\tTHESE BOOTS ARE MADE FOR WALKIN'\t4",
@ -317,7 +317,7 @@ public class TestDiversifiedTopDocsCollector extends LuceneTestCase {
"1969\tARCHIES\tSUGAR, SUGAR\t4"
};
private static final Map<String, Record> parsedRecords = new HashMap<String, Record>();
private static final Map<String, Record> parsedRecords = new HashMap<>();
private Directory dir;
private IndexReader reader;
private IndexSearcher searcher;
@ -452,7 +452,7 @@ public class TestDiversifiedTopDocsCollector extends LuceneTestCase {
private int getMaxNumRecordsPerArtist(ScoreDoc[] sd) throws IOException {
int result = 0;
HashMap<String, Integer> artistCounts = new HashMap<String, Integer>();
HashMap<String, Integer> artistCounts = new HashMap<>();
for (int i = 0; i < sd.length; i++) {
Document doc = reader.storedFields().document(sd[i].doc);
Record record = parsedRecords.get(doc.get("id"));

View File

@ -17,7 +17,9 @@
package org.apache.lucene.queries.payloads;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;
import org.apache.lucene.queries.payloads.SpanPayloadCheckQuery.MatchOperation;
import org.apache.lucene.queries.payloads.SpanPayloadCheckQuery.PayloadType;
import org.apache.lucene.util.ArrayUtil;
@ -30,32 +32,45 @@ import org.apache.lucene.util.BytesRef;
*/
public class PayloadMatcherFactory {
private static final EnumMap<PayloadType, EnumMap<MatchOperation, PayloadMatcher>>
private static final Map<PayloadType, Map<MatchOperation, PayloadMatcher>>
payloadCheckerOpTypeMap;
static {
payloadCheckerOpTypeMap = new EnumMap<>(PayloadType.class);
// ints
EnumMap<MatchOperation, PayloadMatcher> intCheckers = new EnumMap<>(MatchOperation.class);
intCheckers.put(MatchOperation.LT, new LTIntPayloadMatcher());
intCheckers.put(MatchOperation.LTE, new LTEIntPayloadMatcher());
intCheckers.put(MatchOperation.GT, new GTIntPayloadMatcher());
intCheckers.put(MatchOperation.GTE, new GTEIntPayloadMatcher());
EnumMap<MatchOperation, PayloadMatcher> floatCheckers = new EnumMap<>(MatchOperation.class);
floatCheckers.put(MatchOperation.LT, new LTFloatPayloadMatcher());
floatCheckers.put(MatchOperation.LTE, new LTEFloatPayloadMatcher());
floatCheckers.put(MatchOperation.GT, new GTFloatPayloadMatcher());
floatCheckers.put(MatchOperation.GTE, new GTEFloatPayloadMatcher());
Map<MatchOperation, PayloadMatcher> intCheckers =
Collections.unmodifiableMap(
new EnumMap<>(
Map.of(
MatchOperation.LT, new LTIntPayloadMatcher(),
MatchOperation.LTE, new LTEIntPayloadMatcher(),
MatchOperation.GT, new GTIntPayloadMatcher(),
MatchOperation.GTE, new GTEIntPayloadMatcher())));
// floats
Map<MatchOperation, PayloadMatcher> floatCheckers =
Collections.unmodifiableMap(
new EnumMap<>(
Map.of(
MatchOperation.LT, new LTFloatPayloadMatcher(),
MatchOperation.LTE, new LTEFloatPayloadMatcher(),
MatchOperation.GT, new GTFloatPayloadMatcher(),
MatchOperation.GTE, new GTEFloatPayloadMatcher())));
// strings
EnumMap<MatchOperation, PayloadMatcher> stringCheckers = new EnumMap<>(MatchOperation.class);
stringCheckers.put(MatchOperation.LT, new LTStringPayloadMatcher());
stringCheckers.put(MatchOperation.LTE, new LTEStringPayloadMatcher());
stringCheckers.put(MatchOperation.GT, new GTStringPayloadMatcher());
stringCheckers.put(MatchOperation.GTE, new GTEStringPayloadMatcher());
Map<MatchOperation, PayloadMatcher> stringCheckers =
Collections.unmodifiableMap(
new EnumMap<>(
Map.of(
MatchOperation.LT, new LTStringPayloadMatcher(),
MatchOperation.LTE, new LTEStringPayloadMatcher(),
MatchOperation.GT, new GTStringPayloadMatcher(),
MatchOperation.GTE, new GTEStringPayloadMatcher())));
// load the matcher maps per payload type
payloadCheckerOpTypeMap.put(PayloadType.INT, intCheckers);
payloadCheckerOpTypeMap.put(PayloadType.FLOAT, floatCheckers);
payloadCheckerOpTypeMap.put(PayloadType.STRING, stringCheckers);
payloadCheckerOpTypeMap =
Collections.unmodifiableMap(
new EnumMap<>(
Map.of(
PayloadType.INT, intCheckers,
PayloadType.FLOAT, floatCheckers,
PayloadType.STRING, stringCheckers)));
}
/**
@ -75,7 +90,7 @@ public class PayloadMatcherFactory {
return new EQPayloadMatcher();
}
// otherwise, we need to pay attention to the payload type and operation
EnumMap<MatchOperation, PayloadMatcher> opMap = payloadCheckerOpTypeMap.get(payloadType);
Map<MatchOperation, PayloadMatcher> opMap = payloadCheckerOpTypeMap.get(payloadType);
if (opMap != null) {
return opMap.get(op);
} else {

View File

@ -19,6 +19,7 @@ package org.apache.lucene.spatial.prefix.tree;
import com.google.common.geometry.S2CellId;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -63,7 +64,7 @@ class S2PrefixTreeCell implements CellCanPrune {
for (int i = 0; i < TOKENS.length; i++) {
pixels.put(TOKENS[i], i);
}
PIXELS = Map.copyOf(pixels);
PIXELS = Collections.unmodifiableMap(pixels);
}
S2CellId cellId;