|
1 | 1 | package io.github.jeemv.springboot.vuejs.utilities;
|
2 | 2 |
|
3 |
| - |
4 | 3 | /**
|
5 |
| - * JsArray |
6 |
| - * Javascript array utilities |
7 |
| - * This class is part of springBoot-VueJS |
| 4 | + * JsArray Javascript array utilities This class is part of springBoot-VueJS |
| 5 | + * |
8 | 6 | * @author jcheron myaddressmail@gmail.com
|
9 |
| - * @version 1.0.0 |
| 7 | + * @version 1.0.1 |
10 | 8 | *
|
11 | 9 | */
|
12 | 10 | public class JsArray {
|
13 |
| - |
| 11 | + |
14 | 12 | /**
|
15 | 13 | * Remove an element from array
|
16 |
| - * @param array the array reference |
| 14 | + * |
| 15 | + * @param array the array reference |
17 | 16 | * @param element the element to remove
|
18 | 17 | * @return
|
19 | 18 | */
|
20 |
| - public static String remove(String array,String element) { |
21 |
| - return array+".splice(self.orgas.indexOf("+element+"), 1);"; |
| 19 | + public static String remove(String array, String element) { |
| 20 | + return array + ".splice(array.indexOf(" + element + "), 1);"; |
22 | 21 | }
|
23 |
| - |
| 22 | + |
24 | 23 | /**
|
25 | 24 | * Replace an element at index position in array
|
26 |
| - * @param array the array reference |
27 |
| - * @param index The index of the element to replace |
| 25 | + * |
| 26 | + * @param array the array reference |
| 27 | + * @param index The index of the element to replace |
28 | 28 | * @param element The element to replace with
|
29 | 29 | * @return
|
30 | 30 | */
|
31 |
| - public static String replace(String array,String index,String element) { |
32 |
| - return " Object.assign("+array+"["+index+"], "+element+");"; |
| 31 | + public static String replace(String array, String index, String element) { |
| 32 | + return " Object.assign(" + array + "[" + index + "], " + element + ");"; |
33 | 33 | }
|
34 |
| - |
| 34 | + |
35 | 35 | /**
|
36 | 36 | * Adds an element to array
|
37 |
| - * @param array The array reference |
| 37 | + * |
| 38 | + * @param array The array reference |
38 | 39 | * @param element The element to add
|
39 | 40 | * @return
|
40 | 41 | */
|
41 |
| - public static String add(String array,String element) { |
42 |
| - return array+".push("+element+");"; |
| 42 | + public static String add(String array, String element) { |
| 43 | + return array + ".push(" + element + ");"; |
43 | 44 | }
|
44 |
| - |
| 45 | + |
45 | 46 | /**
|
46 | 47 | * Adds or replace an element in array
|
47 |
| - * @param array The array reference |
48 |
| - * @param index The index of the element to replace or -1 for adding |
| 48 | + * |
| 49 | + * @param array The array reference |
| 50 | + * @param index The index of the element to replace or -1 for adding |
49 | 51 | * @param element The element to add or replace
|
50 | 52 | * @return
|
51 | 53 | */
|
52 |
| - public static String addOrReplace(String array,String index,String element) { |
53 |
| - return "if("+index+">-1){"+replace(array, index, element)+"}else{"+add(array, element)+"}"; |
| 54 | + public static String addOrReplace(String array, String index, String element) { |
| 55 | + return "if(" + index + ">-1){" + replace(array, index, element) + "}else{" + add(array, element) + "}"; |
54 | 56 | }
|
55 | 57 | }
|
0 commit comments