<commit_before>package com.zelory.kace.adressbook.data.model;

import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.zelory.kace.adressbook.util.JsonParser;
import lombok.Getter;
import lombok.Setter;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
public class AddressBook {
    private String name;
    private List<Person> persons;
    private String path;

    public AddressBook() {
        this("Untitled", new ArrayList<>());
    }

    public AddressBook(File file) throws IOException, JsonSyntaxException {
        StringBuilder data = new StringBuilder();
        Files.lines(Paths.get(file.getAbsolutePath()), StandardCharsets.UTF_8).forEach(data::append);
        name = file.getName();
        persons = JsonParser.getInstance().getParser().fromJson(data.toString(), new TypeToken<List<Person>>() {}.getType());
        path = file.getAbsolutePath();
    }

    public AddressBook(String name, List<Person> persons) {
        this.name = name;
        this.persons = persons;
    }
}<commit_msg>Add method for handling add or update person<commit_after>package com.zelory.kace.adressbook.data.model;

import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.zelory.kace.adressbook.util.JsonParser;
import lombok.Getter;
import lombok.Setter;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
public class AddressBook {

    public static final int PERSON_ADDED = 1;
    public static final int PERSON_UPDATED = 2;

    private String name;
    private List<Person> persons;
    private String path;

    public AddressBook() {
        this("Untitled", new ArrayList<>());
    }

    public AddressBook(File file) throws IOException, JsonSyntaxException {
        StringBuilder data = new StringBuilder();
        Files.lines(Paths.get(file.getAbsolutePath()), StandardCharsets.UTF_8).forEach(data::append);
        name = file.getName();
        persons = JsonParser.getInstance().getParser().fromJson(data.toString(), new TypeToken<List<Person>>() {}.getType());
        path = file.getAbsolutePath();
    }

    public AddressBook(String name, List<Person> persons) {
        this.name = name;
        this.persons = persons;
    }

    public int addOrUpdatePerson(Person person) {
        int pos = persons.indexOf(person);
        if (pos > 0) {
            persons.set(pos, person);
            return PERSON_UPDATED;
        } else {
            persons.add(person);
            return PERSON_ADDED;
        }
    }
}
{'fraction_non_alphanumeric': 0.11597757533286615, 'fraction_numerical': 0.001751927119831815, 'mean_word_length': 3.4749216300940438, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, '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': '3869502', 'n_tokens_mistral': 844, 'n_tokens_neox': 836, 'n_words': 187}