<commit_before>package com.github.mikhailerofeev.runity.domain.entities;

import com.github.mikhailerofeev.runity.domain.values.ParamValueWithVersionId;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author m-erofeev
 * @since 25.04.14
 */
public class Employee {

    @Id
    private String id;
    private String name;

    //detalisation for mongo purpose
    private Map<String, ArrayList<ParamValueWithVersionId>> param2valueAndVersion;
    private Map<String, Pair<Integer, Integer>> paramRating;

    //for seriazation purposes
    Employee() {

    }

    public Employee(String name) {
        this.name = name;
        param2valueAndVersion = Maps.newHashMap();
        paramRating = Maps.newHashMap();
    }

    public Employee(String name, Map<String, ArrayList<ParamValueWithVersionId>> param2valueAndVersion) {
        this.name = name;
        this.param2valueAndVersion = param2valueAndVersion;
        paramRating = Maps.newHashMap();
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public Map<String, ArrayList<ParamValueWithVersionId>> getParam2valueAndVersion() {
        return Collections.unmodifiableMap(param2valueAndVersion);
    }

    @Override
    public String toString() {
        return new Gson().toJson(this);
    }

    public void addParam(String names, ParamValueWithVersionId newValue) {
        ArrayList<ParamValueWithVersionId> values = param2valueAndVersion.get(names);
        if (values == null) {
            values = Lists.newArrayList();
            param2valueAndVersion.put(names, values);
        }
        if (newValue.isActual()) {
            for (ParamValueWithVersionId value : values) {
                value.setActual(false);
            }
        }
        values.add(newValue);
    }

    public String getActualParamVaue(String paramName) {
        final List<ParamValueWithVersionId> values = param2valueAndVersion.get(paramName);
        if (values == null) {
            return null;
        }
        for (ParamValueWithVersionId paramValueWithVersionId : values) {
            if (paramValueWithVersionId.isActual()) {
                return paramValueWithVersionId.getValue();
            }
        }
        return null;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Employee)) return false;

        Employee employee = (Employee) o;

        if (id != null ? !id.equals(employee.id) : employee.id != null) return false;
        if (name != null ? !name.equals(employee.name) : employee.name != null) return false;
        if (param2valueAndVersion != null ? !param2valueAndVersion.equals(employee.param2valueAndVersion) : employee.param2valueAndVersion != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (param2valueAndVersion != null ? param2valueAndVersion.hashCode() : 0);
        return result;
    }

    public Map<String, Pair<Integer, Integer>> getParamRating() {
        return paramRating;
    }

    public void addParamRating(String param) {
        this.paramRating.put(param, Pair.of(0, 0));
    }

    public void increaseParamRating(String param) {
        Pair<Integer, Integer> rating = this.paramRating.get(param);<commit_msg>Employee fix for null rating<commit_after>package com.github.mikhailerofeev.runity.domain.entities;

import com.github.mikhailerofeev.runity.domain.values.ParamValueWithVersionId;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author m-erofeev
 * @since 25.04.14
 */
public class Employee {

    @Id
    private String id;
    private String name;

    //detalisation for mongo purpose
    private Map<String, ArrayList<ParamValueWithVersionId>> param2valueAndVersion;
    private Map<String, Pair<Integer, Integer>> paramRating;

    //for seriazation purposes
    Employee() {

    }

    public Employee(String name) {
        this.name = name;
        param2valueAndVersion = Maps.newHashMap();
        paramRating = Maps.newHashMap();
    }

    public Employee(String name, Map<String, ArrayList<ParamValueWithVersionId>> param2valueAndVersion) {
        this.name = name;
        this.param2valueAndVersion = param2valueAndVersion;
        paramRating = Maps.newHashMap();
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public Map<String, ArrayList<ParamValueWithVersionId>> getParam2valueAndVersion() {
        return Collections.unmodifiableMap(param2valueAndVersion);
    }

    @Override
    public String toString() {
        return new Gson().toJson(this);
    }

    public void addParam(String names, ParamValueWithVersionId newValue) {
        ArrayList<ParamValueWithVersionId> values = param2valueAndVersion.get(names);
        if (values == null) {
            values = Lists.newArrayList();
            param2valueAndVersion.put(names, values);
        }
        if (newValue.isActual()) {
            for (ParamValueWithVersionId value : values) {
                value.setActual(false);
            }
        }
        values.add(newValue);
    }

    public String getActualParamVaue(String paramName) {
        final List<ParamValueWithVersionId> values = param2valueAndVersion.get(paramName);
        if (values == null) {
            return null;
        }
        for (ParamValueWithVersionId paramValueWithVersionId : values) {
            if (paramValueWithVersionId.isActual()) {
                return paramValueWithVersionId.getValue();
            }
        }
        return null;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Employee)) return false;

        Employee employee = (Employee) o;

        if (id != null ? !id.equals(employee.id) : employee.id != null) return false;
        if (name != null ? !name.equals(employee.name) : employee.name != null) return false;
        if (param2valueAndVersion != null ? !param2valueAndVersion.equals(employee.param2valueAndVersion) : employee.param2valueAndVersion != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (param2valueAndVersion != null ? param2valueAndVersion.hashCode() : 0);
        return result;
    }

    public Map<String, Pair<Integer, Integer>> getParamRating() {
        return paramRating;
    }

    public void addParamRating(String param) {
        this.paramRating.put(param, Pair.of(0, 0));
    }
    public void setParamRating(Map<String, Pair<Integer, Integer>> paramRating) {
        if(paramRating == null) {
            this.paramRating = Maps.newHashMap();
        }else{
            this.paramRating = paramRating;
        }
    }

    public void increaseParamRating(String param) {
        Pair<Integer, Integer> rating = this.paramRating.get(param);
{'fraction_non_alphanumeric': 0.10430463576158941, 'fraction_numerical': 0.00815078960774325, 'mean_word_length': 2.750238777459408, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '7323559', 'n_tokens_mistral': 2333, 'n_tokens_neox': 2204, 'n_words': 496}