<commit_before>package sword.langbook3.android;

import android.os.Parcel;
import android.os.Parcelable;

import sword.collections.ImmutableIntRange;
import sword.collections.MutableIntValueHashMap;
import sword.collections.MutableIntValueMap;
import sword.langbook3.android.models.SentenceSpan;

public final class SpanEditorActivityState implements Parcelable {

    private final MutableIntValueMap<SentenceSpan> spans = MutableIntValueHashMap.empty();
    private ImmutableIntRange selection;

    ImmutableIntRange getSelection() {
        return selection;
    }

    void setSelection(ImmutableIntRange range) {
        if (range != null && range.min() < 0) {
            throw new IllegalArgumentException();
        }

        selection = range;
    }

    MutableIntValueMap<SentenceSpan> getSpans() {
        return spans;
    }

    public static final Creator<SpanEditorActivityState> CREATOR = new Creator<SpanEditorActivityState>() {
        @Override
        public SpanEditorActivityState createFromParcel(Parcel in) {
            final SpanEditorActivityState state = new SpanEditorActivityState();
            final int start = in.readInt();
            if (start >= 0) {
                final int end = in.readInt();
                state.setSelection(new ImmutableIntRange(start, end));
            }

            sentenceSpanSetFromParcel(state.getSpans(), in);
            return state;<commit_msg>Sort span list in SpanEditorActivity by position within the sentence<commit_after>package sword.langbook3.android;

import android.os.Parcel;
import android.os.Parcelable;

import sword.collections.ImmutableIntRange;
import sword.collections.MutableIntValueMap;
import sword.collections.MutableIntValueSortedMap;
import sword.langbook3.android.models.SentenceSpan;

public final class SpanEditorActivityState implements Parcelable {

    private final MutableIntValueMap<SentenceSpan> spans = MutableIntValueSortedMap.empty((a, b) -> a.range.min() < b.range.min());
    private ImmutableIntRange selection;

    ImmutableIntRange getSelection() {
        return selection;
    }

    void setSelection(ImmutableIntRange range) {
        if (range != null && range.min() < 0) {
            throw new IllegalArgumentException();
        }

        selection = range;
    }

    MutableIntValueMap<SentenceSpan> getSpans() {
        return spans;
    }

    public static final Creator<SpanEditorActivityState> CREATOR = new Creator<SpanEditorActivityState>() {
        @Override
        public SpanEditorActivityState createFromParcel(Parcel in) {
            final SpanEditorActivityState state = new SpanEditorActivityState();
            final int start = in.readInt();
            if (start >= 0) {
                final int end = in.readInt();
                state.setSelection(new ImmutableIntRange(start, end));
            }

            sentenceSpanSetFromParcel(state.getSpans(), in);
            return state;
{'fraction_non_alphanumeric': 0.08299319727891157, 'fraction_numerical': 0.0027210884353741495, 'mean_word_length': 3.13061797752809, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '17511', 'n_tokens_mistral': 792, 'n_tokens_neox': 763, 'n_words': 179}