@@ -14,7 +14,7 @@ import java.util.*
1414 * time : 2019/1/1
1515 * desc :
1616</pre> */
17- open class FileTreeNode private constructor () {
17+ open class FileTreeNode () {
1818
1919 var name: String = " "
2020
@@ -58,21 +58,12 @@ open class FileTreeNode private constructor() {
5858 }
5959 }
6060
61- constructor (block: FileTreeNode .() -> Unit ) : this () {
62- invoke(block)
63- }
64-
6561 constructor (parent: FileTreeNode ? , name: String , isDir: Boolean ) : this () {
6662 this .name = name
6763 this .parent = parent
6864 this .isDir = isDir
6965 }
7066
71- operator fun invoke (block : FileTreeNode .() -> Unit ): FileTreeNode {
72- this .block()
73- return this
74- }
75-
7667 fun removeFromParent (): Boolean {
7768 if (parent != null ) {
7869 parent!! .labeledChildren.remove(getLabel())
@@ -110,6 +101,10 @@ open class FileTreeNode private constructor() {
110101 return labeledChildren.containsKey(label)
111102 }
112103
104+ fun getChild (name : String , isDir : Boolean ): FileTreeNode ? {
105+ return labeledChildren[" ${name} _$isDir " ]
106+ }
107+
113108 /* *
114109 * get the real name replace with placeholder
115110 */
@@ -125,17 +120,6 @@ open class FileTreeNode private constructor() {
125120 return placeholders ? : parent?.getPlaceholderInherit()
126121 }
127122
128- fun fileTemplate (fileName : String , template : String ) {
129- if (this .fileTemplates == null ) {
130- this .fileTemplates = mutableMapOf ()
131- }
132- fileTemplates!! [fileName] = template
133- }
134-
135- fun hasFileTemplate (): Boolean {
136- return template != null || getFileTemplateInherit()?.containsKey(name) == true
137- }
138-
139123 fun getTemplateFile (): String? {
140124 return template ? : getFileTemplateInherit()?.get(name)
141125 }
@@ -146,21 +130,21 @@ open class FileTreeNode private constructor() {
146130
147131 fun placeholder (name : String , value : String ) {
148132 if (this .placeholders == null ) {
149- this .placeholders = kotlin.collections. mutableMapOf ()
133+ this .placeholders = mutableMapOf ()
150134 }
151135 placeholders!! [name] = value
152136 }
153137
154138 fun placeholders (placeholders : Map <String , String >) {
155139 if (this .placeholders == null ) {
156- this .placeholders = kotlin.collections. mutableMapOf ()
140+ this .placeholders = mutableMapOf ()
157141 }
158142 this .placeholders!! .putAll(placeholders)
159143 }
160144
161145 fun fileTemplates (placeholders : Map <String , String >) {
162146 if (this .fileTemplates == null ) {
163- this .fileTemplates = kotlin.collections. mutableMapOf ()
147+ this .fileTemplates = mutableMapOf ()
164148 }
165149 fileTemplates!! .putAll(placeholders)
166150 }
@@ -229,26 +213,14 @@ open class FileTreeNode private constructor() {
229213 }
230214 }
231215
232- /* *
233- * create directory nodes from the path
234- *
235- * @param path The dir path
236- * @param block The child node domain
237- */
238- fun dir (path : String , block : FileTreeNode .() -> Unit = {}) {
239- if (! isDir) return
240- val dirs = path.split(" /" ).filter { it.isNotBlank() }.toMutableList()
241- createDirs(dirs, this )(block)
242- }
243-
244216 /* *
245217 * create directories tree from a list
246218 * the larger the index, the deeper the directory
247219 *
248220 * @param dirs The dirs list to create tree
249221 * @param parent The parent of current node
250222 */
251- private fun createDirs (dirs : MutableList <String >, parent : FileTreeNode ): FileTreeNode {
223+ open fun createDirs (dirs : MutableList <String >, parent : FileTreeNode ): FileTreeNode {
252224 if (dirs.isEmpty()) {
253225 return parent
254226 }
@@ -259,11 +231,6 @@ open class FileTreeNode private constructor() {
259231 return createDirs(dirs, dirNode)
260232 }
261233
262- fun file (name : String ) {
263- if (! isDir) return
264- addChild(FileTreeNode (this , name, false ))
265- }
266-
267234 /* *
268235 * get path of current node.
269236 * if the current node is the root node, it will return absolute path,
@@ -318,7 +285,12 @@ open class FileTreeNode private constructor() {
318285 str.append(when (this ) {
319286 parent?.children?.last() -> " └─"
320287 parent?.children?.first() -> " ├─"
321- else -> if (parent?.parent != null ) " ├─" else " ┌─"
288+ else -> {
289+ when {
290+ parent != null -> " ├─"
291+ else -> " "
292+ }
293+ }
322294 })
323295 str.append(getRealName()).append(" \n " )
324296
@@ -355,7 +327,7 @@ open class FileTreeNode private constructor() {
355327 }
356328 }
357329
358- private fun getLabel (): String {
330+ protected fun getLabel (): String {
359331 return " ${name} _$isDir "
360332 }
361333
0 commit comments