| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
package smetana.core; |
| 38 |
|
| 39 |
import java.util.ArrayList; |
| 40 |
import java.util.List; |
| 41 |
|
| 42 |
import smetana.core.amiga.Area; |
| 43 |
import smetana.core.amiga.AreaInt; |
| 44 |
import smetana.core.amiga.BuilderArea; |
| 45 |
import smetana.core.amiga.Counter; |
| 46 |
|
| 47 |
public class __array_of_integer_impl__ implements __array_of_integer__ { |
| 48 |
|
| 49 |
private final List<Area> data; |
| 50 |
private final int currentPos; |
| 51 |
|
| 52 |
private final int UID = Counter.CPT++; |
| 53 |
|
| 54 |
public String getUID36() { |
| 55 |
return Integer.toString(UID, 36); |
| 56 |
} |
| 57 |
|
| 58 |
public void swap(int i, int j) { |
| 59 |
Area e1 = data.get(i); |
| 60 |
Area e2 = data.get(j); |
| 61 |
data.set(i, e2); |
| 62 |
data.set(j, e1); |
| 63 |
} |
| 64 |
|
| 65 |
@Override |
| 66 |
public String toString() { |
| 67 |
if (data.get(0) != null) { |
| 68 |
return "__array__ " + getUID36() + " " + currentPos + "/" + data.size() + " " + data.get(0).toString(); |
| 69 |
} |
| 70 |
return "__array__ " + getUID36() + " " + currentPos + "/" + data.size(); |
| 71 |
} |
| 72 |
|
| 73 |
public void realloc(int nb) { |
| 74 |
while (data.size() < nb + currentPos) { |
| 75 |
data.add(new AreaInt()); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public int comparePointerInternal(__array_of_integer__ other2) { |
| 84 |
__array_of_integer_impl__ other = (__array_of_integer_impl__) other2; |
| 85 |
if (this.data != other.data) { |
| 86 |
throw new IllegalArgumentException(); |
| 87 |
} |
| 88 |
return this.currentPos - other.currentPos; |
| 89 |
} |
| 90 |
|
| 91 |
public static __array_of_integer_impl__ mallocInteger(int nb) { |
| 92 |
return new __array_of_integer_impl__(nb, new BuilderArea() { |
| 93 |
public Area createArea() { |
| 94 |
return new AreaInt(); |
| 95 |
} |
| 96 |
}); |
| 97 |
} |
| 98 |
|
| 99 |
private __array_of_integer_impl__(List<Area> data, int currentPos) { |
| 100 |
this.data = data; |
| 101 |
this.currentPos = currentPos; |
| 102 |
check(); |
| 103 |
} |
| 104 |
|
| 105 |
private __array_of_integer_impl__(int size, BuilderArea builder) { |
| 106 |
this.data = new ArrayList<Area>(); |
| 107 |
this.currentPos = 0; |
| 108 |
for (int i = 0; i < size; i++) { |
| 109 |
final Area tmp = builder.createArea(); |
| 110 |
data.add(tmp); |
| 111 |
} |
| 112 |
check(); |
| 113 |
} |
| 114 |
|
| 115 |
private void check() { |
| 116 |
if (getUID36().equals("194")) { |
| 117 |
JUtils.LOG("It's me"); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
public __array_of_integer_impl__ move(int delta) { |
| 122 |
return new __array_of_integer_impl__(data, currentPos + delta); |
| 123 |
} |
| 124 |
|
| 125 |
public __array_of_integer_impl__ plus(int delta) { |
| 126 |
return move(delta); |
| 127 |
} |
| 128 |
|
| 129 |
public Area getInternal(int idx) { |
| 130 |
return data.get(idx + currentPos); |
| 131 |
} |
| 132 |
|
| 133 |
public void memcopyFrom(Area source) { |
| 134 |
throw new UnsupportedOperationException(); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
public int getInt() { |
| 140 |
return ((AreaInt) getInternal(0)).getInternal(); |
| 141 |
} |
| 142 |
|
| 143 |
public void setInt(int value) { |
| 144 |
((AreaInt) getInternal(0)).setInternal(value); |
| 145 |
} |
| 146 |
|
| 147 |
} |