<commit_before>package nl.sense_os.commonsense.client.utility;

import nl.sense_os.commonsense.shared.TagModel;

import com.extjs.gxt.ui.client.data.ModelKeyProvider;
import com.extjs.gxt.ui.client.data.TreeModel;

/**
 * Key provider to help grids and trees distinguish between different sensors.
 */
public class SenseKeyProvider<M extends TreeModel> implements ModelKeyProvider<M> {

    private static final String TAG = "SenseKeyProvider";

    @Override
    public String getKey(M model) {
        String key = "";

        while (model != null) {
            if (false == model.getProperties().containsKey("tagType")) {
                Log.e(TAG, "No tagType?!?!");
                for (String property : model.getPropertyNames()) {
                    Log.e(TAG, "  " + model.get(property));
                }
                model = (M) model.getParent();
                continue;
            }
            key += getPartialKey(model);
            model = (M) model.getParent();
        }
        return key;
    }

    private String getPartialKey(M model) {
        int tagType = model.get("tagType");
        switch (tagType) {
            case TagModel.TYPE_DEVICE :
                return "D_" + model.<String> get("id") + ": " + model.<String> get("uuid") + "; ";
            case TagModel.TYPE_GROUP :
                return "G_" + model.<String> get("id") + ": " + model.<String> get("text") + "; ";
            case TagModel.TYPE_SENSOR :
                return "S_" + model.<String> get("id") + ": " + model.<String> get("text") + "; ";
            case TagModel.TYPE_SERVICE :
                return "X_" + model.<String> get("id") + ": " + model.<String> get("text") + "; ";
            case TagModel.TYPE_USER :
                return "U_" + model.<String> get("id") + ": " + model.<String> get("text") + "; ";
            case TagModel.TYPE_CATEGORY :
                return "C_" + model.<String> get("text") + "; ";
            default :
                Log.d(TAG, "Unexpected tagType");
                return "error";
        }
    }
}<commit_msg>stop using tagtype property, use instanceof instead<commit_after>package nl.sense_os.commonsense.client.utility;

import nl.sense_os.commonsense.shared.DeviceModel;
import nl.sense_os.commonsense.shared.GroupModel;
import nl.sense_os.commonsense.shared.SensorModel;
import nl.sense_os.commonsense.shared.UserModel;

import com.extjs.gxt.ui.client.data.ModelKeyProvider;
import com.extjs.gxt.ui.client.data.TreeModel;

/**
 * Key provider to help grids and trees distinguish between different sensors.
 */
public class SenseKeyProvider<M extends TreeModel> implements ModelKeyProvider<M> {

    private static final String TAG = "SenseKeyProvider";

    @SuppressWarnings("unchecked")
    @Override
    public String getKey(M model) {
        String key = "";
        while (model != null) {
            key += getPartialKey(model);
            model = (M) model.getParent();
        }
        return key;
    }

    private String getPartialKey(M model) {

        if (model instanceof DeviceModel) {
            DeviceModel device = (DeviceModel) model;
            return "D_" + device.getId() + ": " + device.getUuid() + "; ";
        } else if (model instanceof GroupModel) {
            GroupModel group = (GroupModel) model;
            return "G_" + group.getId() + ": " + group.getName() + "; ";
        } else if (model instanceof SensorModel) {
            SensorModel sensor = (SensorModel) model;
            return "S_" + sensor.getId() + ": " + sensor.getDisplayName() + "; ";
        } else if (model instanceof UserModel) {
            UserModel user = (UserModel) model;
            return "U_" + user.getId() + ": " + user.getName() + "; ";
        } else {
            Log.e(TAG, "Unexpected class: " + model);
            return model + "; ";
        }
    }
}
{'fraction_non_alphanumeric': 0.13829787234042554, 'fraction_numerical': 0.0, 'mean_word_length': 2.201827242524917, 'pattern_counts': {'":': 9, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '257418', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1092, 'n_words': 250}