/** * Returns an unmodifiable {@link CharArrayMap}. This allows to provide * unmodifiable views of internal map for "read-only" use. * * @param map * a map for which the unmodifiable map is returned. * @return an new unmodifiable {@link CharArrayMap}. * @throws NullPointerException * if the given map is <code>null</code>. */ public static <V> CharArrayMap<V> unmodifiableMap(CharArrayMap<V> map) { if (map == null) throw new NullPointerException("Given map is null"); if (map == emptyMap() || map.isEmpty()) return emptyMap(); if (map instanceof UnmodifiableCharArrayMap) return map; return new UnmodifiableCharArrayMap<V>(map); }
/** * Returns an unmodifiable {@link CharArrayMap}. This allows to provide * unmodifiable views of internal map for "read-only" use. * * @param map * a map for which the unmodifiable map is returned. * @return an new unmodifiable {@link CharArrayMap}. * @throws NullPointerException * if the given map is <code>null</code>. */ public static <V> CharArrayMap<V> unmodifiableMap(CharArrayMap<V> map) { if (map == null) throw new NullPointerException("Given map is null"); if (map == emptyMap() || map.isEmpty()) return emptyMap(); if (map instanceof UnmodifiableCharArrayMap) return map; return new UnmodifiableCharArrayMap<>(map); }
public DutchAnalyzer(CharArraySet stopwords, CharArraySet stemExclusionTable, CharArrayMap<String> stemOverrideDict) { this.stoptable = CharArraySet.unmodifiableSet(CharArraySet.copy(stopwords)); this.excltable = CharArraySet.unmodifiableSet(CharArraySet.copy(stemExclusionTable)); if (stemOverrideDict.isEmpty()) { this.stemdict = null; } else { // we don't need to ignore case here since we lowercase in this analyzer anyway StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder(false); CharArrayMap<String>.EntryIterator iter = stemOverrideDict.entrySet().iterator(); CharsRefBuilder spare = new CharsRefBuilder(); while (iter.hasNext()) { char[] nextKey = iter.nextKey(); spare.copyChars(nextKey, 0, nextKey.length); builder.add(spare.get(), iter.currentValue()); } try { this.stemdict = builder.build(); } catch (IOException ex) { throw new RuntimeException("can not build stem dict", ex); } } }