Compare commits
No commits in common. "master" and "v1.0.04" have entirely different histories.
86
.circleci/config.yml
Normal file
@ -0,0 +1,86 @@
|
||||
version: 2.1
|
||||
jobs:
|
||||
build:
|
||||
working_directory: ~/code
|
||||
docker:
|
||||
- image: circleci/android:api-29
|
||||
environment:
|
||||
JVM_OPTS: -Xmx3200m
|
||||
steps:
|
||||
- checkout
|
||||
- restore_cache:
|
||||
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
|
||||
- run:
|
||||
name: Download Dependencies
|
||||
command: ./gradlew androidDependencies
|
||||
- save_cache:
|
||||
paths:
|
||||
- ~/.gradle
|
||||
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
|
||||
|
||||
tests:
|
||||
working_directory: ~/code
|
||||
docker:
|
||||
- image: circleci/android:api-29
|
||||
environment:
|
||||
JVM_OPTS: -Xmx3200m
|
||||
steps:
|
||||
- checkout
|
||||
- restore_cache:
|
||||
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
|
||||
- store_artifacts:
|
||||
path: app/build/reports
|
||||
destination: reports
|
||||
- run:
|
||||
name: Run Lint Test
|
||||
command: ./gradlew lint
|
||||
- run:
|
||||
name: Run Tests
|
||||
command: ./gradlew lint test
|
||||
- store_artifacts:
|
||||
path: app/build/reports
|
||||
destination: reports
|
||||
- store_test_results:
|
||||
path: app/build/test-results
|
||||
|
||||
deploy:
|
||||
working_directory: ~/code
|
||||
docker:
|
||||
- image: circleci/android:api-29
|
||||
environment:
|
||||
JVM_OPTS: -Xmx3200m
|
||||
steps:
|
||||
- checkout
|
||||
- restore_cache:
|
||||
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
|
||||
- run:
|
||||
name: Build Library
|
||||
command: ./gradlew :treedatastructure:assembleRelease
|
||||
- run:
|
||||
name: Export key
|
||||
command: |
|
||||
mkdir treedatastructure/maven
|
||||
echo ${GPG_KEY_CONTENTS} | base64 -d --ignore-garbage > treedatastructure/maven/secret.gpg
|
||||
- run:
|
||||
name: Staging
|
||||
command: ./gradlew :treedatastructure:publishReleasePublicationToSonatypeRepository
|
||||
- run:
|
||||
name: Release Library
|
||||
command: ./gradlew closeAndReleaseRepository
|
||||
|
||||
workflows:
|
||||
version: 2.1
|
||||
build-and-deploy:
|
||||
jobs:
|
||||
- build:
|
||||
filters: # required since `deploy` has tag filters AND requires `build`
|
||||
tags:
|
||||
only: /.*/
|
||||
- deploy:
|
||||
requires:
|
||||
- build
|
||||
filters:
|
||||
tags:
|
||||
only: /^v[0-9]{1,3}\.[0-9]{1,3}\.?[0-9]{0,3}$/
|
||||
branches:
|
||||
ignore: /.*/
|
38
.github/workflows/publishRelease.yml
vendored
@ -1,38 +0,0 @@
|
||||
name: Publish
|
||||
|
||||
on:
|
||||
release:
|
||||
# We'll run this workflow when a new GitHub release is created
|
||||
types: [released]
|
||||
|
||||
|
||||
jobs:
|
||||
test:
|
||||
uses: ./.github/workflows/test.yml
|
||||
secrets: inherit
|
||||
|
||||
publish:
|
||||
needs: test
|
||||
name: Publish Production
|
||||
environment: production
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: adopt
|
||||
java-version: 11
|
||||
|
||||
# Runs upload, and then closes & releases the repository
|
||||
- name: Publish to MavenCentral
|
||||
run: ./gradlew publish --max-workers 1
|
||||
env:
|
||||
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
||||
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
|
||||
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
|
||||
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
|
||||
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
|
||||
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
|
||||
SNAPSHOT: false
|
35
.github/workflows/publishSnapshot.yml
vendored
@ -1,35 +0,0 @@
|
||||
name: Publish Snapshot
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
uses: ./.github/workflows/test.yml
|
||||
secrets: inherit
|
||||
|
||||
publish:
|
||||
needs: test
|
||||
name: Publish Snapshot
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: adopt
|
||||
java-version: 11
|
||||
|
||||
# Runs upload, and then closes & releases the repository
|
||||
- name: Publish to snapshot to Sonatype
|
||||
run: ./gradlew publish --max-workers 1
|
||||
env:
|
||||
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
||||
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
|
||||
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
|
||||
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
|
||||
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
|
||||
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
|
||||
SNAPSHOT: true
|
23
.github/workflows/test.yml
vendored
@ -1,23 +0,0 @@
|
||||
name: Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches-ignore: [master]
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Run unit tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: adopt
|
||||
java-version: 11
|
||||
|
||||
# Builds the release artifacts of the library
|
||||
- name: Test
|
||||
run: ./gradlew test
|
4
.gitignore
vendored
@ -12,7 +12,3 @@
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
/.idea/.name
|
||||
/.idea/compiler.xml
|
||||
/.idea/jarRepositories.xml
|
||||
/.idea/deploymentTargetDropDown.xml
|
||||
|
4
.idea/.gitignore
generated
vendored
@ -1,4 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
artifacts
|
115
.idea/codeStyles/Project.xml
generated
@ -3,6 +3,121 @@
|
||||
<JetCodeStyleSettings>
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</JetCodeStyleSettings>
|
||||
<MarkdownNavigatorCodeStyleSettings>
|
||||
<option name="RIGHT_MARGIN" value="72" />
|
||||
</MarkdownNavigatorCodeStyleSettings>
|
||||
<codeStyleSettings language="XML">
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
<arrangement>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</codeStyleSettings>
|
||||
|
7
.idea/gradle.xml
generated
@ -1,16 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="WRAPPED" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
<option value="$PROJECT_DIR$/treedatastructure" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
6
.idea/inspectionProfiles/Project_Default.xml
generated
@ -1,6 +0,0 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="ReplaceUntilWithRangeUntil" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
9
.idea/kotlinScripting.xml
generated
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="KotlinScriptingSettings">
|
||||
<scriptDefinition className="org.jetbrains.kotlin.scripting.resolve.KotlinScriptDefinitionFromAnnotatedTemplate" definitionName="KotlinBuildScript">
|
||||
<order>2147483647</order>
|
||||
<autoReloadConfigurations>true</autoReloadConfigurations>
|
||||
</scriptDefinition>
|
||||
</component>
|
||||
</project>
|
8
.idea/misc.xml
generated
@ -1,7 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
12
.idea/runConfigurations.xml
generated
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
86
README.md
@ -1,73 +1,47 @@
|
||||
# Tree (Data Structure)
|
||||
[](https://mvnrepository.com/artifact/com.github.adriankuta/tree-structure)
|
||||
[](https://github.com/AdrianKuta/Tree-Data-Structure/blob/master/LICENSE)
|
||||
[](https://github.com/AdrianKuta/Tree-Data-Structure/actions/workflows/publish.yml)
|
||||
[](https://search.maven.org/artifact/com.github.adriankuta/tree-structure)
|
||||
[](https://github.com/AdrianKuta/Design-Patterns-Kotlin/blob/master/LICENSE)
|
||||
[](https://circleci.com/gh/AdrianKuta/Tree-Data-Structure)
|
||||
|
||||
Simple implementation to store object in tree structure.
|
||||
Simple implementation to store object in tree structure. Method `toString()` is overrided to provide nice tree view in logs.
|
||||
|
||||
## Usage
|
||||
|
||||
**Kotlin**
|
||||
```kotlin
|
||||
val root = TreeNode("World")
|
||||
val northA = TreeNode("North America")
|
||||
val europe = TreeNode("Europe")
|
||||
root.addChild(northA)
|
||||
root.addChild(europe)
|
||||
val root = TreeNode<String>("Root")
|
||||
val beveragesNode = TreeNode<String>("Beverages")
|
||||
val curdNode = TreeNode<String>("Curd")
|
||||
root.addChild(beveragesNode)
|
||||
root.addChild(curdNode)
|
||||
|
||||
val usa = TreeNode("USA")
|
||||
northA.addChild(usa)
|
||||
val teaNode = TreeNode<String>("tea")
|
||||
val coffeeNode = TreeNode<String>("coffee")
|
||||
val milkShakeNode = TreeNode<String>("Milk Shake")
|
||||
beveragesNode.addChild(teaNode)
|
||||
beveragesNode.addChild(coffeeNode)
|
||||
beveragesNode.addChild(milkShakeNode)
|
||||
|
||||
val poland = TreeNode("Poland")
|
||||
val france = TreeNode("France")
|
||||
europe.addChild(poland)
|
||||
europe.addChild(france)
|
||||
println(root.prettyString())
|
||||
```
|
||||
val gingerTeaNode = TreeNode<String>("ginger tea")
|
||||
val normalTeaNode = TreeNode<String>("normal tea")
|
||||
teaNode.addChild(gingerTeaNode)
|
||||
teaNode.addChild(normalTeaNode)
|
||||
|
||||
**Pretty Kotlin**
|
||||
val yogurtNode = TreeNode<String>("yogurt")
|
||||
val lassiNode = TreeNode<String>("lassi")
|
||||
curdNode.addChild(yogurtNode)
|
||||
curdNode.addChild(lassiNode)
|
||||
|
||||
```kotlin
|
||||
val root =
|
||||
tree("World") {
|
||||
child("North America") {
|
||||
child("USA")
|
||||
}
|
||||
child("Europe") {
|
||||
child("Poland")
|
||||
child("Germany")
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Java**
|
||||
```java
|
||||
TreeNode<String> root = new TreeNode<>("World");
|
||||
TreeNode<String> northA = new TreeNode<>("North America");
|
||||
TreeNode<String> europe = new TreeNode<>("Europe");
|
||||
root.addChild(northA);
|
||||
root.addChild(europe);
|
||||
|
||||
TreeNode<String> usa = new TreeNode<>("USA");
|
||||
northA.addChild(usa);
|
||||
|
||||
TreeNode<String> poland = new TreeNode<>("Poland");
|
||||
TreeNode<String> france = new TreeNode<>("France");
|
||||
europe.addChild(poland);
|
||||
europe.addChild(france);
|
||||
System.out.println(root.prettyString());
|
||||
println(root)
|
||||
System.out.println("Remove: ${curdNode.value}")
|
||||
root.removeChild(curdNode)
|
||||
System.out.println("Remove: ${gingerTeaNode.value}")
|
||||
root.removeChild(gingerTeaNode)
|
||||
println(root)
|
||||
```
|
||||
|
||||
*Output:*
|
||||
|
||||
```
|
||||
World
|
||||
├── North America
|
||||
│ └── USA
|
||||
└── Europe
|
||||
├── Poland
|
||||
└── France
|
||||
```
|
||||
<img src="https://github.com/AdrianKuta/Tree-Collection/blob/master/images/console_output.png" width=400>
|
||||
|
||||
|
||||
## Download
|
||||
|
1
app/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
35
app/build.gradle
Normal file
@ -0,0 +1,35 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.2"
|
||||
defaultConfig {
|
||||
applicationId "com.github.adriankuta.treedatastructure"
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation 'androidx.appcompat:appcompat:1.0.2'
|
||||
implementation 'androidx.core:core-ktx:1.0.2'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
||||
}
|
21
app/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
@ -0,0 +1,24 @@
|
||||
package com.github.adriankuta.treedatastructure
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.github.adriankuta.treedatastructure", appContext.packageName)
|
||||
}
|
||||
}
|
21
app/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.github.adriankuta.treedatastructure">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,12 @@
|
||||
package com.github.adriankuta.treedatastructure
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
}
|
||||
}
|
34
app/src/main/res/drawable-v24/ic_launcher_foreground.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="78.5885"
|
||||
android:endY="90.9159"
|
||||
android:startX="48.7653"
|
||||
android:startY="61.0927"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
170
app/src/main/res/drawable/ic_launcher_background.xml
Normal file
@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#008577"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
18
app/src/main/res/layout/activity_main.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 6.2 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 8.9 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 15 KiB |
6
app/src/main/res/values/colors.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#008577</color>
|
||||
<color name="colorPrimaryDark">#00574B</color>
|
||||
<color name="colorAccent">#D81B60</color>
|
||||
</resources>
|
3
app/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">Tree Data Structure</string>
|
||||
</resources>
|
11
app/src/main/res/values/styles.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
@ -0,0 +1,17 @@
|
||||
package com.github.adriankuta.treedatastructure
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
31
build.gradle
Normal file
@ -0,0 +1,31 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.61'
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.3'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.21.2"
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
|
||||
apply plugin: 'io.codearte.nexus-staging'
|
149
build.gradle.kts
@ -1,149 +0,0 @@
|
||||
import org.jetbrains.kotlin.konan.properties.Properties
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform") version "1.7.20"
|
||||
id("org.jetbrains.dokka") version "1.7.20"
|
||||
id("maven-publish")
|
||||
signing
|
||||
}
|
||||
|
||||
val PUBLISH_GROUP_ID = "com.github.adriankuta"
|
||||
val PUBLISH_ARTIFACT_ID = "tree-structure"
|
||||
val PUBLISH_VERSION = "3.0.2"
|
||||
|
||||
val secretFile = File(rootProject.rootDir, "local.properties")
|
||||
if (secretFile.exists()) {
|
||||
secretFile.reader().use {
|
||||
Properties().apply {
|
||||
load(it)
|
||||
}
|
||||
}.onEach { (name, value) ->
|
||||
project.ext[name.toString()] = value
|
||||
}
|
||||
} else {
|
||||
project.ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME")
|
||||
project.ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD")
|
||||
project.ext["sonatypeStagingProfileId"] = System.getenv("SONATYPE_STAGING_PROFILE_ID")
|
||||
project.ext["signingKeyId"] = System.getenv("SIGNING_KEY_ID")
|
||||
project.ext["signingPassword"] = System.getenv("SIGNING_PASSWORD")
|
||||
project.ext["signingKey"] = System.getenv("SIGNING_KEY")
|
||||
project.ext["snapshot"] = System.getenv("SNAPSHOT")
|
||||
}
|
||||
val snapshot: String? by project
|
||||
|
||||
group = PUBLISH_GROUP_ID
|
||||
version = if (snapshot.toBoolean()) "$PUBLISH_VERSION-SNAPSHOT" else PUBLISH_VERSION
|
||||
|
||||
val dokkaHtml by tasks.getting(org.jetbrains.dokka.gradle.DokkaTask::class)
|
||||
|
||||
val javadocJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
|
||||
dependsOn(dokkaHtml)
|
||||
archiveClassifier.set("javadoc")
|
||||
from(dokkaHtml.outputDirectory)
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
|
||||
withType<MavenPublication> {
|
||||
artifact(javadocJar)
|
||||
pom {
|
||||
name.set("Tree Data Structure")
|
||||
description.set("Simple implementation to store object in tree structure.")
|
||||
url.set("https://github.com/AdrianKuta/Tree-Data-Structure")
|
||||
licenses {
|
||||
license {
|
||||
name.set("MIT License")
|
||||
url.set("https://www.mit.edu/~amini/LICENSE.md")
|
||||
}
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
name.set("Adrian Kuta")
|
||||
email.set("adrian.kuta93@gmail.com")
|
||||
}
|
||||
}
|
||||
scm {
|
||||
connection.set("scm:git:github.com/AdrianKuta/Tree-Data-Structure.git")
|
||||
developerConnection.set("scm:git:ssh://github.com/AdrianKuta/Tree-Data-Structure.git")
|
||||
url.set("https://github.com/AdrianKuta/Tree-Data-Structure/tree/master")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "Sonatype"
|
||||
val releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
|
||||
val snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
|
||||
url = uri(if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl)
|
||||
credentials {
|
||||
val ossrhUsername: String? by project
|
||||
val ossrhPassword: String? by project
|
||||
username = ossrhUsername
|
||||
password = ossrhPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signing {
|
||||
val signingKeyId: String? by project
|
||||
val signingPassword: String? by project
|
||||
val signingKey: String? by project
|
||||
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
|
||||
|
||||
sign(publishing.publications)
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm {
|
||||
compilations.all {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
withJava()
|
||||
testRuns["test"].executionTask.configure {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
}
|
||||
js(BOTH) {
|
||||
browser {
|
||||
commonWebpackConfig {
|
||||
cssSupport.enabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
val hostOs = System.getProperty("os.name")
|
||||
val isMingwX64 = hostOs.startsWith("Windows")
|
||||
val nativeTarget = when {
|
||||
hostOs == "Mac OS X" -> macosX64("native")
|
||||
hostOs == "Linux" -> linuxX64("native")
|
||||
isMingwX64 -> mingwX64("native")
|
||||
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
|
||||
}
|
||||
|
||||
|
||||
sourceSets {
|
||||
val commonMain by getting
|
||||
val commonTest by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("test"))
|
||||
}
|
||||
}
|
||||
val jvmMain by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("script-runtime"))
|
||||
}
|
||||
}
|
||||
val jvmTest by getting
|
||||
val jsMain by getting
|
||||
val jsTest by getting
|
||||
val nativeMain by getting
|
||||
val nativeTest by getting
|
||||
}
|
||||
}
|
@ -1,2 +1,21 @@
|
||||
# Project-wide Gradle settings.
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx1536m
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||
# Android operating system, and which are packaged with your app's APK
|
||||
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||
android.useAndroidX=true
|
||||
# Automatically convert third-party libraries to use AndroidX
|
||||
android.enableJetifier=true
|
||||
# Kotlin code style for this project: "official" or "obsolete":
|
||||
kotlin.code.style=official
|
||||
kotlin.js.compiler=ir
|
||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,6 @@
|
||||
#Wed Jan 08 12:28:15 CET 2020
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
|
||||
|
286
gradlew
vendored
@ -1,129 +1,78 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# https://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.
|
||||
#
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
@ -132,7 +81,7 @@ Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
@ -140,95 +89,84 @@ location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
43
gradlew.bat
vendored
@ -1,19 +1,3 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@ -29,18 +13,15 @@ if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
@ -54,7 +35,7 @@ goto fail
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
@ -64,14 +45,28 @@ echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
|
BIN
images/console_output.png
Normal file
After Width: | Height: | Size: 71 KiB |
122
scripts/publish-mavencentral.gradle
Normal file
@ -0,0 +1,122 @@
|
||||
task androidSourcesJar(type: Jar) {
|
||||
archiveClassifier.set("sources")
|
||||
from android.sourceSets.main.java.source
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives androidSourcesJar
|
||||
}
|
||||
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'signing'
|
||||
|
||||
group = PUBLISH_GROUP_ID
|
||||
version = PUBLISH_VERSION
|
||||
|
||||
ext["signing.keyId"] = ''
|
||||
ext["signing.password"] = ''
|
||||
ext["signing.secretKeyRingFile"] = ''
|
||||
ext["ossrhUsername"] = ''
|
||||
ext["ossrhPassword"] = ''
|
||||
|
||||
File secretPropsFile = project.rootProject.file('local.properties')
|
||||
if (secretPropsFile.exists()) {
|
||||
println "Found secret props file, loading props"
|
||||
Properties p = new Properties()
|
||||
p.load(new FileInputStream(secretPropsFile))
|
||||
p.each { name, value ->
|
||||
ext[name] = value
|
||||
}
|
||||
} else {
|
||||
println "No props file, loading env vars"
|
||||
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
|
||||
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
|
||||
ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
|
||||
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
|
||||
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
|
||||
}
|
||||
|
||||
nexusStaging {
|
||||
packageGroup = PUBLISH_GROUP_ID
|
||||
stagingProfileId = '2097bad464f778'
|
||||
username = ossrhUsername
|
||||
password = ossrhPassword
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
release(MavenPublication) {
|
||||
// The coordinates of the library, being set from variables that
|
||||
// we'll set up in a moment
|
||||
groupId PUBLISH_GROUP_ID
|
||||
artifactId PUBLISH_ARTIFACT_ID
|
||||
version PUBLISH_VERSION
|
||||
|
||||
// Two artifacts, the `aar` and the sources
|
||||
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
|
||||
artifact androidSourcesJar
|
||||
|
||||
// Self-explanatory metadata for the most part
|
||||
pom {
|
||||
name = PUBLISH_ARTIFACT_ID
|
||||
description = 'Simple implementation to store object in tree structure.'
|
||||
// If your project has a dedicated site, use its URL here
|
||||
url = 'https://github.com/AdrianKuta/Tree-Data-Structure'
|
||||
licenses {
|
||||
license {
|
||||
name = 'MIT License'
|
||||
url = 'https://www.mit.edu/~amini/LICENSE.md'
|
||||
}
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
name = 'Adrian Kuta'
|
||||
email = 'adrian.kuta93@gmail.com'
|
||||
}
|
||||
}
|
||||
// Version control info, if you're using GitHub, follow the format as seen here
|
||||
scm {
|
||||
connection = 'scm:git:github.com/AdrianKuta/Tree-Data-Structure.git'
|
||||
developerConnection = 'scm:git:ssh://github.com/AdrianKuta/Tree-Data-Structure.git'
|
||||
url = 'https://github.com/AdrianKuta/Tree-Data-Structure/tree/master'
|
||||
}
|
||||
// A slightly hacky fix so that your POM will include any transitive dependencies
|
||||
// that your library builds upon
|
||||
withXml {
|
||||
def dependenciesNode = asNode().appendNode('dependencies')
|
||||
|
||||
project.configurations.implementation.allDependencies.each {
|
||||
def dependencyNode = dependenciesNode.appendNode('dependency')
|
||||
dependencyNode.appendNode('groupId', it.group)
|
||||
dependencyNode.appendNode('artifactId', it.name)
|
||||
dependencyNode.appendNode('version', it.version)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
// The repository to publish to, Sonatype/MavenCentral
|
||||
maven {
|
||||
// This is an arbitrary name, you may also use "mavencentral" or
|
||||
// any other name that's descriptive for you
|
||||
name = "sonatype"
|
||||
|
||||
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
|
||||
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||
// You only need this if you want to publish snapshots, otherwise just set the URL
|
||||
// to the release repo directly
|
||||
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
|
||||
|
||||
// The username and password we've fetched earlier
|
||||
credentials {
|
||||
username ossrhUsername
|
||||
password ossrhPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signing {
|
||||
sign publishing.publications
|
||||
}
|
2
settings.gradle
Normal file
@ -0,0 +1,2 @@
|
||||
include ':app', ':treedatastructure'
|
||||
rootProject.name='Tree Data Structure'
|
@ -1,3 +0,0 @@
|
||||
|
||||
rootProject.name = "tree-structure"
|
||||
|
@ -1,24 +0,0 @@
|
||||
package com.github.adriankuta.datastructure.tree
|
||||
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
|
||||
interface ChildDeclarationInterface<T> {
|
||||
|
||||
/**
|
||||
* This method is used to easily create child in node.
|
||||
* ```
|
||||
* val root = tree("World") {
|
||||
* child("North America") {
|
||||
* child("USA")
|
||||
* }
|
||||
* child("Europe") {
|
||||
* child("Poland")
|
||||
* child("Germany")
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
* @return New created TreeNode.
|
||||
*/
|
||||
@JvmSynthetic
|
||||
fun child(value: T, childDeclaration: ChildDeclaration<T>? = null): TreeNode<T>
|
||||
}
|
@ -1,174 +0,0 @@
|
||||
package com.github.adriankuta.datastructure.tree
|
||||
|
||||
import com.github.adriankuta.datastructure.tree.exceptions.TreeNodeException
|
||||
import com.github.adriankuta.datastructure.tree.iterators.LevelOrderTreeIterator
|
||||
import com.github.adriankuta.datastructure.tree.iterators.PostOrderTreeIterator
|
||||
import com.github.adriankuta.datastructure.tree.iterators.PreOrderTreeIterator
|
||||
import com.github.adriankuta.datastructure.tree.iterators.TreeNodeIterators
|
||||
import com.github.adriankuta.datastructure.tree.iterators.TreeNodeIterators.*
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
|
||||
/**
|
||||
* @param treeIterator Choose one of available iterators from [TreeNodeIterators]
|
||||
*/
|
||||
open class TreeNode<T>(val value: T, var treeIterator: TreeNodeIterators = PreOrder) : Iterable<TreeNode<T>>, ChildDeclarationInterface<T> {
|
||||
|
||||
private var _parent: TreeNode<T>? = null
|
||||
|
||||
/**
|
||||
* The converse notion of a child, an immediate ancestor.
|
||||
*/
|
||||
val parent: TreeNode<T>?
|
||||
get() = _parent
|
||||
|
||||
private val _children = mutableListOf<TreeNode<T>>()
|
||||
|
||||
/**
|
||||
* A group of nodes with the same parent.
|
||||
*/
|
||||
val children: List<TreeNode<T>>
|
||||
get() = _children
|
||||
|
||||
/**
|
||||
* Checks whether the current tree node is the root of the tree
|
||||
* @return `true` if the current tree node is root of the tree, `false` otherwise.
|
||||
*/
|
||||
val isRoot: Boolean
|
||||
get() = _parent == null
|
||||
|
||||
/**
|
||||
* Add new child to current node or root.
|
||||
*
|
||||
* @param child A node which will be directly connected to current node.
|
||||
*/
|
||||
fun addChild(child: TreeNode<T>) {
|
||||
child._parent = this
|
||||
_children.add(child)
|
||||
}
|
||||
|
||||
@JvmSynthetic
|
||||
override fun child(value: T, childDeclaration: ChildDeclaration<T>?): TreeNode<T> {
|
||||
val newChild = TreeNode(value)
|
||||
newChild._parent = this
|
||||
if (childDeclaration != null)
|
||||
newChild.childDeclaration()
|
||||
_children.add(newChild)
|
||||
return newChild
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a single instance of the specified node from this tree, if it is present.
|
||||
*
|
||||
* @return `true` if the node has been successfully removed; `false` if it was not present in the tree.
|
||||
*/
|
||||
fun removeChild(child: TreeNode<T>): Boolean {
|
||||
println(child.value)
|
||||
val removed = child._parent?._children?.remove(child)
|
||||
child._parent = null
|
||||
return removed ?: false
|
||||
}
|
||||
|
||||
/**
|
||||
* This function go through tree and counts children. Root element is not counted.
|
||||
* @return All child and nested child count.
|
||||
*/
|
||||
fun nodeCount(): Int {
|
||||
if (_children.isEmpty())
|
||||
return 0
|
||||
return _children.size +
|
||||
_children.sumOf { it.nodeCount() }
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The number of edges on the longest path between current node and a descendant leaf.
|
||||
*/
|
||||
fun height(): Int {
|
||||
val childrenMaxDepth = _children.map { it.height() }
|
||||
.maxOrNull()
|
||||
?: -1 // -1 because this method counts nodes, and edges are always one less then nodes.
|
||||
return childrenMaxDepth + 1
|
||||
}
|
||||
|
||||
/**
|
||||
* Distance is the number of edges along the shortest path between two nodes.
|
||||
* @return The distance between current node and the root.
|
||||
*/
|
||||
fun depth(): Int {
|
||||
var depth = 0
|
||||
var tempParent = parent
|
||||
|
||||
while (tempParent != null) {
|
||||
depth++
|
||||
tempParent = tempParent.parent
|
||||
}
|
||||
return depth
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the collection of nodes, which connect the current node
|
||||
* with its descendants
|
||||
*
|
||||
* @param descendant the bottom child node for which the path is calculated
|
||||
* @return collection of nodes, which connect the current node with its descendants
|
||||
* @throws TreeNodeException exception that may be thrown in case if the
|
||||
* current node does not have such descendant or if the
|
||||
* specified tree node is root
|
||||
*/
|
||||
@Throws(TreeNodeException::class)
|
||||
fun path(descendant: TreeNode<T>): List<TreeNode<T>> {
|
||||
|
||||
val path = mutableListOf<TreeNode<T>>()
|
||||
var node = descendant
|
||||
path.add(node)
|
||||
while (!node.isRoot) {
|
||||
node = node.parent!!
|
||||
path.add(node)
|
||||
if (node == this)
|
||||
return path
|
||||
}
|
||||
throw TreeNodeException("The specified tree node $descendant is not the descendant of tree node $this")
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all children from root and every node in tree.
|
||||
*/
|
||||
fun clear() {
|
||||
_parent = null
|
||||
_children.forEach { it.clear() }
|
||||
_children.clear()
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return value.toString()
|
||||
}
|
||||
|
||||
fun prettyString(): String {
|
||||
val stringBuilder = StringBuilder()
|
||||
print(stringBuilder, "", "")
|
||||
return stringBuilder.toString()
|
||||
}
|
||||
|
||||
private fun print(stringBuilder: StringBuilder, prefix: String, childrenPrefix: String) {
|
||||
stringBuilder.append(prefix)
|
||||
stringBuilder.append(value)
|
||||
stringBuilder.append('\n')
|
||||
val childIterator = _children.iterator()
|
||||
while (childIterator.hasNext()) {
|
||||
val node = childIterator.next()
|
||||
if (childIterator.hasNext()) {
|
||||
node.print(stringBuilder, "$childrenPrefix├── ", "$childrenPrefix│ ")
|
||||
} else {
|
||||
node.print(stringBuilder, "$childrenPrefix└── ", "$childrenPrefix ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* You can change default iterator by changing [treeIterator] property.
|
||||
*/
|
||||
override fun iterator(): Iterator<TreeNode<T>> = when (treeIterator) {
|
||||
PreOrder -> PreOrderTreeIterator(this)
|
||||
PostOrder -> PostOrderTreeIterator(this)
|
||||
LevelOrder -> LevelOrderTreeIterator(this)
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.github.adriankuta.datastructure.tree
|
||||
|
||||
import com.github.adriankuta.datastructure.tree.iterators.TreeNodeIterators
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
|
||||
typealias ChildDeclaration<T> = ChildDeclarationInterface<T>.() -> Unit
|
||||
|
||||
/**
|
||||
* This method can be used to initialize new tree.
|
||||
* ```
|
||||
* val root = tree("World") { ... }
|
||||
* ```
|
||||
* @param root Root element of new tree.
|
||||
* @see [ChildDeclarationInterface.child]
|
||||
*/
|
||||
@JvmSynthetic
|
||||
inline fun <reified T> tree(
|
||||
root: T,
|
||||
defaultIterator: TreeNodeIterators = TreeNodeIterators.PreOrder,
|
||||
childDeclaration: ChildDeclaration<T>
|
||||
): TreeNode<T> {
|
||||
val treeNode = TreeNode(root, defaultIterator)
|
||||
treeNode.childDeclaration()
|
||||
return treeNode
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package com.github.adriankuta.datastructure.tree.exceptions
|
||||
|
||||
import kotlin.jvm.JvmOverloads
|
||||
|
||||
class TreeNodeException @JvmOverloads constructor(message: String? = null, cause: Throwable? = null) :
|
||||
RuntimeException(message, cause)
|
@ -1,39 +0,0 @@
|
||||
package com.github.adriankuta.datastructure.tree.iterators
|
||||
|
||||
import com.github.adriankuta.datastructure.tree.TreeNode
|
||||
|
||||
/**
|
||||
* Tree is iterated by using `Level-order Traversal Algorithm"
|
||||
* In level-order traversal we iterating nodes level by level,
|
||||
* starting from root, and going deeper and deeper in tree.
|
||||
* ```
|
||||
* E.g.
|
||||
* 1
|
||||
* / | \
|
||||
* / | \
|
||||
* 2 3 4
|
||||
* / \ / | \
|
||||
* 5 6 7 8 9
|
||||
* / / | \
|
||||
* 10 11 12 13
|
||||
*
|
||||
* Output: 1 2 3 4 5 6 7 8 9 10 11 12 13
|
||||
* ```
|
||||
*/
|
||||
class LevelOrderTreeIterator<T>(root: TreeNode<T>) : Iterator<TreeNode<T>> {
|
||||
|
||||
private val stack = ArrayDeque<TreeNode<T>>()
|
||||
|
||||
init {
|
||||
stack.addLast(root)
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean = stack.isNotEmpty()
|
||||
|
||||
override fun next(): TreeNode<T> {
|
||||
val node = stack.removeFirst()
|
||||
node.children
|
||||
.forEach { stack.addLast(it) }
|
||||
return node
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package com.github.adriankuta.datastructure.tree.iterators
|
||||
|
||||
import com.github.adriankuta.datastructure.tree.TreeNode
|
||||
|
||||
/**
|
||||
* Tree is iterated by using `Post-order Traversal Algorithm"
|
||||
* In post-order traversal, we starting from most left child.
|
||||
* First visit all children of parent, then parent.
|
||||
* ```
|
||||
* E.g.
|
||||
* 1
|
||||
* / | \
|
||||
* / | \
|
||||
* 2 3 4
|
||||
* / \ / | \
|
||||
* 5 6 7 8 9
|
||||
* / / | \
|
||||
* 10 11 12 13
|
||||
*
|
||||
* Output: 10 5 11 12 13 6 2 3 7 8 9 4 1
|
||||
* ```
|
||||
*/
|
||||
class PostOrderTreeIterator<T>(root: TreeNode<T>) : Iterator<TreeNode<T>> {
|
||||
|
||||
private val stack = ArrayDeque<TreeNode<T>>()
|
||||
|
||||
init {
|
||||
stack.addAll(getChildrenStack(root))
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean = stack.isNotEmpty()
|
||||
|
||||
override fun next(): TreeNode<T> {
|
||||
return stack.removeFirst()
|
||||
}
|
||||
|
||||
private fun getChildrenStack(node: TreeNode<T>): ArrayDeque<TreeNode<T>> {
|
||||
val stack = ArrayDeque<TreeNode<T>>()
|
||||
if(node.children.isEmpty()) {
|
||||
return ArrayDeque(listOf(node))
|
||||
}
|
||||
node.children.forEach {
|
||||
stack.addAll(getChildrenStack(it))
|
||||
}
|
||||
stack.addLast(node)
|
||||
return stack
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package com.github.adriankuta.datastructure.tree.iterators
|
||||
|
||||
import com.github.adriankuta.datastructure.tree.TreeNode
|
||||
|
||||
/**
|
||||
* Tree is iterated by using `Pre-order Traversal Algorithm"
|
||||
* The pre-order traversal is a topologically sorted one,
|
||||
* because a parent node is processed before any of its child nodes is done.
|
||||
* ```
|
||||
* E.g.
|
||||
* 1
|
||||
* / | \
|
||||
* / | \
|
||||
* 2 3 4
|
||||
* / \ / | \
|
||||
* 5 6 7 8 9
|
||||
* / / | \
|
||||
* 10 11 12 13
|
||||
*
|
||||
* Output: 1 2 5 10 6 11 12 13 3 4 7 8 9
|
||||
* ```
|
||||
*/
|
||||
class PreOrderTreeIterator<T>(root: TreeNode<T>) : Iterator<TreeNode<T>> {
|
||||
|
||||
private val stack = ArrayDeque<TreeNode<T>>()
|
||||
|
||||
init {
|
||||
stack.addLast(root)
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean = stack.isNotEmpty()
|
||||
|
||||
override fun next(): TreeNode<T> {
|
||||
val node = stack.removeLast()
|
||||
node.children
|
||||
.asReversed()
|
||||
.forEach { stack.addLast(it) }
|
||||
return node
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
package com.github.adriankuta.datastructure.tree.iterators
|
||||
|
||||
/**
|
||||
* @see PreOrder
|
||||
* @see PostOrder
|
||||
* @see LevelOrder
|
||||
*/
|
||||
enum class TreeNodeIterators {
|
||||
/**
|
||||
* Tree is iterated by using `Pre-order Traversal Algorithm"
|
||||
* The pre-order traversal is a topologically sorted one,
|
||||
* because a parent node is processed before any of its child nodes is done.
|
||||
* ```
|
||||
* E.g.
|
||||
* 1
|
||||
* / | \
|
||||
* / | \
|
||||
* 2 3 4
|
||||
* / \ / | \
|
||||
* 5 6 7 8 9
|
||||
* / / | \
|
||||
* 10 11 12 13
|
||||
*
|
||||
* Output: 1 2 5 10 6 11 12 13 3 4 7 8 9
|
||||
* ```
|
||||
*/
|
||||
PreOrder,
|
||||
|
||||
/**
|
||||
* Tree is iterated by using `Post-order Traversal Algorithm"
|
||||
* In post-order traversal, we starting from most left child.
|
||||
* First visit all children of parent, then parent.
|
||||
* ```
|
||||
* E.g.
|
||||
* 1
|
||||
* / | \
|
||||
* / | \
|
||||
* 2 3 4
|
||||
* / \ / | \
|
||||
* 5 6 7 8 9
|
||||
* / / | \
|
||||
* 10 11 12 13
|
||||
*
|
||||
* Output: 10 5 11 12 13 6 2 3 7 8 9 4 1
|
||||
* ```
|
||||
*/
|
||||
PostOrder,
|
||||
|
||||
/**
|
||||
* Tree is iterated by using `Level-order Traversal Algorithm"
|
||||
* In level-order traversal we iterating nodes level by level,
|
||||
* starting from root, and going deeper and deeper in tree.
|
||||
* ```
|
||||
* E.g.
|
||||
* 1
|
||||
* / | \
|
||||
* / | \
|
||||
* 2 3 4
|
||||
* / \ / | \
|
||||
* 5 6 7 8 9
|
||||
* / / | \
|
||||
* 10 11 12 13
|
||||
*
|
||||
* Output: 1 2 3 4 5 6 7 8 9 10 11 12 13
|
||||
* ```
|
||||
*/
|
||||
LevelOrder
|
||||
}
|
@ -1,228 +0,0 @@
|
||||
package com.github.adriankuta.datastructure.tree
|
||||
|
||||
import com.github.adriankuta.datastructure.tree.iterators.TreeNodeIterators
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertContentEquals
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNull
|
||||
|
||||
class TreeNodeTest {
|
||||
|
||||
@Test
|
||||
fun removeNodeTest() {
|
||||
val root = TreeNode("Root")
|
||||
val beveragesNode = TreeNode("Beverages")
|
||||
val curdNode = TreeNode("Curd")
|
||||
root.addChild(beveragesNode)
|
||||
root.addChild(curdNode)
|
||||
|
||||
val teaNode = TreeNode("tea")
|
||||
val coffeeNode = TreeNode("coffee")
|
||||
val milkShakeNode = TreeNode("Milk Shake")
|
||||
beveragesNode.addChild(teaNode)
|
||||
beveragesNode.addChild(coffeeNode)
|
||||
beveragesNode.addChild(milkShakeNode)
|
||||
|
||||
val gingerTeaNode = TreeNode("ginger tea")
|
||||
val normalTeaNode = TreeNode("normal tea")
|
||||
teaNode.addChild(gingerTeaNode)
|
||||
teaNode.addChild(normalTeaNode)
|
||||
|
||||
val yogurtNode = TreeNode("yogurt")
|
||||
val lassiNode = TreeNode("lassi")
|
||||
curdNode.addChild(yogurtNode)
|
||||
curdNode.addChild(lassiNode)
|
||||
|
||||
assertEquals(
|
||||
"Root\n" +
|
||||
"├── Beverages\n" +
|
||||
"│ ├── tea\n" +
|
||||
"│ │ ├── ginger tea\n" +
|
||||
"│ │ └── normal tea\n" +
|
||||
"│ ├── coffee\n" +
|
||||
"│ └── Milk Shake\n" +
|
||||
"└── Curd\n" +
|
||||
" ├── yogurt\n" +
|
||||
" └── lassi\n",
|
||||
root.prettyString(),
|
||||
"Pretty print test"
|
||||
)
|
||||
|
||||
root.removeChild(curdNode)
|
||||
root.removeChild(gingerTeaNode)
|
||||
assertEquals(
|
||||
"Root\n" +
|
||||
"└── Beverages\n" +
|
||||
" ├── tea\n" +
|
||||
" │ └── normal tea\n" +
|
||||
" ├── coffee\n" +
|
||||
" └── Milk Shake\n",
|
||||
root.prettyString(),
|
||||
"Remove node test"
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun clearTest() {
|
||||
val root = TreeNode("Root")
|
||||
val beveragesNode = TreeNode("Beverages")
|
||||
val curdNode = TreeNode("Curd")
|
||||
root.addChild(beveragesNode)
|
||||
root.addChild(curdNode)
|
||||
|
||||
val teaNode = TreeNode("tea")
|
||||
val coffeeNode = TreeNode("coffee")
|
||||
val milkShakeNode = TreeNode("Milk Shake")
|
||||
beveragesNode.addChild(teaNode)
|
||||
beveragesNode.addChild(coffeeNode)
|
||||
beveragesNode.addChild(milkShakeNode)
|
||||
|
||||
val gingerTeaNode = TreeNode("ginger tea")
|
||||
val normalTeaNode = TreeNode("normal tea")
|
||||
teaNode.addChild(gingerTeaNode)
|
||||
teaNode.addChild(normalTeaNode)
|
||||
|
||||
val yogurtNode = TreeNode("yogurt")
|
||||
val lassiNode = TreeNode("lassi")
|
||||
curdNode.addChild(yogurtNode)
|
||||
curdNode.addChild(lassiNode)
|
||||
|
||||
root.clear()
|
||||
assertEquals(root.children, emptyList())
|
||||
assertEquals(beveragesNode.children, emptyList())
|
||||
assertEquals(curdNode.children, emptyList())
|
||||
assertEquals(teaNode.children, emptyList())
|
||||
assertEquals(coffeeNode.children, emptyList())
|
||||
assertEquals(milkShakeNode.children, emptyList())
|
||||
assertEquals(gingerTeaNode.children, emptyList())
|
||||
assertEquals(normalTeaNode.children, emptyList())
|
||||
assertEquals(yogurtNode.children, emptyList())
|
||||
assertEquals(lassiNode.children, emptyList())
|
||||
|
||||
assertNull(root.parent)
|
||||
assertNull(beveragesNode.parent)
|
||||
assertNull(curdNode.parent)
|
||||
assertNull(teaNode.parent)
|
||||
assertNull(coffeeNode.parent)
|
||||
assertNull(milkShakeNode.parent)
|
||||
assertNull(gingerTeaNode.parent)
|
||||
assertNull(normalTeaNode.parent)
|
||||
assertNull(yogurtNode.parent)
|
||||
assertNull(lassiNode.parent)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun kotlinExtTest() {
|
||||
val root = TreeNode("World")
|
||||
val northA = TreeNode("North America")
|
||||
val europe = TreeNode("Europe")
|
||||
root.addChild(northA)
|
||||
root.addChild(europe)
|
||||
|
||||
val usa = TreeNode("USA")
|
||||
northA.addChild(usa)
|
||||
|
||||
val poland = TreeNode("Poland")
|
||||
val france = TreeNode("France")
|
||||
europe.addChild(poland)
|
||||
europe.addChild(france)
|
||||
|
||||
val rootExt = tree("World") {
|
||||
child("North America") {
|
||||
child("USA")
|
||||
}
|
||||
child("Europe") {
|
||||
child("Poland")
|
||||
child("France")
|
||||
}
|
||||
}
|
||||
assertEquals(root.prettyString(), rootExt.prettyString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun preOrderIteratorTest() {
|
||||
val tree = tree("F") {
|
||||
child("B") {
|
||||
child("A")
|
||||
child("D") {
|
||||
child("C")
|
||||
child("E")
|
||||
}
|
||||
}
|
||||
child("G") {
|
||||
child("I") {
|
||||
child("H")
|
||||
}
|
||||
}
|
||||
}
|
||||
val expectedPreOrder = listOf("F", "B", "A", "D", "C", "E", "G", "I", "H")
|
||||
assertContentEquals(expectedPreOrder, tree.toList().map { it.toString() })
|
||||
}
|
||||
@Test
|
||||
fun postOrderIteratorTest() {
|
||||
val tree = tree("A", TreeNodeIterators.PostOrder) {
|
||||
child("B") {
|
||||
child("E")
|
||||
}
|
||||
child("C")
|
||||
child("D") {
|
||||
child("F")
|
||||
child("G")
|
||||
child("H")
|
||||
child("I")
|
||||
child("J")
|
||||
}
|
||||
}
|
||||
|
||||
val expectedPreOrder = listOf("E", "B", "C", "F", "G", "H", "I", "J", "D", "A")
|
||||
assertContentEquals(expectedPreOrder, tree.toList().map { it.toString() })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun secondPostOrderIteratorTest() {
|
||||
val tree = tree(1, TreeNodeIterators.PostOrder) {
|
||||
child(2) {
|
||||
child(5) {
|
||||
child(10)
|
||||
}
|
||||
child(6) {
|
||||
child(11)
|
||||
child(12)
|
||||
child(13)
|
||||
}
|
||||
}
|
||||
child(3)
|
||||
child(4) {
|
||||
child(7)
|
||||
child(8)
|
||||
child(9)
|
||||
}
|
||||
}
|
||||
val expectedOrder = listOf(10, 5, 11, 12, 13, 6, 2, 3, 7, 8, 9, 4, 1)
|
||||
assertContentEquals(expectedOrder, tree.toList().map { it.value })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun levelOrderIteratorTest() {
|
||||
val tree = tree(1, TreeNodeIterators.LevelOrder) {
|
||||
child(2) {
|
||||
child(5) {
|
||||
child(10)
|
||||
}
|
||||
child(6) {
|
||||
child(11)
|
||||
child(12)
|
||||
child(13)
|
||||
}
|
||||
}
|
||||
child(3)
|
||||
child(4) {
|
||||
child(7)
|
||||
child(8)
|
||||
child(9)
|
||||
}
|
||||
}
|
||||
val expectedOrder = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
|
||||
assertContentEquals(expectedOrder, tree.toList().map { it.value })
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
import com.github.adriankuta.datastructure.tree.tree
|
||||
|
||||
val root =
|
||||
tree("World") {
|
||||
child("North America") {
|
||||
child("USA")
|
||||
}
|
||||
child("Europe") {
|
||||
child("Poland")
|
||||
child("Germany")
|
||||
}
|
||||
}
|
||||
|
||||
print(root.prettyString())
|
1
treedatastructure/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
49
treedatastructure/build.gradle
Normal file
@ -0,0 +1,49 @@
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
afterEvaluate {
|
||||
generateReleaseBuildConfig.enabled = false
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.2"
|
||||
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "1.0.4"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.core:core-ktx:1.1.0'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
}
|
||||
|
||||
ext {
|
||||
PUBLISH_GROUP_ID = 'com.github.adriankuta'
|
||||
PUBLISH_ARTIFACT_ID = 'tree-structure'
|
||||
PUBLISH_VERSION = android.defaultConfig.versionName
|
||||
}
|
||||
|
||||
apply from: "${rootProject.projectDir}/scripts/publish-mavencentral.gradle"
|
0
treedatastructure/consumer-rules.pro
Normal file
21
treedatastructure/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
@ -0,0 +1,24 @@
|
||||
package com.github.adriankuta.datastructure.tree
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.github.adriankuta.datastructure.tree.test", appContext.packageName)
|
||||
}
|
||||
}
|
2
treedatastructure/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,2 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.github.adriankuta.datastructure.tree" />
|
@ -0,0 +1,63 @@
|
||||
package com.github.adriankuta.datastructure.tree
|
||||
|
||||
class TreeNode<T>(val value: T) {
|
||||
|
||||
private var parent: TreeNode<T>? = null
|
||||
private val children = mutableListOf<TreeNode<T>>()
|
||||
|
||||
fun addChild(child: TreeNode<T>) {
|
||||
child.parent = this
|
||||
children += child
|
||||
}
|
||||
|
||||
fun removeChild(child: TreeNode<T>): Boolean {
|
||||
if (children.isEmpty()) {
|
||||
return false
|
||||
}
|
||||
|
||||
val nestedChildRemoved = children.map {
|
||||
it.removeChild(child)
|
||||
}.reduce { acc, b -> acc or b }
|
||||
|
||||
return children.remove(child) or nestedChildRemoved
|
||||
}
|
||||
|
||||
fun getParent(): TreeNode<T>? = parent
|
||||
|
||||
fun getChildren(): List<TreeNode<T>> = children
|
||||
|
||||
fun size(): Int {
|
||||
if (children.isEmpty())
|
||||
return 0
|
||||
return children.size +
|
||||
children.sumBy { it.size() }
|
||||
|
||||
}
|
||||
|
||||
fun depth(): Int {
|
||||
|
||||
val childrenMaxDepth = children.map { it.depth() }.max() ?: 0
|
||||
return childrenMaxDepth + 1
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
val stringBuilder = StringBuilder()
|
||||
print(stringBuilder, "", "")
|
||||
return stringBuilder.toString()
|
||||
}
|
||||
|
||||
private fun print(stringBuilder: StringBuilder, prefix: String, childrenPrefix: String) {
|
||||
stringBuilder.append(prefix)
|
||||
stringBuilder.append(value)
|
||||
stringBuilder.append('\n')
|
||||
val childIterator = children.iterator()
|
||||
while (childIterator.hasNext()) {
|
||||
val node = childIterator.next()
|
||||
if(childIterator.hasNext()) {
|
||||
node.print(stringBuilder, "$childrenPrefix├── ", "$childrenPrefix│ ")
|
||||
} else {
|
||||
node.print(stringBuilder, "$childrenPrefix└── ", "$childrenPrefix ")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
treedatastructure/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">Tree Data Structure</string>
|
||||
</resources>
|
@ -1,7 +1,8 @@
|
||||
package com.github.adriankuta.datastructure.tree
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|