Skip to content

Commit

Permalink
[auto] Reflect the changes of main repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
nyabkun committed May 28, 2023
1 parent 0c09301 commit 298f6ba
Show file tree
Hide file tree
Showing 9 changed files with 562 additions and 656 deletions.
110 changes: 8 additions & 102 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,11 @@
# 🐕 qq-tree

**qq-tree** is a Kotlin library that can construct a tree structure.
- Just copy and paste 🟦 Single-File version [QTreeNode.kt](src-single/QTreeNode.kt) into your project.
- Or you can use 🟩 Split-File Jar version. See [Maven Dependency Section](#-split-file-jar-version-maven-dependency).
- Feel free to fork or copy to your own codebase.

## Example

### output
<p align="center">
<img src="img/001-num-unicode.png" width="203" alt="001-num-unicode.png">
<img src="img/002-num-ascii.png" width="194" alt="002-num-ascii.png">
</p>
<p align="center">
<img src="img/003-walk-tree.png" width="443" alt="003-walk-tree.png">
</p>
<p align="center">
<img src="img/004-string-tree.png" width="250" alt="004-string-tree.png">
<img src="img/005-dir-tree.png" width="195" alt="005-dir-tree.png">
</p>

### code

Full Source [QTreeNodeExample.kt](src-example/QTreeNodeExample.kt)

```kotlin
fun main() {
// First, you have to create the root node.
val root = QTreeNode(0)

val node1 = root add 1
val node2 = root add 2
val node3 = node2 add 3
val node4 = node2 add 4
val node5 = node4 add 5
val node6 = node4 add 6
val node7 = node2 add 7

val unicodeTree = root.tree(color = QShColor.GREEN, style = QTreeStyle.UNICODE)

println(unicodeTree)

val asciiTree = root.tree(color = QShColor.BLUE, style = QTreeStyle.ASCII)

println(asciiTree)

println()

val depthFirstResult = root.descendantsList(QSearchAlgo.DepthFirst).toString()

println("DepthFirst : $depthFirstResult") // [0, 1, 2, 3, 4, 5, 6, 7]

val breadthFirstResult = root.descendantsList(QSearchAlgo.BreadthFirst).toString()

println("BreadthFirst : $breadthFirstResult") // [0, 1, 2, 3, 4, 7, 5, 6]

println()

// node can store anything
val rootA = QTreeNode("A")
val nodeB = rootA add "B"
val nodeC = nodeB add "C"
val nodeD = nodeB add "D"
val nodeE = nodeD add "E"
val nodeF = nodeE add "F"
val nodeG = nodeC add "G"

val textTree = rootA.tree(color = QShColor.CYAN, style = QTreeStyle.UNICODE)

println(textTree)

// You can implement QLazyNode for more complicated situations.
class QFileNode(override val value: Path) : QLazyTreeNode<Path> {
override fun hasChildNodesToFill(): Boolean {
return value.isDirectory()
}

override fun fillChildNodes(): List<QFileNode> = Files.walk(value, 1).filter {
it != value
}.map {
QFileNode(it)
}.toList()

override fun toTreeNodeString(): String {
return value.name
}
}

val rootDir = Paths.get("rsc-test/root-dir").toAbsolutePath()
- Just copy and paste 🟦 Single-File version [QTreeNode.kt](src-single/QTreeNode.kt) into your project.- Or you can use 🟩 Split-File Jar version. See [Maven Dependency Section](#-split-file-jar-version-maven-dependency).
- Feel free to fork or copy to your own codebase.

val fileTree = QFileNode(rootDir).fillTree(maxDepth = 2).tree()

println(fileTree)
}
```

Please see [QTreeNodeTest.kt](src-test-split/nyab/util/QTreeNodeTest.kt) for more code examples.
Single-File version [src-test-single/QTreeNodeTest.kt](src-test-single/QTreeNodeTest.kt) is a self-contained source code that includes a runnable main function.
You can easily copy and paste it into your codebase.

## 🟦 Single-File version Dependency

Expand Down Expand Up @@ -126,7 +34,7 @@ repositories {
}
dependencies {
implementation 'com.github.nyabkun:qq-tree:v2023-05-22'
implementation 'com.github.nyabkun:qq-tree:v2023-05-28'
}
```

Expand All @@ -138,7 +46,7 @@ repositories {
}

dependencies {
implementation("com.github.nyabkun:qq-tree:v2023-05-22")
implementation("com.github.nyabkun:qq-tree:v2023-05-28")
}
```

Expand All @@ -157,16 +65,14 @@ dependencies {
<dependency>
<groupId>com.github.nyabkun</groupId>
<artifactId>qq-tree</artifactId>
<version>v2023-05-22</version>
<version>v2023-05-28</version>
</dependency>
</dependencies>
```

## How did I create this library

I created this library by developing a program within my own codebase that automatically resolves dependencies at the method or property level, extracts necessary code elements, and generates a compact, self-contained, single-file library.

The program uses [PSI](https://plugins.jetbrains.com/docs/intellij/psi.html) to resolve dependencies for function calls and references to classes.

Although my original repository is currently disorganized, I have been gradually extracting and publishing small libraries. I also plan to prepare the original repository for publication in the future
- I developed [qq-compact-lib](https://github.com/nyabkun/qq-compact-lib) that resolves dependencies and generates compact, self-contained libraries.
- It utilizes [PSI](https://plugins.jetbrains.com/docs/intellij/psi.html) to resolve function calls and class references.
- The original repository is currently being organized, and I'm gradually extracting and publishing smaller libraries.

4 changes: 2 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
v2023-05-22
8a0b25a1ba01b5f4b9c4956d63687a5a55d231a8fa313cfac656fe3e116334433432dd1254fbf89cd8c881f93b13f2691ac4fb0ae661b01556a875dede926d0e
v2023-05-28
f5b4d712c22124fd15407d08997388b76e203043bd70d311e0d99743b371686862e5dc3710e95643d6996905b36afa739d1a85608de21f0974de692eb1475d3b
69 changes: 34 additions & 35 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ plugins {

group = "com.nyabkun.qol"

version = "v2023-05-22"
version = "v2023-05-28"

repositories {
mavenCentral()
Expand All @@ -45,38 +45,37 @@ java {


sourceSets.main {
java.srcDirs("src-split")
java.srcDirs("src-split")

resources.srcDirs("rsc")
}

sourceSets.test {
java.srcDirs("src-test-split")

resources.srcDirs("rsc-test")
}

sourceSets.register("example") {
java.srcDirs("src-example")

resources.srcDirs("rsc")

val jarFile = "$buildDir/libs/$qMavenArtifactId-$version.jar"
compileClasspath += files(jarFile)
runtimeClasspath += files(jarFile)
}

tasks.getByName("compileExampleKotlin").dependsOn("jar")

val exampleImplementation: Configuration by configurations.getting {
extendsFrom(configurations.implementation.get())
}
resources.srcDirs("rsc")
}

val exampleRuntimeOnly: Configuration by configurations.getting {
extendsFrom(configurations.runtimeOnly.get())
}
sourceSets.test {
java.srcDirs("src-test-split")

sourceSets.register("single") {
resources.srcDirs("rsc-test")
}

sourceSets.register("example") {
java.srcDirs("src-example")
val jarFile = "$buildDir/libs/$qMavenArtifactId-$version.jar"
compileClasspath += files(jarFile)
runtimeClasspath += files(jarFile)

resources.srcDirs("rsc")
}

tasks.getByName("compileExampleKotlin").dependsOn("jar")

val exampleImplementation: Configuration by configurations.getting {
extendsFrom(configurations.implementation.get())
}

val exampleRuntimeOnly: Configuration by configurations.getting {
extendsFrom(configurations.runtimeOnly.get())
}

sourceSets.register("single") {
java.srcDirs("src-single")
}

Expand Down Expand Up @@ -112,13 +111,13 @@ tasks {
enabled = true

archiveBaseName.set(qMavenArtifactId)

from(sourceSets.main.get().output)

manifest {
attributes(
"Implementation-Title" to qMavenArtifactId,
"Implementation-Version" to project.version
"Implementation-Title" to qMavenArtifactId,
"Implementation-Version" to project.version
)
}
}
Expand All @@ -128,7 +127,7 @@ tasks {
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}

artifacts {
archives(qSrcJar)
archives(jar)
Expand Down
Loading

0 comments on commit 298f6ba

Please sign in to comment.