<commit_before>/*
 * Axelor Business Solutions
 *
 * Copyright (C) 2005-2018 Axelor (<http://axelor.com>).
 *
 * This program is free software: you can redistribute it and/or  modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.axelor.event;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.inject.Inject;

class EventImpl<T> implements Event<T> {

  private EventBus eventBus;

  private Type eventType;

  private Set<Annotation> qualifiers;

  @Inject
  public EventImpl(EventBus eventBus) {
    this.eventBus = eventBus;
  }

  public Type getEventType() {
    return eventType;
  }

  public void setEventType(Type eventType) {
    this.eventType = eventType;
  }

  public void addQualifier(Annotation qualifier) {
    if (this.qualifiers == null) {
      this.qualifiers = new HashSet<>();
    }
    this.qualifiers.add(qualifier);
  }

  @Override
  public void fire(T event) {
    eventBus.fire(event, eventType, qualifiers);
  }

  @Override
  public Event<T> select(Annotation... qualifiers) {
    if (qualifiers == null || qualifiers.length == 0) {
      return this;
    }

    EventImpl<T> copy = new EventImpl<>(eventBus);
    copy.eventType = eventType;
    copy.qualifiers = new HashSet<>();

    Arrays.stream(qualifiers).forEach(copy.qualifiers::add);

    return copy;
  }
}<commit_msg>Make Event::select add qualifiers instead of replacing them<commit_after>/*
 * Axelor Business Solutions
 *
 * Copyright (C) 2005-2018 Axelor (<http://axelor.com>).
 *
 * This program is free software: you can redistribute it and/or  modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.axelor.event;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import javax.inject.Inject;

class EventImpl<T> implements Event<T> {

  private EventBus eventBus;

  private Type eventType;

  private Set<Annotation> qualifiers;

  @Inject
  public EventImpl(EventBus eventBus) {
    this.eventBus = eventBus;
  }

  public Type getEventType() {
    return eventType;
  }

  public void setEventType(Type eventType) {
    this.eventType = eventType;
  }

  public void addQualifier(Annotation qualifier) {
    if (this.qualifiers == null) {
      this.qualifiers = new HashSet<>();
    }
    this.qualifiers.add(qualifier);
  }

  @Override
  public void fire(T event) {
    eventBus.fire(event, eventType, qualifiers);
  }

  @Override
  public Event<T> select(Annotation... qualifiers) {
    if (qualifiers == null || qualifiers.length == 0) {
      return this;
    }

    EventImpl<T> copy = new EventImpl<>(eventBus);
    copy.eventType = eventType;
    copy.qualifiers =
        new HashSet<>(Optional.ofNullable(this.qualifiers).orElse(Collections.emptySet()));

    Arrays.stream(qualifiers).forEach(copy.qualifiers::add);

    return copy;
  }
}
{'fraction_non_alphanumeric': 0.10114598903836572, 'fraction_numerical': 0.004982561036372696, 'mean_word_length': 3.646990740740741, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2272611', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1164, 'n_words': 385}