<commit_before>class User {
  constructor(name, id) {
    this.name = name;
    this.id = id;
  }
}

class UserService {
  constructor(name) {
    this.name = name;
    this.users = {};
    this.listeners = {};
  }

  addUser(user) {
    if (!this.users[user.id] || this.users[user.id].name !== user.name) {
      this.users[user.id] = user;
      this.notify('addUser', user);
    }
  }

  deleteUser(user) {
    const userToDelete = this.users[user.id];
    if (userToDelete && userToDelete.name === user.name) {
      delete this.users[user.id];
      this.notify('deleteUser', user);
    }
  }

  getUsers() {
    const result = [];
    for (let userId in this.users) {
      result.push(this.users[userId]);
    }
    return result;
  }

  registerListener(service) {
    if (!this.listeners[service.name]) {
      this.listeners[service.name] = service;
    }
  }

  deregisterListener(service) {
    if (this.listeners[service.name]) {
      delete this.listeners[service.name];
    }
  }

  notify(command, user) {
    for (let serviceName in this.listeners) {
      const service = this.listeners[serviceName];
      if (service) {
        switch (command) {
          case 'addUser':
            return service.addUser(user);
          case 'deleteUser':
            return service.deleteUser(user);
          default:
            break;
        }
      }
    }
  }
}

const service1 = new UserService('u1');
service1.addUser(new User('mary', 1));
service1.addUser(new User('mary', 1));
console.log(service1.getUsers());

service1.deleteUser(new User('mary', 1));
console.log(service1.getUsers());

const service2 = new UserService('u2');

service1.registerListener(service2);
service1.addUser('su', 2);
console.log(service1.getUsers());
console.log(service2.getUsers());<commit_msg>fix some bugs<commit_after>class User {
  constructor(name, id) {
    this.name = name;
    this.id = id;
  }
}

class UserService {
  constructor(name) {
    this.name = name;
    this.users = {};
    this.listeners = {};
  }

  addUser(user) {
    if (!this.users[user.id] || this.users[user.id].name !== user.name) {
      this.users[user.id] = user;
      this.notify('addUser', user);
    }
  }

  deleteUser(user) {
    const userToDelete = this.users[user.id];
    if (userToDelete && userToDelete.name === user.name) {
      delete this.users[user.id];
      this.notify('deleteUser', user);
    }
  }

  getUsers() {
    const result = [];
    for (let userId in this.users) {
      result.push(this.users[userId]);
    }
    return result.sort((a, b) => a.id - b.id);
  }

  registerListener(service) {
    if (!this.listeners[service.name]) {
      this.listeners[service.name] = service;
    }
  }

  deregisterListener(service) {
    if (this.listeners[service.name]) {
      delete this.listeners[service.name];
    }
  }

  notify(command, user) {
    for (let serviceName in this.listeners) {
      const service = this.listeners[serviceName];
      if (service) {
        switch (command) {
          case 'addUser':
            return service.addUser(user);
          case 'deleteUser':
            return service.deleteUser(user);
          default:
            break;
        }
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.1529595015576324, 'fraction_numerical': 0.005607476635514018, 'mean_word_length': 2.509289617486339, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6407814', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1060, 'n_words': 190}