<commit_before>package com.cloudycrew.cloudycar.requeststorage;

import com.cloudycrew.cloudycar.models.requests.Request;
import com.cloudycrew.cloudycar.observables.IObserver;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import rx.Observable;

/**
 * Created by George on 2016-11-07.
 */

public class RequestStore implements IRequestStore {
    private Map<String, Request> requestMap;
    private Set<IObserver<? super IRequestStore>> observers;

    public RequestStore() {
        this.requestMap = new LinkedHashMap<>();
        this.observers = new HashSet<>();
    }

    @Override
    public Request getRequest(String id) {
        return getRequest(id, Request.class);
    }

    public <T extends Request> T getRequest(String requestId, Class<T> requestClass) {
        return Observable.from(requestMap.values())
                         .filter(r -> r.getId().equals(requestId))
                         .filter(r -> r.getClass().isAssignableFrom(requestClass))
                         .cast(requestClass)
                         .toBlocking()
                         .firstOrDefault(null);
    }

    @Override
    public List<Request> getRequests() {
        return getRequests(Request.class);
    }

    public <T extends Request> List<T> getRequests(Class<T> requestClass) {
        return Observable.from(requestMap.values())
                         .filter(r -> r.getClass().isAssignableFrom(requestClass))
                         .cast(requestClass)
                         .toList()
                         .toBlocking()
                         .firstOrDefault(new ArrayList<>());
    }

    @Override
    public void setAll(Collection<? extends Request> requests) {
        requestMap.clear();
        for (Request request: requests) {
            requestMap.put(request.getId(), request);
        }
    }

    @Override
    public void addRequest(Request request) {
        if (!requestMap.containsKey(request.getId())) {
            requestMap.put(request.getId(), request);
            notifyObservers();
        }
    }

    @Override<commit_msg>Notify observers in RequestStore when setting all requests<commit_after>package com.cloudycrew.cloudycar.requeststorage;

import com.cloudycrew.cloudycar.models.requests.Request;
import com.cloudycrew.cloudycar.observables.IObserver;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import rx.Observable;

/**
 * Created by George on 2016-11-07.
 */

public class RequestStore implements IRequestStore {
    private Map<String, Request> requestMap;
    private Set<IObserver<? super IRequestStore>> observers;

    public RequestStore() {
        this.requestMap = new LinkedHashMap<>();
        this.observers = new HashSet<>();
    }

    @Override
    public Request getRequest(String id) {
        return getRequest(id, Request.class);
    }

    public <T extends Request> T getRequest(String requestId, Class<T> requestClass) {
        return Observable.from(requestMap.values())
                         .filter(r -> r.getId().equals(requestId))
                         .filter(r -> r.getClass().isAssignableFrom(requestClass))
                         .cast(requestClass)
                         .toBlocking()
                         .firstOrDefault(null);
    }

    @Override
    public List<Request> getRequests() {
        return getRequests(Request.class);
    }

    public <T extends Request> List<T> getRequests(Class<T> requestClass) {
        return Observable.from(requestMap.values())
                         .filter(r -> r.getClass().isAssignableFrom(requestClass))
                         .cast(requestClass)
                         .toList()
                         .toBlocking()
                         .firstOrDefault(new ArrayList<>());
    }

    @Override
    public void setAll(Collection<? extends Request> requests) {
        requestMap.clear();
        for (Request request: requests) {
            requestMap.put(request.getId(), request);
        }
        notifyObservers();
    }

    @Override
    public void addRequest(Request request) {
        if (!requestMap.containsKey(request.getId())) {
            requestMap.put(request.getId(), request);
            notifyObservers();
        }
    }

    @Override
{'fraction_non_alphanumeric': 0.10886917960088692, 'fraction_numerical': 0.003547671840354767, 'mean_word_length': 2.2429906542056073, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 35, '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': '1797312', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1191, 'n_words': 251}