|
1 | | -package com.devkev.devscript.raw; |
2 | | - |
3 | | -import java.util.ArrayList; |
4 | | - |
5 | | -import com.devkev.devscript.raw.ApplicationBuilder.Type; |
6 | | - |
7 | | -public class Array { //For dataContainers |
8 | | - private final ArrayList<Object> indexes = new ArrayList<Object>(2); |
9 | | - public DataType arrayType; |
10 | | - |
11 | | - public Array(Object... indexes) { |
12 | | - for(Object d : indexes) this.indexes.add(d); |
13 | | - updateArraytype(); |
14 | | - } |
15 | | - |
16 | | - public Array() { |
17 | | - updateArraytype(); |
18 | | - } |
19 | | - |
20 | | - public void push(Object container) { |
21 | | - indexes.add(container); |
22 | | - updateArraytype(); |
23 | | - } |
24 | | - |
25 | | - public void push(Object container, int index) { |
26 | | - indexes.add(index, container); |
27 | | - updateArraytype(); |
28 | | - } |
29 | | - |
30 | | - public void pop(int index) { |
31 | | - indexes.remove(index); |
32 | | - updateArraytype(); |
33 | | - } |
34 | | - |
35 | | - public void pop(Object container) { |
36 | | - indexes.remove(container); |
37 | | - updateArraytype(); |
38 | | - } |
39 | | - |
40 | | - public ArrayList<Object> getIndexes() { |
41 | | - return indexes; |
42 | | - } |
43 | | - |
44 | | - public void updateArraytype() { |
45 | | - Type type = Type.NULL; |
46 | | - for(int j = 0; j < indexes.size(); j++) { |
47 | | - DataType containerType = ApplicationBuilder.toDataType(indexes.get(j)); |
48 | | - if(j > 0) { |
49 | | - DataType indexType = ApplicationBuilder.toDataType(indexes.get(j-1)); |
50 | | - if(indexType.type != containerType.type && type != Type.ANY) { |
51 | | - type = Type.ANY; |
52 | | - break; |
53 | | - } |
54 | | - } else if(j == 0) { |
55 | | - type = containerType.type; |
56 | | - } |
57 | | - } |
58 | | - arrayType = new DataType(type, true); |
59 | | - } |
60 | | - |
61 | | - public String toString() { |
62 | | - String s = "ARRAY:{"; |
63 | | - for(int i = 0; i < indexes.size()-1; i++) s += indexes.get(i) + ","; |
64 | | - if(indexes.size() > 0) s += indexes.get(indexes.size()-1); |
65 | | - return s + "}"; |
66 | | - } |
67 | | -} |
| 1 | +package com.devkev.devscript.raw; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | + |
| 5 | +import com.devkev.devscript.raw.ApplicationBuilder.Type; |
| 6 | + |
| 7 | +public class Array { //For dataContainers |
| 8 | + private final ArrayList<Object> indexes = new ArrayList<Object>(2); |
| 9 | + public DataType arrayType; |
| 10 | + |
| 11 | + public Array(Object... indexes) { |
| 12 | + for(Object d : indexes) this.indexes.add(d); |
| 13 | + updateArraytype(); |
| 14 | + } |
| 15 | + |
| 16 | + public Array() { |
| 17 | + updateArraytype(); |
| 18 | + } |
| 19 | + |
| 20 | + public void push(Object container) { |
| 21 | + indexes.add(container); |
| 22 | + updateArraytype(); |
| 23 | + } |
| 24 | + |
| 25 | + public void push(Object container, int index) { |
| 26 | + indexes.add(index, container); |
| 27 | + updateArraytype(); |
| 28 | + } |
| 29 | + |
| 30 | + public void pop(int index) { |
| 31 | + indexes.remove(index); |
| 32 | + updateArraytype(); |
| 33 | + } |
| 34 | + |
| 35 | + public void pop(Object container) { |
| 36 | + indexes.remove(container); |
| 37 | + updateArraytype(); |
| 38 | + } |
| 39 | + |
| 40 | + public ArrayList<Object> getIndexes() { |
| 41 | + return indexes; |
| 42 | + } |
| 43 | + |
| 44 | + public void updateArraytype() { |
| 45 | + Type type = Type.NULL; |
| 46 | + for(int j = 0; j < indexes.size(); j++) { |
| 47 | + DataType containerType = ApplicationBuilder.toDataType(indexes.get(j)); |
| 48 | + if(j > 0) { |
| 49 | + DataType indexType = ApplicationBuilder.toDataType(indexes.get(j-1)); |
| 50 | + if(indexType.type != containerType.type && type != Type.ANY) { |
| 51 | + type = Type.ANY; |
| 52 | + break; |
| 53 | + } |
| 54 | + } else if(j == 0) { |
| 55 | + type = containerType.type; |
| 56 | + } |
| 57 | + } |
| 58 | + arrayType = new DataType(type, true); |
| 59 | + } |
| 60 | + |
| 61 | + public String toString() { |
| 62 | + String s = "ARRAY:{"; |
| 63 | + for(int i = 0; i < indexes.size()-1; i++) s += indexes.get(i) + ","; |
| 64 | + if(indexes.size() > 0) s += indexes.get(indexes.size()-1); |
| 65 | + return s + "}"; |
| 66 | + } |
| 67 | +} |
0 commit comments