<commit_before>package app.lsgui.model;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import app.lsgui.model.twitch.TwitchChannel;
import app.lsgui.service.twitch.TwitchAPIClient;
import app.lsgui.service.twitch.TwitchChannelUpdateService;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.ObservableMap;
import javafx.collections.transformation.SortedList;

public class Service {
    private static final Logger LOGGER = LoggerFactory.getLogger(Service.class);

    private StringProperty name;
    private StringProperty url;
    private ListProperty<Channel> channelProperty;
    private BooleanProperty sortChannels;
    private Comparator<Channel> comp;

    private static final ObservableMap<Channel, TwitchChannelUpdateService> UPDATESERVICES = FXCollections
            .observableHashMap();

    public Service(String name, String url) {
        this.name = new SimpleStringProperty(name);
        this.url = new SimpleStringProperty(url);
        channelProperty = new SimpleListProperty<>();
        sortChannels = new SimpleBooleanProperty();
    }

    public void bindSortProperty(final BooleanProperty property) {
        if (!sortChannels.isBound()) {
            sortChannels.bind(property);
            sortChannels.addListener((obs, oldValue, newValue) -> {
                changeComparator(newValue);
                refreshList();
                LOGGER.info("Change Sorting method and refresh list");
            });
        }
    }

    private void refreshList() {
        ObservableList<Channel> obsChannels = FXCollections.observableArrayList(TwitchChannel.extractor());
        obsChannels.addAll(getChannels().getValue());
        SortedList<Channel> obsChannelsSorted = new SortedList<>(obsChannels);
        obsChannelsSorted.setComparator(comp);
        getChannels().setValue(obsChannelsSorted);
    }

    public void addChannel(final String name) {
        LOGGER.debug("Add Channel to List");
        List<Channel> channels = new ArrayList<>(getChannels().subList(0, getChannels().getSize()));
        Channel sm = new TwitchChannel(name);
        channels.add(sm);
        ObservableList<Channel> obsChannels = FXCollections.observableArrayList(TwitchChannel.extractor());
        obsChannels.addAll(channels);
        SortedList<Channel> obsChannelsSorted = new SortedList<>(obsChannels);
        obsChannelsSorted.setComparator(comp);
        getChannels().setValue(obsChannelsSorted);
        final TwitchChannelUpdateService tcus = new TwitchChannelUpdateService(sm);
        tcus.start();
        UPDATESERVICES.put(sm, tcus);
    }

    public void removeSelectedChannel(final Channel selectedStream) {
        if (selectedStream != null) {
            LOGGER.debug("Remove Channel {} from list", selectedStream.getName());
            List<Channel> channels = getChannels().subList(0, getChannels().getSize());
            channels.remove(selectedStream);
            ObservableList<Channel> obsChannels = FXCollections.observableArrayList(TwitchChannel.extractor());
            obsChannels.addAll(channels);
            SortedList<Channel> obsChannelsSorted = new SortedList<>(obsChannels);
            obsChannelsSorted.setComparator(comp);
            getChannels().setValue(obsChannelsSorted);
            final TwitchChannelUpdateService tcus = UPDATESERVICES.remove(selectedStream);
            tcus.cancel();
        }
    }

    public void addFollowedChannels(final String username) {
        LOGGER.debug("Import followed Streams for user {}", username);
        Set<String> set = TwitchAPIClient.instance().getListOfFollowedStreams(username);
        for (String s : set) {
            addChannel(s);
        }
    }

    private void changeComparator(boolean doSorting) {
        if (!doSorting) {
            comp = (ch1, ch2) -> ch1.getName().get().compareTo(ch2.getName().get());
        } else {
            comp = (ch1, ch2) -> {
                if (ch1.isOnline().get() && !ch2.isOnline().get()) {
                    return -1;
                } else if (!ch1.isOnline().get() && ch2.isOnline().get()) {
                    return 1;
                }
                return 0;
            };
        }
    }

    public ListProperty<Channel> getChannels() {
        return channelProperty;
    }

    public StringProperty getName() {
        return name;
    }

    public StringProperty getUrl() {
        return url;
    }

    public static ObservableMap<Channel, TwitchChannelUpdateService> getUpdateServices() {
        return UPDATESERVICES;
    }

}
<commit_msg>fix starting without any channels<commit_after>package app.lsgui.model;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import app.lsgui.model.twitch.TwitchChannel;
import app.lsgui.service.twitch.TwitchAPIClient;
import app.lsgui.service.twitch.TwitchChannelUpdateService;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.ObservableMap;
import javafx.collections.transformation.SortedList;

public class Service {
    private static final Logger LOGGER = LoggerFactory.getLogger(Service.class);

    private StringProperty name;
    private StringProperty url;
    private ListProperty<Channel> channelProperty;
    private BooleanProperty sortChannels;
    private Comparator<Channel> comp;

    private static final ObservableMap<Channel, TwitchChannelUpdateService> UPDATESERVICES = FXCollections
            .observableHashMap();

    public Service(String name, String url) {
        this.name = new SimpleStringProperty(name);
        this.url = new SimpleStringProperty(url);
        channelProperty = new SimpleListProperty<>();
        sortChannels = new SimpleBooleanProperty();
    }

    public void bindSortProperty(final BooleanProperty property) {
        if (!sortChannels.isBound()) {
            sortChannels.bind(property);
            sortChannels.addListener((obs, oldValue, newValue) -> {
                changeComparator(newValue);
                refreshList();
                LOGGER.info("Change Sorting method and refresh list");
            });
        }
    }

    private void refreshList() {
        if (getChannels().getValue()!= null) {
            ObservableList<Channel> obsChannels = FXCollections.observableArrayList(TwitchChannel.extractor());
            obsChannels.addAll(getChannels().getValue());
            SortedList<Channel> obsChannelsSorted = new SortedList<>(obsChannels);
            obsChannelsSorted.setComparator(comp);
            getChannels().setValue(obsChannelsSorted);
        }
    }

    public void addChannel(final String name) {
        LOGGER.debug("Add Channel to List");
        List<Channel> channels = new ArrayList<>(getChannels().subList(0, getChannels().getSize()));
        Channel sm = new TwitchChannel(name);
        channels.add(sm);
        ObservableList<Channel> obsChannels = FXCollections.observableArrayList(TwitchChannel.extractor());
        obsChannels.addAll(channels);
        SortedList<Channel> obsChannelsSorted = new SortedList<>(obsChannels);
        obsChannelsSorted.setComparator(comp);
        getChannels().setValue(obsChannelsSorted);
        final TwitchChannelUpdateService tcus = new TwitchChannelUpdateService(sm);
        tcus.start();
        UPDATESERVICES.put(sm, tcus);
    }

    public void removeSelectedChannel(final Channel selectedStream) {
        if (selectedStream != null) {
            LOGGER.debug("Remove Channel {} from list", selectedStream.getName());
            List<Channel> channels = getChannels().subList(0, getChannels().getSize());
            channels.remove(selectedStream);
            ObservableList<Channel> obsChannels = FXCollections.observableArrayList(TwitchChannel.extractor());
            obsChannels.addAll(channels);
            SortedList<Channel> obsChannelsSorted = new SortedList<>(obsChannels);
            obsChannelsSorted.setComparator(comp);
            getChannels().setValue(obsChannelsSorted);
            final TwitchChannelUpdateService tcus = UPDATESERVICES.remove(selectedStream);
            tcus.cancel();
        }
    }

    public void addFollowedChannels(final String username) {
        LOGGER.debug("Import followed Streams for user {}", username);
        Set<String> set = TwitchAPIClient.instance().getListOfFollowedStreams(username);
        for (String s : set) {
            addChannel(s);
        }
    }

    private void changeComparator(boolean doSorting) {
        if (!doSorting) {
            comp = (ch1, ch2) -> ch1.getName().get().compareTo(ch2.getName().get());
        } else {
            comp = (ch1, ch2) -> {
                if (ch1.isOnline().get() && !ch2.isOnline().get()) {
                    return -1;
                } else if (!ch1.isOnline().get() && ch2.isOnline().get()) {
                    return 1;
                }
                return 0;
            };
        }
    }

    public ListProperty<Channel> getChannels() {
        return channelProperty;
    }

    public StringProperty getName() {
        return name;
    }

    public StringProperty getUrl() {
        return url;
    }

    public static ObservableMap<Channel, TwitchChannelUpdateService> getUpdateServices() {
        return UPDATESERVICES;
    }

}

{'fraction_non_alphanumeric': 0.10236844713110693, 'fraction_numerical': 0.003369339014963829, 'mean_word_length': 3.0223196492626543, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 47, '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': '2547000', 'n_tokens_mistral': 2746, 'n_tokens_neox': 2711, 'n_words': 525}