<commit_before>package com.jakewharton.diffuse.diff

import com.jakewharton.diffuse.Arsc
import com.jakewharton.diffuse.diffuseTable
import com.jakewharton.diffuse.report.toDiffString
import com.jakewharton.picnic.TextAlignment.MiddleLeft
import com.jakewharton.picnic.TextAlignment.MiddleRight
import com.jakewharton.picnic.renderText

internal class ArscDiff(
  val oldArsc: Arsc,
  val newArsc: Arsc
) {
  val configsAdded = (newArsc.configs - oldArsc.configs).sorted()
  val configsRemoved = (oldArsc.configs - newArsc.configs).sorted()
  val entriesAdded = (newArsc.entries.values - oldArsc.entries.values).sorted()
  val entriesRemoved = (oldArsc.entries.values - newArsc.entries.values).sorted()

  val changed = configsAdded.isNotEmpty() ||
      configsRemoved.isNotEmpty() ||
      entriesAdded.isNotEmpty() ||
      entriesRemoved.isNotEmpty()
}

internal fun ArscDiff.toSummaryTable() = diffuseTable {
  header {
    row {
      cell("ARSC")
      cell("old")
      cell("new")
      cell("diff") {
        columnSpan = 2
      }
    }
  }

  body {
    cellStyle {
      alignment = MiddleRight
    }

    row {
      cell("configs")
      cell(oldArsc.configs.size)
      cell(newArsc.configs.size)

      val configsDelta = configsAdded.size - configsRemoved.size
      cell(configsDelta.toDiffString()) {
        borderRight = false
      }

      val delta = if (configsDelta > 0) {
        val added = configsAdded.size.toDiffString(zeroSign = '+')
        val removed = (-configsRemoved.size).toDiffString(zeroSign = '-')
        "($added $removed)"
      } else {
        ""
      }
      cell(delta) {
        borderLeft = false
        paddingLeft = 0
        alignment = MiddleLeft
      }
    }

    row {
      cell("entries")
      cell(oldArsc.entries.size)
      cell(newArsc.entries.size)

      val entriesDelta = entriesAdded.size - entriesRemoved.size
      cell(entriesDelta.toDiffString()) {
        borderRight = false
      }

      val delta = if (entriesDelta > 0) {
        val added = entriesAdded.size.toDiffString(zeroSign = '+')
        val removed = (-entriesRemoved.size).toDiffString(zeroSign = '-')
        "($added $removed)"
      } else {
        ""
      }
      cell(delta) {
        borderLeft = false
        paddingLeft = 0<commit_msg>Show granular diff for all non-empty deltas<commit_after>package com.jakewharton.diffuse.diff

import com.jakewharton.diffuse.Arsc
import com.jakewharton.diffuse.diffuseTable
import com.jakewharton.diffuse.report.toDiffString
import com.jakewharton.picnic.TextAlignment.MiddleLeft
import com.jakewharton.picnic.TextAlignment.MiddleRight
import com.jakewharton.picnic.renderText

internal class ArscDiff(
  val oldArsc: Arsc,
  val newArsc: Arsc
) {
  val configsAdded = (newArsc.configs - oldArsc.configs).sorted()
  val configsRemoved = (oldArsc.configs - newArsc.configs).sorted()
  val entriesAdded = (newArsc.entries.values - oldArsc.entries.values).sorted()
  val entriesRemoved = (oldArsc.entries.values - newArsc.entries.values).sorted()

  val changed = configsAdded.isNotEmpty() ||
      configsRemoved.isNotEmpty() ||
      entriesAdded.isNotEmpty() ||
      entriesRemoved.isNotEmpty()
}

internal fun ArscDiff.toSummaryTable() = diffuseTable {
  header {
    row {
      cell("ARSC")
      cell("old")
      cell("new")
      cell("diff") {
        columnSpan = 2
      }
    }
  }

  body {
    cellStyle {
      alignment = MiddleRight
    }

    row {
      cell("configs")
      cell(oldArsc.configs.size)
      cell(newArsc.configs.size)

      val configsDelta = configsAdded.size - configsRemoved.size
      cell(configsDelta.toDiffString()) {
        borderRight = false
      }

      val delta = if (configsAdded.isNotEmpty() || configsRemoved.isNotEmpty()) {
        val added = configsAdded.size.toDiffString(zeroSign = '+')
        val removed = (-configsRemoved.size).toDiffString(zeroSign = '-')
        "($added $removed)"
      } else {
        ""
      }
      cell(delta) {
        borderLeft = false
        paddingLeft = 0
        alignment = MiddleLeft
      }
    }

    row {
      cell("entries")
      cell(oldArsc.entries.size)
      cell(newArsc.entries.size)

      val entriesDelta = entriesAdded.size - entriesRemoved.size
      cell(entriesDelta.toDiffString()) {
        borderRight = false
      }

      val delta = if (entriesAdded.isNotEmpty() || entriesRemoved.isNotEmpty()) {
        val added = entriesAdded.size.toDiffString(zeroSign = '+')
        val removed = (-entriesRemoved.size).toDiffString(zeroSign = '-')
        "($added $removed)"
      } else {
        ""
      }
      cell(delta) {
        borderLeft = false
        paddingLeft = 0
{'fraction_non_alphanumeric': 0.11492537313432835, 'fraction_numerical': 0.0017057569296375266, 'mean_word_length': 2.625193199381762, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3871729', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1489, 'n_words': 251}