All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.kyay10.kotlinnulldefaults.utils.FileExtensions.kt Maven / Gradle / Ivy

Go to download

A Kotlin compiler plugin that allows Java callers to pass in null for default parameters

The newest version!
@file:OptIn(ExperimentalStdlibApi::class)
@file:Suppress("unused")

package io.github.kyay10.kotlinnulldefaults.utils

import org.jetbrains.kotlin.com.intellij.openapi.vfs.VirtualFile
import java.io.File
import java.io.FilenameFilter

@OptIn(ExperimentalStdlibApi::class)
fun VirtualFile.collectFiles(): List {
  return buildList {
    listOf(this@collectFiles).collectFiles(this)
  }
}

@JvmName("collectVirtualFiles")
tailrec fun List.collectFiles(list: MutableList) {
  if (isEmpty()) return
  list.addAll(this)
  flatMap { it.children }.collectFiles(list)
}

fun File.collectFiles(filter: FilenameFilter? = null): List {
  return buildList {
    listOf(this@collectFiles).collectFiles(this, filter)
    if (filter?.accept([email protected], [email protected]) == false) {
      removeAt(0)
    }
  }
}

fun List.collectFiles(filter: FilenameFilter? = null): List {
  return buildList {
    [email protected](this, filter)
    if (filter != null) {
      [email protected] { index, file ->
        if (!filter.accept(file.parentFile, file.name)) {
          removeAt(index)
        }
      }
    }
  }
}

tailrec fun List.collectFiles(list: MutableList, filter: FilenameFilter? = null) {
  if (isEmpty()) return
  list.addAll(this)
  flatMap { it.listFiles(filter).toListOrEmpty() }.collectFiles(list)
}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy