<commit_before>package com.bluejamesbond.text;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.TextPaint;
import android.widget.Toast;

import com.bluejamesbond.text.hyphen.Hyphenator;
import com.bluejamesbond.text.style.TextAlignment;

import java.util.Arrays;

/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * -------------------------------------------------------------------------
 *
 * IDocumentLayout.java
 * @author <NAME>
 *
 * From TextJustify-Android Library v2.0
 * https://github.com/bluejamesbond/TextJustify-Android
 *
 * Please report any issues
 * https://github.com/bluejamesbond/TextJustify-Android/issues
 *
 * Date: 10/27/14 1:36 PM
 */

@SuppressWarnings("unused")
public abstract class IDocumentLayout {

    // Main content
    protected CharSequence text;
    protected int lineCount;
    protected int measuredHeight;
    protected boolean debugging;
    protected boolean textChange;
    protected LayoutParams params;
    protected TextPaint paint;
    private Toast toast;

    @SuppressLint("ShowToast")
    public IDocumentLayout(Context context, TextPaint textPaint) {
        paint = textPaint;
        text = "";
        measuredHeight = 0;
        lineCount = 0;
        debugging = false;
        textChange = false;
        toast = Toast.makeText(context, "", Toast.LENGTH_SHORT);

        params = new LayoutParams();
        params.setLineHeightMultiplier(1.0f);
        params.setHyphenated(false);
        params.setReverse(false);
    }

    protected void showToast(String s) {
        toast.setText(s);
        toast.show();
    }

    public boolean isDebugging() {
        return debugging;
    }

    public void setDebugging(boolean debugging) {
        this.debugging = debugging;
    }

    public Paint getPaint() {
        return paint;
    }

    public LayoutParams getLayoutParams() {
        return params;
    }

    public CharSequence getText() {
        return this.text;
    }

    public void setText(CharSequence text) {
        this.text = text == null ? new SpannableString("") : text;
        this.textChange = true;
    }

    public int getMeasuredHeight() {
        return measuredHeight;
    }

    protected void onTextNull() {
        params.changed = false;
        measuredHeight = (int) (params.paddingTop + params.paddingBottom);
    }

    public int getLineCount() {
        return lineCount;
    }

    public boolean measure(ISet<Float> progress, IGet<Boolean> cancelled) {

        if (!params.changed && !textChange) {
            return true;
        }

        params.loadTo(paint);

        return onMeasure(progress, cancelled);
    }

    protected abstract boolean onMeasure(ISet<Float> progress, IGet<Boolean> cancelled);

    public void draw(Canvas canvas, int startTop, int startBottom) {
        onDraw(canvas, startTop, startBottom);
    }

    protected abstract void onDraw(Canvas canvas, int startTop, int startBottom);

    public abstract int getTokenIndex(float y, TokenPosition position);

    public abstract float getTokenTopAt(int index);

    public abstract CharSequence getTokenTextAt(int index);

    public abstract boolean isTokenized();

    public static enum TokenPosition {
        START_OF_LINE, END_OF_LINE
    }

    public static interface ISet<T> {
        public void set(T val);
    }

    public static interface IGet<T> {
        public T get();
    }

    public static class LayoutParams {

        /**
         * All the customizable parameters
         */
        protected Hyphenator hyphenator = null;
        protected Float paddingLeft = 0.0f;
        protected Float paddingTop = 0.0f;
        protected Float paddingBottom = 0.0f;
        protected Float paddingRight = 0.0f;
        protected Float parentWidth = 800.0f;
        protected Float offsetX = 0.0f;
        protected Float offsetY = 0.0f;

        protected Float wordSpacingMultiplier = 1.0f;
        protected Float lineHeightMultiplier = 0.0f;
        protected Boolean hyphenated = false;
        protected Boolean reverse = false;
        protected Integer maxLines = Integer.MAX_VALUE;
        protected String hyphen = "-";
        protected TextAlignment textAlignment = TextAlignment.LEFT;

        protected Boolean textUnderline = false;
        protected Boolean textStrikeThru = false;
        protected Boolean textFakeBold = false;
        protected Typeface textTypeface = Typeface.DEFAULT;
        protected Float textSize = 40f;
        protected Integer textColor = Color.BLACK;

        /**
         * If any settings have changed.
         */
        protected boolean changed = false;

        public int hashCode() {
            return Arrays.hashCode(
                    new Object[]{hyphenator, paddingLeft, paddingTop, paddingBottom, paddingRight,
                            parentWidth, offsetX, offsetX,
                            lineHeightMultiplier, hyphenated, reverse, maxLines, hyphen, textAlignment, wordSpacingMultiplier,
                            textUnderline, textStrikeThru, textFakeBold, textTypeface, textSize, textColor});
        }

        public void loadTo(Paint paint) {
            paint.setTextSize(textSize);
            paint.setFakeBoldText(textFakeBold);
            paint.setStrikeThruText(textStrikeThru);
            paint.setColor(textColor);
            paint.setTypeface(textTypeface);
            paint.setUnderlineText(textUnderline);
        }

        public Float getWordSpacingMultiplier() {
            return wordSpacingMultiplier;
        }

        public void setWordSpacingMultiplier(float wordSpacingMultiplier) {
            if (this.wordSpacingMultiplier.equals(wordSpacingMultiplier)) {
                return;
            }

            this.wordSpacingMultiplier = wordSpacingMultiplier;<commit_msg>Minor fix with DocumentLayoutParams#equals<commit_after>package com.bluejamesbond.text;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.TextPaint;
import android.widget.Toast;

import com.bluejamesbond.text.hyphen.Hyphenator;
import com.bluejamesbond.text.style.TextAlignment;

import java.util.Arrays;

/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * -------------------------------------------------------------------------
 *
 * IDocumentLayout.java
 * @author <NAME>
 *
 * From TextJustify-Android Library v2.0
 * https://github.com/bluejamesbond/TextJustify-Android
 *
 * Please report any issues
 * https://github.com/bluejamesbond/TextJustify-Android/issues
 *
 * Date: 10/27/14 1:36 PM
 */

@SuppressWarnings("unused")
public abstract class IDocumentLayout {

    // Main content
    protected CharSequence text;
    protected int lineCount;
    protected int measuredHeight;
    protected boolean debugging;
    protected boolean textChange;
    protected LayoutParams params;
    protected TextPaint paint;
    private Toast toast;

    @SuppressLint("ShowToast")
    public IDocumentLayout(Context context, TextPaint textPaint) {
        paint = textPaint;
        text = "";
        measuredHeight = 0;
        lineCount = 0;
        debugging = false;
        textChange = false;
        toast = Toast.makeText(context, "", Toast.LENGTH_SHORT);

        params = new LayoutParams();
        params.setLineHeightMultiplier(1.0f);
        params.setHyphenated(false);
        params.setReverse(false);
    }

    protected void showToast(String s) {
        toast.setText(s);
        toast.show();
    }

    public boolean isDebugging() {
        return debugging;
    }

    public void setDebugging(boolean debugging) {
        this.debugging = debugging;
    }

    public Paint getPaint() {
        return paint;
    }

    public LayoutParams getLayoutParams() {
        return params;
    }

    public CharSequence getText() {
        return this.text;
    }

    public void setText(CharSequence text) {
        this.text = text == null ? new SpannableString("") : text;
        this.textChange = true;
    }

    public int getMeasuredHeight() {
        return measuredHeight;
    }

    protected void onTextNull() {
        params.changed = false;
        measuredHeight = (int) (params.paddingTop + params.paddingBottom);
    }

    public int getLineCount() {
        return lineCount;
    }

    public boolean measure(ISet<Float> progress, IGet<Boolean> cancelled) {

        if (!params.changed && !textChange) {
            return true;
        }

        params.loadTo(paint);

        return onMeasure(progress, cancelled);
    }

    protected abstract boolean onMeasure(ISet<Float> progress, IGet<Boolean> cancelled);

    public void draw(Canvas canvas, int startTop, int startBottom) {
        onDraw(canvas, startTop, startBottom);
    }

    protected abstract void onDraw(Canvas canvas, int startTop, int startBottom);

    public abstract int getTokenIndex(float y, TokenPosition position);

    public abstract float getTokenTopAt(int index);

    public abstract CharSequence getTokenTextAt(int index);

    public abstract boolean isTokenized();

    public static enum TokenPosition {
        START_OF_LINE, END_OF_LINE
    }

    public static interface ISet<T> {
        public void set(T val);
    }

    public static interface IGet<T> {
        public T get();
    }

    public static class LayoutParams {

        /**
         * All the customizable parameters
         */
        protected Hyphenator hyphenator = null;
        protected Float paddingLeft = 0.0f;
        protected Float paddingTop = 0.0f;
        protected Float paddingBottom = 0.0f;
        protected Float paddingRight = 0.0f;
        protected Float parentWidth = 800.0f;
        protected Float offsetX = 0.0f;
        protected Float offsetY = 0.0f;

        protected Float wordSpacingMultiplier = 1.0f;
        protected Float lineHeightMultiplier = 0.0f;
        protected Boolean hyphenated = false;
        protected Boolean reverse = false;
        protected Integer maxLines = Integer.MAX_VALUE;
        protected String hyphen = "-";
        protected TextAlignment textAlignment = TextAlignment.LEFT;

        protected Boolean textUnderline = false;
        protected Boolean textStrikeThru = false;
        protected Boolean textFakeBold = false;
        protected Typeface textTypeface = Typeface.DEFAULT;
        protected Float textSize = 40f;
        protected Integer textColor = Color.BLACK;

        /**
         * If any settings have changed.
         */
        protected boolean changed = false;

        public int hashCode() {
            return Arrays.hashCode(
                    new Object[]{hyphenator, paddingLeft, paddingTop, paddingBottom, paddingRight,
                            parentWidth, offsetX, offsetY,
                            lineHeightMultiplier, hyphenated, reverse, maxLines, hyphen, textAlignment, wordSpacingMultiplier,
                            textUnderline, textStrikeThru, textFakeBold, textTypeface, textSize, textColor});
        }

        public void loadTo(Paint paint) {
            paint.setTextSize(textSize);
            paint.setFakeBoldText(textFakeBold);
            paint.setStrikeThruText(textStrikeThru);
            paint.setColor(textColor);
            paint.setTypeface(textTypeface);
            paint.setUnderlineText(textUnderline);
        }

        public Float getWordSpacingMultiplier() {
            return wordSpacingMultiplier;
        }

        public void setWordSpacingMultiplier(float wordSpacingMultiplier) {
            if (this.wordSpacingMultiplier.equals(wordSpacingMultiplier)) {
                return;
            }

            this.wordSpacingMultiplier = wordSpacingMultiplier;
{'fraction_non_alphanumeric': 0.08960354441983041, 'fraction_numerical': 0.0068749522572759915, 'mean_word_length': 2.5174637291778614, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 4, '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': '5044001', 'n_tokens_mistral': 3527, 'n_tokens_neox': 3409, 'n_words': 960}