<commit_before>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package my.home.model.datasource;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import my.home.common.BusProvider;
import my.home.model.entities.AutoCompleteCountHolder;
import my.home.model.entities.AutoCompleteItem;
import my.home.model.entities.AutoCompleteToolItem;
import my.home.model.events.MConfAutoCompleteItemEvent;
import my.home.model.events.MGetAutoCompleteItemEvent;
import my.home.model.events.MSaveAutoCompleteLocalHistoryEvent;

/**
 * Created by legendmohe on 15/2/13.
 */
public class AutoCompleteItemDataSourceImpl implements AutoCompleteItemDataSource {

    public static final String TAG = "ACItemDataSource";

    public static final float DEFAULT_AUTOCOMPLETE_WEIGHT = 0.0f;

    public static AutoCompleteItemDataSourceImpl INSTANCE;

    private Map<String, List<String>> mNodes;
    private Map<String, List<String>> mLinks;
    private String mMessageSeq;
    private String mTimeSeq;
    private String mInitState;
    private boolean mLoadSuccess = false;
    private Map<String, AutoCompleteCountHolder> mAutoCompleteCountHolderMap;
    private HashMap<String, Integer> mWeightDivides;

    private static Comparator<AutoCompleteItem> mResultComparator;

    static {
        mResultComparator = new Comparator<AutoCompleteItem>() {
            @Override
            public int compare(AutoCompleteItem lhs, AutoCompleteItem rhs) {
                return Float.compare(rhs.getWeight(), lhs.getWeight());
            }
        };
    }


    public static AutoCompleteItemDataSourceImpl getInstance() {

        if (INSTANCE == null)
            INSTANCE = new AutoCompleteItemDataSourceImpl();

        return INSTANCE;
    }

    private AutoCompleteItemDataSourceImpl() {
        super();
    }<commit_msg>fix bug: singleInstance thread-safe<commit_after>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package my.home.model.datasource;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import my.home.common.BusProvider;
import my.home.model.entities.AutoCompleteCountHolder;
import my.home.model.entities.AutoCompleteItem;
import my.home.model.entities.AutoCompleteToolItem;
import my.home.model.events.MConfAutoCompleteItemEvent;
import my.home.model.events.MGetAutoCompleteItemEvent;
import my.home.model.events.MSaveAutoCompleteLocalHistoryEvent;

/**
 * Created by legendmohe on 15/2/13.
 */
public class AutoCompleteItemDataSourceImpl implements AutoCompleteItemDataSource {

    public static final String TAG = "ACItemDataSource";

    public static final float DEFAULT_AUTOCOMPLETE_WEIGHT = 0.0f;

    private static AutoCompleteItemDataSourceImpl INSTANCE;

    private Map<String, List<String>> mNodes;
    private Map<String, List<String>> mLinks;
    private String mMessageSeq;
    private String mTimeSeq;
    private String mInitState;
    private boolean mLoadSuccess = false;
    private Map<String, AutoCompleteCountHolder> mAutoCompleteCountHolderMap;
    private HashMap<String, Integer> mWeightDivides;

    private static Comparator<AutoCompleteItem> mResultComparator;

    static {
        mResultComparator = new Comparator<AutoCompleteItem>() {
            @Override
            public int compare(AutoCompleteItem lhs, AutoCompleteItem rhs) {
                return Float.compare(rhs.getWeight(), lhs.getWeight());
            }
        };
    }

    private static class SingletonHolder {  
        private static final AutoCompleteItemDataSourceImpl INSTANCE = new AutoCompleteItemDataSourceImpl();  
    }  

    public static AutoCompleteItemDataSourceImpl getInstance() {
        return SingletonHolder.INSTANCE;
    }

    private AutoCompleteItemDataSourceImpl() {
        super();
    }
{'fraction_non_alphanumeric': 0.08150851581508516, 'fraction_numerical': 0.0038234271810914148, 'mean_word_length': 4.092920353982301, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5834956', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1548, 'n_words': 450}