<commit_before>package io.anand.springboot;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired // This means to get the bean called userRepository
    // Which is auto-generated by Spring, we will use it to handle the data
    private UserRepository userRepository;

    private ArrayList<User> users;

    public UserService () {
        users = new ArrayList<User> ();
        users.add(new User ("John", "Elementary", 192838, 145354545));
        users.add(new User ("Ravi", "Middle", 192298, 145312144));
        users.add(new User ("David", "Elementary", 192848, 145354652));
        users.add(new User ("Mary", "Middle", 192858, 145351234));
        users.add(new User ("Vinh", "High School", 192538, 14534567));
        users.add(new User ("Surya", "High School", 193138, 14538613));
    }

    public List<User> getUsers () {
        return (List<User>) userRepository.findAll();
        // return users;
    }

    public User getUser (String userName) {
        return userRepository.findByName(userName);
        /*
        try {
            return users.stream().filter(u -> u.getName().equals(userName)).findFirst().get();
        } catch (Exception e) {
            System.out.println("Caught Exception looking up user: " + userName + ", e: " + e);
        }
        return null;
        */
    }

    public User updUser (String userName, User updUser) {
        return userRepository.save(updUser);
        /*
        int index = users.indexOf(users.stream().filter(u -> u.getName().equals(userName)).findFirst().get());
        users.set(index, updUser);
        return users.get(index);
         */
    }

    public User addUser (User user) {

        User addedUser = userRepository.save(user);
        users.add(user);
        return addedUser;
    }

    public boolean remUser (User user) {
        userRepository.delete(user);
        boolean deleted = users.remove(getUser(user.getName()));
        System.out.println(deleted ? "Able " : " Unable " + "to remove the user: " + user.toString());
        return deleted;
    }
}<commit_msg>Delete from local array first before removing from database, otherwise delete fails to find the intem in the get call and array will not be updated<commit_after>package io.anand.springboot;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired // This means to get the bean called userRepository
    // Which is auto-generated by Spring, we will use it to handle the data
    private UserRepository userRepository;

    private ArrayList<User> users;

    public UserService () {
        users = new ArrayList<User> ();
        users.add(new User ("John", "Elementary", 192838, 145354545));
        users.add(new User ("Ravi", "Middle", 192298, 145312144));
        users.add(new User ("David", "Elementary", 192848, 145354652));
        users.add(new User ("Mary", "Middle", 192858, 145351234));
        users.add(new User ("Vinh", "High School", 192538, 14534567));
        users.add(new User ("Surya", "High School", 193138, 14538613));
    }

    public List<User> getUsers () {
        return (List<User>) userRepository.findAll();
        // return users;
    }

    public User getUser (String userName) {
        User user = userRepository.findByName(userName);
        if (null == user)
            return user;

        try {
            return users.stream().filter(u -> u.getName().equals(user.getName())).findFirst().get();
        } catch (Exception e) {
            System.out.println("Caught Exception looking up user: " + userName + ", e: " + e);
        }
        return null;
    }

    public User updUser (String userName, User updUser) {
        User user = userRepository.save(updUser);
        if (null == user)
            return user;

        int index = users.indexOf(users.stream().filter(u -> u.getId() == (user.getId())).findFirst().get());
        users.set(index, updUser);
        return users.get(index);
    }

    public User addUser (User user) {
        User addedUser = userRepository.save(user);
        if (null == addedUser)
            return addedUser;

        users.add(user);
        return addedUser;
    }

    public boolean remUser (User user) {
        boolean deleted = users.remove(getUser(user.getName()));
        System.out.println(deleted ? "Able " : " Unable " + "to remove the user: " + user.toString());
        userRepository.delete(user);
        return deleted;
    }
}
{'fraction_non_alphanumeric': 0.1284845944246489, 'fraction_numerical': 0.036889540976734435, 'mean_word_length': 2.7049689440993787, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '979725', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1343, 'n_words': 375}