Skip to content

Commit 6ee8452

Browse files
committed
fix: Update README.md
1 parent 72ba672 commit 6ee8452

1 file changed

Lines changed: 111 additions & 76 deletions

File tree

README.md

Lines changed: 111 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
```kotlin
66
dependencies {
7-
implementation("io.github.Yaklede:empty-object-generator:0.1.1")
7+
implementation("io.github.Yaklede:empty-object-generator:0.2.1")
88
}
99
```
1010

@@ -25,7 +25,7 @@ val double: Double
2525
val boolean: Boolean
2626
val list: List<Any>
2727
val set: Set<Any>
28-
val map: Map<Any,Any>
28+
val map: Map<Any, Any>
2929

3030
val stringSingleArray: Array<String>
3131
val intSingleArray: IntArray
@@ -35,7 +35,7 @@ val doubleSingleArray: DoubleArray
3535
val booleanSingleArray: BooleanArray
3636
val listArray: Array<List<Any>>
3737
val setArray: Array<Set<Any>>
38-
val mapArray: Array<Map<Any,Any>>
38+
val mapArray: Array<Map<Any, Any>>
3939

4040
val stringNestedArray: Array<Array<String>>
4141
val intNestedArray: Array<IntArray>
@@ -45,10 +45,18 @@ val doubleNestedArray: Array<DoubleArray>
4545
val booleanNestedArray: Array<BooleanArray>
4646
val listNestedArray: Array<Array<List<Any>>>
4747
val setNestedArray: Array<Array<Set<Any>>>
48-
val mapNestedArray: Array<Array<Map<Any,Any>>>
48+
val mapNestedArray: Array<Array<Map<Any, Any>>>
4949
```
5050

51-
## Supported Parameter
51+
## Supported Method
52+
53+
| Method | Description |
54+
|--------------------------|-------------------------------------------------------------------|
55+
| `generate` | Used to create an empty object. |
56+
| `addCustomSupportType` | Allows specifying the return type for the generated empty object. |
57+
| `clearCustomTypeSupport` | Resets all registered custom types. |
58+
59+
### Generate Method Supported Parameter
5260

5361
| Parameter | Type | Description | Default Value | Required |
5462
|-----------------------|-------------|-------------------------------------------------------------------------------|---------------|----------|
@@ -64,12 +72,35 @@ val mapNestedArray: Array<Array<Map<Any,Any>>>
6472
| defaultInnerArraySize | Int | The default size for 2-dimensional arrays. | 0 | No |
6573
| emptyValue | EmptyValue? | Customizable empty value for additional support beyond primitive types. | null | No |
6674

75+
### addCustomSupportType Supported Parameter
76+
77+
| Parameter | Description | Type | Default Value | Required |
78+
|----------------|-------------------------------------------------------------|-------------|---------------|----------|
79+
| `clazz` | Represents the class of the supported custom Kotlin type. | `KClass<*>` | - | Yes |
80+
| `defaultValue` | Represents the default value for the specified Kotlin type. | `Any` | - | Yes |
81+
82+
### clearCustomTypeSupport
83+
84+
| Parameter | Description | Type | Default Value | Required |
85+
|-----------------|---------------------------------|------|---------------|----------|
86+
| (No parameters) | (No parameters for this method) | - | - | No |
87+
6788
## How use
6889

90+
- The usual method involves receiving the return value and then utilizing it.
91+
6992
```kotlin
7093
val result: YourClass = EmptyObjectGenerator.generate(YourClass::class)
7194
```
7295

96+
- You can use it directly within the method block without receiving the return value.
97+
98+
```kotlin
99+
EmptyObjectGenerator.generate(YourClass::class) {
100+
something(it)
101+
}
102+
```
103+
73104
## Example
74105

75106
### Primitive type
@@ -84,7 +115,7 @@ data class EmptyPrimitiveObject(
84115
val boolean: Boolean? = null,
85116
val list: List<Any>? = null,
86117
val set: Set<Any>? = null,
87-
val map: Map<Any,Any>? = null
118+
val map: Map<Any, Any>? = null
88119
)
89120

90121
val emptyPrimitiveObject = EmptyObjectGenerator.generate(EmptyPrimitiveObject::class)
@@ -128,22 +159,22 @@ data class ComplexEmptyPrimitiveObject(
128159
val boolean: Boolean,
129160
val nullableList: List<Any>? = null,
130161
val set: Set<Any>,
131-
val nullableMap: Map<Any,Any>? = null,
162+
val nullableMap: Map<Any, Any>? = null,
132163
)
133164

134-
val complexEmptyPrimitiveObject = EmptyObjectGenerator.generate(ComplexEmptyPrimitiveObject::class,isNullable = true)
165+
val complexEmptyPrimitiveObject = EmptyObjectGenerator.generate(ComplexEmptyPrimitiveObject::class, isNullable = true)
135166

136167
//return
137168
ComplexEmptyPrimitiveObject(
138-
nullableString=null,
139-
nullableInt=null,
140-
nullableLong=null,
141-
float=0.0f,
142-
double=0.0,
143-
boolean=false,
144-
nullableList=null,
145-
set=[],
146-
nullableMap=null
169+
nullableString = null,
170+
nullableInt = null,
171+
nullableLong = null,
172+
float = 0.0f,
173+
double = 0.0,
174+
boolean = false,
175+
nullableList = null,
176+
set = [],
177+
nullableMap = null
147178
)
148179

149180
```
@@ -167,35 +198,37 @@ val emptyArrayObject = EmptyObjectGenerator.generate(EmptyArrayObject::class, de
167198

168199
//returns
169200
EmptyArrayObject(
170-
stringArray=["empty", "empty", "empty", "empty", "empty"],
171-
intArray=[0, 0, 0, 0, 0],
172-
longArray=[0, 0, 0, 0, 0],
173-
floatArray=[0.0f, 0.0f, 0.0f, 0.0f, 0.0f],
174-
doubleArray=[0.0, 0.0, 0.0, 0.0, 0.0],
175-
booleanArray=[false, false, false, false, false],
176-
listArray=[[], [], [], [], []],
177-
setArray=[[], [], [], [], []],
178-
mapArray=[{}, {}, {}, {}, {}]
201+
stringArray = ["empty", "empty", "empty", "empty", "empty"],
202+
intArray = [0, 0, 0, 0, 0],
203+
longArray = [0, 0, 0, 0, 0],
204+
floatArray = [0.0f, 0.0f, 0.0f, 0.0f, 0.0f],
205+
doubleArray = [0.0, 0.0, 0.0, 0.0, 0.0],
206+
booleanArray = [false, false, false, false, false],
207+
listArray = [[], [], [], [], []],
208+
setArray = [[], [], [], [], []],
209+
mapArray = [{}, {}, {}, {}, {}]
179210
)
180211

181212
//if you use parameter nullable = true
182-
val emptyArrayObjectIsNullable = EmptyObjectGenerator.generate(EmptyArrayObject::class, defaultArraySize = 5, isNullable = true)
213+
val emptyArrayObjectIsNullable =
214+
EmptyObjectGenerator.generate(EmptyArrayObject::class, defaultArraySize = 5, isNullable = true)
183215

184216
//return
185217
EmptyArrayObject(
186-
stringArray=null,
187-
intArray=null,
188-
longArray=null,
189-
floatArray=null,
190-
doubleArray=null,
191-
booleanArray=null,
192-
listArray=null,
193-
setArray=null,
218+
stringArray = null,
219+
intArray = null,
220+
longArray = null,
221+
floatArray = null,
222+
doubleArray = null,
223+
booleanArray = null,
224+
listArray = null,
225+
setArray = null,
194226
mapArray = null
195227
)
196228
```
197229

198230
### Primitive nested array type
231+
199232
```kotlin
200233
data class EmptyNestedArrayObject(
201234
val stringNestedArray: Array<Array<String>>? = null,
@@ -206,7 +239,7 @@ data class EmptyNestedArrayObject(
206239
val booleanNestedArray: Array<BooleanArray>? = null,
207240
val listNestedArray: Array<Array<List<Any>>>? = null,
208241
val setNestedArray: Array<Array<Set<Any>>>? = null,
209-
val mapNestedArray: Array<Array<Map<Any,Any>>>? = null
242+
val mapNestedArray: Array<Array<Map<Any, Any>>>? = null
210243
)
211244

212245
val emptyNestedArrayObject = EmptyObjectGenerator.generate(
@@ -217,15 +250,15 @@ val emptyNestedArrayObject = EmptyObjectGenerator.generate(
217250

218251
//return
219252
EmptyNestedArrayObject(
220-
stringNestedArray=[["empty", "empty", "empty", "empty", "empty"], ["empty", "empty", "empty", "empty", "empty"]],
221-
intNestedArray=[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],
222-
longNestedArray=[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],
223-
floatNestedArray=[[0.0f, 0.0f, 0.0f, 0.0f, 0.0f],[0.0f, 0.0f, 0.0f, 0.0f, 0.0f]],
224-
doubleNestedArray=[[0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0]],
225-
booleanNestedArray=[[false, false, false, false, false], [false, false, false, false, false]],
226-
listNestedArray = [[[],[],[],[],[]]],
227-
setNestedArray = [[[],[],[],[],[]]],
228-
mapNestedArray = [[{},{},{},{},{}]]
253+
stringNestedArray = [["empty", "empty", "empty", "empty", "empty"], ["empty", "empty", "empty", "empty", "empty"]],
254+
intNestedArray = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],
255+
longNestedArray = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],
256+
floatNestedArray = [[0.0f, 0.0f, 0.0f, 0.0f, 0.0f], [0.0f, 0.0f, 0.0f, 0.0f, 0.0f]],
257+
doubleNestedArray = [[0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0]],
258+
booleanNestedArray = [[false, false, false, false, false], [false, false, false, false, false]],
259+
listNestedArray = [[[], [], [], [], []]],
260+
setNestedArray = [[[], [], [], [], []]],
261+
mapNestedArray = [[{}, {}, {}, {}, {}]]
229262
)
230263
//if you use parameter nullable = true
231264
val emptyNestedArrayObjectIsNullable = EmptyObjectGenerator.generate(
@@ -237,19 +270,20 @@ val emptyNestedArrayObjectIsNullable = EmptyObjectGenerator.generate(
237270

238271
//return
239272
EmptyNestedArrayObject(
240-
stringNestedArray=null,
241-
intNestedArray=null,
242-
longNestedArray=null,
243-
floatNestedArray=null,
244-
doubleNestedArray=null,
245-
booleanNestedArray=null,
273+
stringNestedArray = null,
274+
intNestedArray = null,
275+
longNestedArray = null,
276+
floatNestedArray = null,
277+
doubleNestedArray = null,
278+
booleanNestedArray = null,
246279
listNestedArray = null,
247280
setNestedArray = null,
248281
mapNestedArray = null
249282
)
250283
```
251284

252285
### Complex type
286+
253287
```kotlin
254288
data class ComplexObject(
255289
val int: Int,
@@ -271,14 +305,14 @@ val complexObject = EmptyObjectGenerator.generate(
271305
)
272306
//return
273307
ComplexObject(
274-
int=0,
275-
stringNullable="empty",
276-
list=[],
277-
listNullable=[],
278-
complexInnerObject=ComplexInnerObject(
279-
boolean=false,
280-
doubleArrayNullable=[0.0],
281-
floatNestedArray=[[0.0, 0.0]]
308+
int = 0,
309+
stringNullable = "empty",
310+
list = [],
311+
listNullable = [],
312+
complexInnerObject = ComplexInnerObject(
313+
boolean = false,
314+
doubleArrayNullable = [0.0],
315+
floatNestedArray = [[0.0, 0.0]]
282316
)
283317
)
284318

@@ -293,20 +327,21 @@ val complexObjectNullable = EmptyObjectGenerator.generate(
293327

294328
//return
295329
ComplexObject(
296-
int=0,
297-
stringNullable=null,
298-
list=[],
299-
listNullable=null,
300-
complexInnerObject=null
330+
int = 0,
331+
stringNullable = null,
332+
list = [],
333+
listNullable = null,
334+
complexInnerObject = null
301335
)
302336
```
303337

304-
305338
## Custom Support
339+
306340
### Caution
307-
- If you use a custom support it returns only default value
308-
- Objects registered with custom support are globally accessible, so use them with care to avoid unintended side effects throughout your application.
309341

342+
- If you use a custom support it returns only default value
343+
- Objects registered with custom support are globally accessible, so use them with care to avoid unintended side effects
344+
throughout your application.
310345

311346
```kotlin
312347
data class EmptySupportTestObject(
@@ -332,14 +367,14 @@ EmptyObjectGenerator.addCustomTypeSupport(
332367
defaultValue = defaultValue
333368
)
334369

335-
val supportTypeObject = EmptyObjectGenerator.generate(EmptySupportTestObject::class)
370+
val supportTypeObject = EmptyObjectGenerator.generate(EmptySupportTestObject::class)
336371

337372
//return
338373
EmptySupportTestObject(
339-
intArray=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
340-
innerObject=EmptySupportTestInnerObject(
341-
int=10,
342-
string="innerObject"
374+
intArray = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
375+
innerObject = EmptySupportTestInnerObject(
376+
int = 10,
377+
string = "innerObject"
343378
)
344379
)
345380

@@ -348,10 +383,10 @@ val emptySupportTestObjectNullable = EmptyObjectGenerator.generate(EmptySupportT
348383

349384
//return
350385
EmptySupportTestObject(
351-
intArray=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
352-
innerObject=EmptySupportTestInnerObject(
353-
int=10,
354-
string="innerObject"
386+
intArray = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
387+
innerObject = EmptySupportTestInnerObject(
388+
int = 10,
389+
string = "innerObject"
355390
)
356391
)
357392
```

0 commit comments

Comments
 (0)