Debian Codegraph @

src/smetana/core/__array_of_integer_impl__.java

raw symbols SCIP
1 /* ========================================================================
2 * PlantUML : a free UML diagram generator
3 * ========================================================================
4 *
5 * Project Info: http://plantuml.com
6 *
7 * If you like this project or if you find it useful, you can support us at:
8 *
9 * http://plantuml.com/patreon (only 1$ per month!)
10 * http://plantuml.com/paypal
11 *
12 * This file is part of Smetana.
13 * Smetana is a partial translation of Graphviz/Dot sources from C to Java.
14 *
15 * (C) Copyright 2009-2020, Arnaud Roques
16 *
17 * This translation is distributed under the same Licence as the original C program.
18 *
19 * THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
20 * LICENSE ("AGREEMENT"). [Eclipse Public License - v 1.0]
21 *
22 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
23 * RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
24 *
25 * You may obtain a copy of the License at
26 *
27 * http://www.eclipse.org/legal/epl-v10.html
28 *
29 * Unless required by applicable law or agreed to in writing, software
30 * distributed under the License is distributed on an "AS IS" BASIS,
31 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32 * See the License for the specific language governing permissions and
33 * limitations under the License.
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 // public __ptr__ asPtr() {
80 // return new StarArray(this);
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 }