Quellcode durchsuchen

Completed part one

William Brown vor 6 Jahren
Ursprung
Commit
eec427be37
3 geänderte Dateien mit 997 neuen und 1 gelöschten Zeilen
  1. 408
    1
      .idea/workspace.xml
  2. 112
    0
      src/main/java/MyArrayList.java
  3. 477
    0
      src/test/java/MyArrayListTest.java

+ 408
- 1
.idea/workspace.xml Datei anzeigen

@@ -1,15 +1,422 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <project version="4">
3
-  <component name="ProjectFrameBounds">
3
+  <component name="ChangeListManager">
4
+    <list default="true" id="05f02981-1995-4469-ad6a-5aecdfd17208" name="Default Changelist" comment="">
5
+      <change afterPath="$PROJECT_DIR$/src/main/java/MyArrayList.java" afterDir="false" />
6
+      <change afterPath="$PROJECT_DIR$/src/test/java/MyArrayListTest.java" afterDir="false" />
7
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
8
+    </list>
9
+    <ignored path="$PROJECT_DIR$/target/" />
10
+    <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
11
+    <option name="SHOW_DIALOG" value="false" />
12
+    <option name="HIGHLIGHT_CONFLICTS" value="true" />
13
+    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
14
+    <option name="LAST_RESOLUTION" value="IGNORE" />
15
+  </component>
16
+  <component name="FUSProjectUsageTrigger">
17
+    <session id="-1907782372">
18
+      <usages-collector id="statistics.lifecycle.project">
19
+        <counts>
20
+          <entry key="project.closed" value="2" />
21
+          <entry key="project.open.time.1" value="2" />
22
+          <entry key="project.open.time.11" value="1" />
23
+          <entry key="project.opened" value="3" />
24
+        </counts>
25
+      </usages-collector>
26
+      <usages-collector id="statistics.file.extensions.open">
27
+        <counts>
28
+          <entry key="java" value="3" />
29
+          <entry key="md" value="1" />
30
+        </counts>
31
+      </usages-collector>
32
+      <usages-collector id="statistics.file.types.open">
33
+        <counts>
34
+          <entry key="JAVA" value="3" />
35
+          <entry key="Markdown" value="1" />
36
+        </counts>
37
+      </usages-collector>
38
+      <usages-collector id="statistics.file.extensions.edit">
39
+        <counts>
40
+          <entry key="java" value="4265" />
41
+        </counts>
42
+      </usages-collector>
43
+      <usages-collector id="statistics.file.types.edit">
44
+        <counts>
45
+          <entry key="JAVA" value="4265" />
46
+        </counts>
47
+      </usages-collector>
48
+    </session>
49
+  </component>
50
+  <component name="FileEditorManager">
51
+    <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
52
+      <file pinned="false" current-in-tab="false">
53
+        <entry file="file://$PROJECT_DIR$/README.md">
54
+          <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
55
+            <state split_layout="SPLIT">
56
+              <first_editor />
57
+              <second_editor />
58
+            </state>
59
+          </provider>
60
+        </entry>
61
+      </file>
62
+      <file pinned="false" current-in-tab="false">
63
+        <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
64
+          <provider selected="true" editor-type-id="text-editor">
65
+            <state relative-caret-position="85">
66
+              <caret line="6" lean-forward="true" selection-start-line="6" selection-end-line="6" />
67
+              <folding>
68
+                <element signature="e#164#165#0" expanded="true" />
69
+                <element signature="e#211#212#0" expanded="true" />
70
+                <element signature="e#244#245#0" expanded="true" />
71
+                <element signature="e#277#278#0" expanded="true" />
72
+                <element signature="e#142#143#0" expanded="true" />
73
+                <element signature="e#176#177#0" expanded="true" />
74
+                <element signature="e#227#228#0" expanded="true" />
75
+                <element signature="e#273#274#0" expanded="true" />
76
+                <element signature="e#382#412#0" expanded="true" />
77
+                <element signature="e#699#729#0" expanded="true" />
78
+                <element signature="e#1765#1766#0" expanded="true" />
79
+                <element signature="e#1798#1799#0" expanded="true" />
80
+                <element signature="e#1336#1337#0" expanded="true" />
81
+                <element signature="e#1360#1361#0" expanded="true" />
82
+              </folding>
83
+            </state>
84
+          </provider>
85
+        </entry>
86
+      </file>
87
+      <file pinned="false" current-in-tab="true">
88
+        <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
89
+          <provider selected="true" editor-type-id="text-editor">
90
+            <state relative-caret-position="270">
91
+              <caret line="18" column="29" lean-forward="true" selection-start-line="18" selection-start-column="29" selection-end-line="18" selection-end-column="30" />
92
+              <folding>
93
+                <element signature="imports" expanded="true" />
94
+                <element signature="e#388#418#0" expanded="true" />
95
+                <element signature="e#668#698#0" expanded="true" />
96
+                <element signature="e#1073#1103#0" expanded="true" />
97
+                <element signature="e#1370#1400#0" expanded="true" />
98
+                <element signature="e#1782#1812#0" expanded="true" />
99
+                <element signature="e#2180#2210#0" expanded="true" />
100
+                <element signature="e#2734#2764#0" expanded="true" />
101
+                <element signature="e#2958#2988#0" expanded="true" />
102
+                <element signature="e#3184#3214#0" expanded="true" />
103
+                <element signature="e#3410#3440#0" expanded="true" />
104
+              </folding>
105
+            </state>
106
+          </provider>
107
+        </entry>
108
+      </file>
109
+    </leaf>
110
+  </component>
111
+  <component name="FileTemplateManagerImpl">
112
+    <option name="RECENT_TEMPLATES">
113
+      <list>
114
+        <option value="Class" />
115
+      </list>
116
+    </option>
117
+  </component>
118
+  <component name="Git.Settings">
119
+    <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
120
+  </component>
121
+  <component name="IdeDocumentHistory">
122
+    <option name="CHANGED_PATHS">
123
+      <list>
124
+        <option value="$PROJECT_DIR$/src/main/java/MyArrayList.java" />
125
+        <option value="$PROJECT_DIR$/src/test/java/MyArrayListTest.java" />
126
+      </list>
127
+    </option>
128
+  </component>
129
+  <component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
130
+  <component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
131
+  <component name="JsGulpfileManager">
132
+    <detection-done>true</detection-done>
133
+    <sorting>DEFINITION_ORDER</sorting>
134
+  </component>
135
+  <component name="ProjectFrameBounds" fullScreen="true">
4 136
     <option name="y" value="23" />
5 137
     <option name="width" value="1280" />
6 138
     <option name="height" value="738" />
7 139
   </component>
140
+  <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
141
+  <component name="ProjectView">
142
+    <navigator proportions="" version="1">
143
+      <foldersAlwaysOnTop value="true" />
144
+    </navigator>
145
+    <panes>
146
+      <pane id="ProjectPane">
147
+        <subPane>
148
+          <expand>
149
+            <path>
150
+              <item name="generics" type="b2602c69:ProjectViewProjectNode" />
151
+              <item name="CR-MicroLabs-Generics-MyArrayList" type="462c0819:PsiDirectoryNode" />
152
+            </path>
153
+            <path>
154
+              <item name="generics" type="b2602c69:ProjectViewProjectNode" />
155
+              <item name="CR-MicroLabs-Generics-MyArrayList" type="462c0819:PsiDirectoryNode" />
156
+              <item name="src" type="462c0819:PsiDirectoryNode" />
157
+            </path>
158
+            <path>
159
+              <item name="generics" type="b2602c69:ProjectViewProjectNode" />
160
+              <item name="CR-MicroLabs-Generics-MyArrayList" type="462c0819:PsiDirectoryNode" />
161
+              <item name="src" type="462c0819:PsiDirectoryNode" />
162
+              <item name="main" type="462c0819:PsiDirectoryNode" />
163
+            </path>
164
+            <path>
165
+              <item name="generics" type="b2602c69:ProjectViewProjectNode" />
166
+              <item name="CR-MicroLabs-Generics-MyArrayList" type="462c0819:PsiDirectoryNode" />
167
+              <item name="src" type="462c0819:PsiDirectoryNode" />
168
+              <item name="main" type="462c0819:PsiDirectoryNode" />
169
+              <item name="java" type="462c0819:PsiDirectoryNode" />
170
+            </path>
171
+            <path>
172
+              <item name="generics" type="b2602c69:ProjectViewProjectNode" />
173
+              <item name="CR-MicroLabs-Generics-MyArrayList" type="462c0819:PsiDirectoryNode" />
174
+              <item name="src" type="462c0819:PsiDirectoryNode" />
175
+              <item name="test" type="462c0819:PsiDirectoryNode" />
176
+            </path>
177
+            <path>
178
+              <item name="generics" type="b2602c69:ProjectViewProjectNode" />
179
+              <item name="CR-MicroLabs-Generics-MyArrayList" type="462c0819:PsiDirectoryNode" />
180
+              <item name="src" type="462c0819:PsiDirectoryNode" />
181
+              <item name="test" type="462c0819:PsiDirectoryNode" />
182
+              <item name="java" type="462c0819:PsiDirectoryNode" />
183
+            </path>
184
+          </expand>
185
+          <select />
186
+        </subPane>
187
+      </pane>
188
+      <pane id="Scope" />
189
+      <pane id="PackagesPane" />
190
+    </panes>
191
+  </component>
8 192
   <component name="PropertiesComponent">
9 193
     <property name="WebServerToolWindowFactoryState" value="false" />
10 194
     <property name="aspect.path.notification.shown" value="true" />
195
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542254137970" />
11 196
     <property name="last_opened_file_path" value="$PROJECT_DIR$" />
12 197
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
13 198
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
14 199
   </component>
200
+  <component name="RunDashboard">
201
+    <option name="ruleStates">
202
+      <list>
203
+        <RuleState>
204
+          <option name="name" value="ConfigurationTypeDashboardGroupingRule" />
205
+        </RuleState>
206
+        <RuleState>
207
+          <option name="name" value="StatusDashboardGroupingRule" />
208
+        </RuleState>
209
+      </list>
210
+    </option>
211
+  </component>
212
+  <component name="RunManager" selected="JUnit.MyArrayListTest">
213
+    <configuration name="MyArrayListTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
214
+      <module name="generics" />
215
+      <option name="PACKAGE_NAME" value="" />
216
+      <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
217
+      <method v="2">
218
+        <option name="Make" enabled="true" />
219
+      </method>
220
+    </configuration>
221
+    <configuration name="MyArrayListTest.testIsEmptyIntFalse" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
222
+      <module name="generics" />
223
+      <option name="PACKAGE_NAME" value="" />
224
+      <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
225
+      <option name="METHOD_NAME" value="testIsEmptyIntFalse" />
226
+      <option name="TEST_OBJECT" value="method" />
227
+      <method v="2">
228
+        <option name="Make" enabled="true" />
229
+      </method>
230
+    </configuration>
231
+    <configuration name="MyArrayListTest.testSetInt" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
232
+      <module name="generics" />
233
+      <option name="PACKAGE_NAME" value="" />
234
+      <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
235
+      <option name="METHOD_NAME" value="testSetInt" />
236
+      <option name="TEST_OBJECT" value="method" />
237
+      <method v="2">
238
+        <option name="Make" enabled="true" />
239
+      </method>
240
+    </configuration>
241
+    <configuration name="MyArrayListTest.testSizeAfterAddingOne" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
242
+      <module name="generics" />
243
+      <option name="PACKAGE_NAME" value="" />
244
+      <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
245
+      <option name="METHOD_NAME" value="testSizeAfterAddingOne" />
246
+      <option name="TEST_OBJECT" value="method" />
247
+      <method v="2">
248
+        <option name="Make" enabled="true" />
249
+      </method>
250
+    </configuration>
251
+    <configuration name="MyArrayListTest.testSizeConstructor" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
252
+      <module name="generics" />
253
+      <option name="PACKAGE_NAME" value="" />
254
+      <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
255
+      <option name="METHOD_NAME" value="testSizeConstructor" />
256
+      <option name="TEST_OBJECT" value="method" />
257
+      <method v="2">
258
+        <option name="Make" enabled="true" />
259
+      </method>
260
+    </configuration>
261
+    <list>
262
+      <item itemvalue="JUnit.MyArrayListTest.testIsEmptyIntFalse" />
263
+      <item itemvalue="JUnit.MyArrayListTest" />
264
+      <item itemvalue="JUnit.MyArrayListTest.testSetInt" />
265
+      <item itemvalue="JUnit.MyArrayListTest.testSizeAfterAddingOne" />
266
+      <item itemvalue="JUnit.MyArrayListTest.testSizeConstructor" />
267
+    </list>
268
+    <recent_temporary>
269
+      <list>
270
+        <item itemvalue="JUnit.MyArrayListTest" />
271
+        <item itemvalue="JUnit.MyArrayListTest.testSizeConstructor" />
272
+        <item itemvalue="JUnit.MyArrayListTest.testSizeAfterAddingOne" />
273
+        <item itemvalue="JUnit.MyArrayListTest.testSetInt" />
274
+        <item itemvalue="JUnit.MyArrayListTest.testIsEmptyIntFalse" />
275
+      </list>
276
+    </recent_temporary>
277
+  </component>
278
+  <component name="SvnConfiguration">
279
+    <configuration />
280
+  </component>
281
+  <component name="TaskManager">
282
+    <task active="true" id="Default" summary="Default task">
283
+      <changelist id="05f02981-1995-4469-ad6a-5aecdfd17208" name="Default Changelist" comment="" />
284
+      <created>1542225051268</created>
285
+      <option name="number" value="Default" />
286
+      <option name="presentableId" value="Default" />
287
+      <updated>1542225051268</updated>
288
+      <workItem from="1542225052648" duration="3148000" />
289
+      <workItem from="1542229206479" duration="698000" />
290
+      <workItem from="1542247102995" duration="6604000" />
291
+    </task>
292
+    <servers />
293
+  </component>
294
+  <component name="TestHistory">
295
+    <history-entry file="MyArrayListTest - 2018.11.14 at 22h 25m 04s.xml">
296
+      <configuration name="MyArrayListTest" configurationId="JUnit" />
297
+    </history-entry>
298
+    <history-entry file="MyArrayListTest_testSizeAfterAddingOne - 2018.11.14 at 22h 27m 04s.xml">
299
+      <configuration name="MyArrayListTest.testSizeAfterAddingOne" configurationId="JUnit" />
300
+    </history-entry>
301
+    <history-entry file="MyArrayListTest - 2018.11.14 at 22h 32m 00s.xml">
302
+      <configuration name="MyArrayListTest" configurationId="JUnit" />
303
+    </history-entry>
304
+    <history-entry file="MyArrayListTest - 2018.11.14 at 22h 42m 31s.xml">
305
+      <configuration name="MyArrayListTest" configurationId="JUnit" />
306
+    </history-entry>
307
+    <history-entry file="MyArrayListTest - 2018.11.14 at 22h 43m 07s.xml">
308
+      <configuration name="MyArrayListTest" configurationId="JUnit" />
309
+    </history-entry>
310
+    <history-entry file="MyArrayListTest - 2018.11.14 at 22h 43m 29s.xml">
311
+      <configuration name="MyArrayListTest" configurationId="JUnit" />
312
+    </history-entry>
313
+    <history-entry file="MyArrayListTest - 2018.11.14 at 22h 44m 29s.xml">
314
+      <configuration name="MyArrayListTest" configurationId="JUnit" />
315
+    </history-entry>
316
+    <history-entry file="MyArrayListTest - 2018.11.14 at 22h 45m 33s.xml">
317
+      <configuration name="MyArrayListTest" configurationId="JUnit" />
318
+    </history-entry>
319
+    <history-entry file="MyArrayListTest - 2018.11.14 at 22h 53m 10s.xml">
320
+      <configuration name="MyArrayListTest" configurationId="JUnit" />
321
+    </history-entry>
322
+    <history-entry file="MyArrayListTest - 2018.11.14 at 22h 53m 24s.xml">
323
+      <configuration name="MyArrayListTest" configurationId="JUnit" />
324
+    </history-entry>
325
+  </component>
326
+  <component name="TimeTrackingManager">
327
+    <option name="totallyTimeSpent" value="10450000" />
328
+  </component>
329
+  <component name="ToolWindowManager">
330
+    <frame x="0" y="0" width="1280" height="800" extended-state="0" />
331
+    <editor active="true" />
332
+    <layout>
333
+      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25767368" />
334
+      <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
335
+      <window_info id="Image Layers" order="2" />
336
+      <window_info id="Designer" order="3" />
337
+      <window_info id="UI Designer" order="4" />
338
+      <window_info id="Capture Tool" order="5" />
339
+      <window_info id="Favorites" order="6" side_tool="true" />
340
+      <window_info anchor="bottom" id="Message" order="0" />
341
+      <window_info anchor="bottom" id="Find" order="1" />
342
+      <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.34246576" />
343
+      <window_info anchor="bottom" id="Debug" order="3" weight="0.35342467" />
344
+      <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
345
+      <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
346
+      <window_info anchor="bottom" id="TODO" order="6" />
347
+      <window_info anchor="bottom" id="Version Control" order="7" show_stripe_button="false" />
348
+      <window_info anchor="bottom" id="Database Changes" order="8" show_stripe_button="false" />
349
+      <window_info anchor="bottom" id="Terminal" order="9" />
350
+      <window_info anchor="bottom" id="Event Log" order="10" side_tool="true" />
351
+      <window_info anchor="bottom" id="Messages" order="11" weight="0.32876712" />
352
+      <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
353
+      <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
354
+      <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
355
+      <window_info anchor="right" id="Palette" order="3" />
356
+      <window_info anchor="right" id="Capture Analysis" order="4" />
357
+      <window_info anchor="right" id="Database" order="5" />
358
+      <window_info anchor="right" id="Theme Preview" order="6" />
359
+      <window_info anchor="right" id="Palette&#9;" order="7" />
360
+      <window_info anchor="right" id="Maven Projects" order="8" />
361
+    </layout>
362
+  </component>
363
+  <component name="TypeScriptGeneratedFilesManager">
364
+    <option name="version" value="1" />
365
+  </component>
366
+  <component name="VcsContentAnnotationSettings">
367
+    <option name="myLimit" value="2678400000" />
368
+  </component>
369
+  <component name="editorHistoryManager">
370
+    <entry file="file://$PROJECT_DIR$/README.md">
371
+      <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
372
+        <state split_layout="SPLIT">
373
+          <first_editor />
374
+          <second_editor />
375
+        </state>
376
+      </provider>
377
+    </entry>
378
+    <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
379
+      <provider selected="true" editor-type-id="text-editor">
380
+        <state relative-caret-position="85">
381
+          <caret line="6" lean-forward="true" selection-start-line="6" selection-end-line="6" />
382
+          <folding>
383
+            <element signature="e#164#165#0" expanded="true" />
384
+            <element signature="e#211#212#0" expanded="true" />
385
+            <element signature="e#244#245#0" expanded="true" />
386
+            <element signature="e#277#278#0" expanded="true" />
387
+            <element signature="e#142#143#0" expanded="true" />
388
+            <element signature="e#176#177#0" expanded="true" />
389
+            <element signature="e#227#228#0" expanded="true" />
390
+            <element signature="e#273#274#0" expanded="true" />
391
+            <element signature="e#382#412#0" expanded="true" />
392
+            <element signature="e#699#729#0" expanded="true" />
393
+            <element signature="e#1765#1766#0" expanded="true" />
394
+            <element signature="e#1798#1799#0" expanded="true" />
395
+            <element signature="e#1336#1337#0" expanded="true" />
396
+            <element signature="e#1360#1361#0" expanded="true" />
397
+          </folding>
398
+        </state>
399
+      </provider>
400
+    </entry>
401
+    <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
402
+      <provider selected="true" editor-type-id="text-editor">
403
+        <state relative-caret-position="270">
404
+          <caret line="18" column="29" lean-forward="true" selection-start-line="18" selection-start-column="29" selection-end-line="18" selection-end-column="30" />
405
+          <folding>
406
+            <element signature="imports" expanded="true" />
407
+            <element signature="e#388#418#0" expanded="true" />
408
+            <element signature="e#668#698#0" expanded="true" />
409
+            <element signature="e#1073#1103#0" expanded="true" />
410
+            <element signature="e#1370#1400#0" expanded="true" />
411
+            <element signature="e#1782#1812#0" expanded="true" />
412
+            <element signature="e#2180#2210#0" expanded="true" />
413
+            <element signature="e#2734#2764#0" expanded="true" />
414
+            <element signature="e#2958#2988#0" expanded="true" />
415
+            <element signature="e#3184#3214#0" expanded="true" />
416
+            <element signature="e#3410#3440#0" expanded="true" />
417
+          </folding>
418
+        </state>
419
+      </provider>
420
+    </entry>
421
+  </component>
15 422
 </project>

+ 112
- 0
src/main/java/MyArrayList.java Datei anzeigen

@@ -0,0 +1,112 @@
1
+import java.lang.reflect.Array;
2
+
3
+public class MyArrayList<T>{
4
+
5
+    private T t;
6
+    private T[] myArrayList;
7
+
8
+    @SuppressWarnings("unchecked")
9
+    public MyArrayList(int size) {
10
+        this.myArrayList = (T[]) new Object[size];
11
+    }
12
+
13
+    @SuppressWarnings("unchecked")
14
+    public MyArrayList() {
15
+        this.myArrayList = (T[])new Object[0];
16
+    }
17
+
18
+    public T[] getMyArrayList() {
19
+        return myArrayList;
20
+    }
21
+
22
+    public void setMyArrayList(T[] myArrayList) {
23
+        this.myArrayList = myArrayList;
24
+    }
25
+
26
+    public T getT() {
27
+        return t;
28
+    }
29
+
30
+    public void setT(T t) {
31
+        this.t = t;
32
+    }
33
+
34
+    @SuppressWarnings("unchecked")
35
+    public void add(T element){
36
+        T[] output = (T[])new Object[myArrayList.length + 1];
37
+        for(int i = 0; i < myArrayList.length; i ++){
38
+            output[i] = myArrayList[i];
39
+        }
40
+        output[myArrayList.length] = element;
41
+
42
+        myArrayList = output;
43
+    }
44
+
45
+    @SuppressWarnings("unchecked")
46
+    public void add(int index, T element){
47
+        T[] output = (T[]) new Object[myArrayList.length + 1];
48
+        for(int i = 0; i < output.length; i++){
49
+            if(i < index){
50
+                output[i] = myArrayList[i];
51
+            }else if(i > index){
52
+                output[i] = myArrayList[i - 1];
53
+            }else{
54
+                output[index] = element;
55
+            }
56
+        }
57
+
58
+        myArrayList = output;
59
+    }
60
+
61
+    public T get(int index){
62
+        for(int i = 0; i < myArrayList.length; i++){
63
+            if(i == index){
64
+                return myArrayList[i];
65
+            }
66
+        }
67
+        return null;
68
+    }
69
+
70
+    public void remove(int index){
71
+        T[] output = (T[]) new Object[myArrayList.length - 1];
72
+        int counter = 0;
73
+
74
+        for(int i = 0; i < myArrayList.length; i++){
75
+            if(i != index){
76
+                output[counter] = myArrayList[i];
77
+                counter++;
78
+            }
79
+        }
80
+
81
+        myArrayList = output;
82
+    }
83
+
84
+    public void set(int index, T element){
85
+        myArrayList[index] = element;
86
+    }
87
+
88
+    public void clear(){
89
+        T[] output = (T[]) new Object[0];
90
+        myArrayList = output;
91
+    }
92
+
93
+    public boolean isEmpty(){
94
+        if(myArrayList.length == 0){
95
+            return true;
96
+        }
97
+        return false;
98
+    }
99
+
100
+    public boolean contains(T element){
101
+        for(int i = 0; i < myArrayList.length; i++){
102
+            if(element.equals(myArrayList[i])){
103
+                return true;
104
+            }
105
+        }
106
+        return false;
107
+    }
108
+
109
+    public int size(){
110
+        return myArrayList.length;
111
+    }
112
+}

+ 477
- 0
src/test/java/MyArrayListTest.java Datei anzeigen

@@ -0,0 +1,477 @@
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
4
+public class MyArrayListTest {
5
+
6
+    @Test
7
+    public void testSizeConstructor(){
8
+        MyArrayList myArrayList = new MyArrayList(20);
9
+
10
+        int expected = 20;
11
+        int actual = myArrayList.size();
12
+
13
+        Assert.assertEquals(expected, actual);
14
+    }
15
+
16
+    @Test
17
+    public void testSizeBefore(){
18
+        MyArrayList myArrayList = new MyArrayList();
19
+
20
+        int expected = 0;
21
+        int actual = myArrayList.size();
22
+
23
+        Assert.assertEquals(expected, actual);
24
+    }
25
+
26
+    @Test
27
+    @SuppressWarnings("unchecked")
28
+    public void testSizeAfterAddingOne(){
29
+        MyArrayList myArrayList = new MyArrayList();
30
+
31
+        myArrayList.add(34566);
32
+
33
+        int expected = 1;
34
+        int actual = myArrayList.size();
35
+
36
+        Assert.assertEquals(expected, actual);
37
+    }
38
+
39
+
40
+
41
+
42
+
43
+    @Test
44
+    @SuppressWarnings("unchecked")
45
+    public void testAddInt(){
46
+        MyArrayList myArrayList = new MyArrayList();
47
+        myArrayList.add(34);
48
+
49
+        int expected = 1;
50
+        int actual = myArrayList.size();
51
+
52
+        Assert.assertEquals(expected, actual);
53
+    }
54
+
55
+    @Test
56
+    @SuppressWarnings("unchecked")
57
+    public void testAddString(){
58
+        MyArrayList myArrayList = new MyArrayList();
59
+        myArrayList.add("William");
60
+
61
+        int expected = 1;
62
+        int actual = myArrayList.size();
63
+
64
+        Assert.assertEquals(expected, actual);
65
+    }
66
+
67
+    @Test
68
+    @SuppressWarnings("unchecked")
69
+    public void testAddLong(){
70
+        MyArrayList myArrayList = new MyArrayList();
71
+        myArrayList.add(304);
72
+
73
+        int expected = 1;
74
+        int actual = myArrayList.size();
75
+
76
+        Assert.assertEquals(expected, actual);
77
+    }
78
+
79
+    @Test
80
+    @SuppressWarnings("unchecked")
81
+    public void testAddDouble(){
82
+        MyArrayList myArrayList = new MyArrayList();
83
+        myArrayList.add(34.5);
84
+
85
+        int expected = 1;
86
+        int actual = myArrayList.size();
87
+
88
+        Assert.assertEquals(expected, actual);
89
+    }
90
+
91
+
92
+
93
+
94
+
95
+    @Test
96
+    @SuppressWarnings("unchecked")
97
+    public void testAddWithParamInt(){
98
+        MyArrayList myArrayList = new MyArrayList();
99
+        myArrayList.add(1);
100
+        myArrayList.add(2);
101
+        myArrayList.add(3);
102
+        myArrayList.add(4);
103
+
104
+        myArrayList.add(2, 46);
105
+
106
+        int expected = 5;
107
+        int actual = myArrayList.size();
108
+
109
+        Assert.assertEquals(expected, actual);
110
+    }
111
+
112
+    @Test
113
+    @SuppressWarnings("unchecked")
114
+    public void testAddWithParamIntEmpty(){
115
+        MyArrayList myArrayList = new MyArrayList();
116
+        myArrayList.add(0, 74);
117
+
118
+        int expected = 1;
119
+        int actual = myArrayList.size();
120
+
121
+        Assert.assertEquals(expected, actual);
122
+    }
123
+
124
+    @Test
125
+    @SuppressWarnings("unchecked")
126
+    public void testAddWithParamString(){
127
+        MyArrayList myArrayList = new MyArrayList();
128
+        myArrayList.add(0, "William");
129
+
130
+        int expected = 1;
131
+        int actual = myArrayList.size();
132
+
133
+        Assert.assertEquals(expected, actual);
134
+    }
135
+
136
+    @Test
137
+    @SuppressWarnings("unchecked")
138
+    public void testAddWithParamLong(){
139
+        MyArrayList myArrayList = new MyArrayList();
140
+        myArrayList.add(0, 704);
141
+
142
+        int expected = 1;
143
+        int actual = myArrayList.size();
144
+
145
+        Assert.assertEquals(expected, actual);
146
+    }
147
+
148
+    @Test
149
+    @SuppressWarnings("unchecked")
150
+    public void testAddWithParamDouble(){
151
+        MyArrayList myArrayList = new MyArrayList();
152
+        myArrayList.add(0, 74.5);
153
+
154
+        int expected = 1;
155
+        int actual = myArrayList.size();
156
+
157
+        Assert.assertEquals(expected, actual);
158
+    }
159
+
160
+
161
+
162
+
163
+
164
+    @Test
165
+    @SuppressWarnings("unchecked")
166
+    public void testGetInt(){
167
+        MyArrayList myArrayList = new MyArrayList();
168
+        myArrayList.add(23);
169
+        myArrayList.add(6);
170
+        myArrayList.add(34);
171
+        myArrayList.add(98);
172
+        myArrayList.add(0);
173
+
174
+        Integer expected = 0;
175
+        Integer actual = (Integer) myArrayList.get(4);
176
+
177
+        Assert.assertEquals(expected, actual);
178
+    }
179
+
180
+    @Test
181
+    @SuppressWarnings("unchecked")
182
+    public void testGetString(){
183
+        MyArrayList myArrayList = new MyArrayList();
184
+        myArrayList.add("a");
185
+        myArrayList.add("Word");
186
+        myArrayList.add("something");
187
+        myArrayList.add("ofCourse");
188
+        myArrayList.add("jawn");
189
+
190
+        String expected = "jawn";
191
+        String actual = (String) myArrayList.get(4);
192
+
193
+        Assert.assertEquals(expected, actual);
194
+    }
195
+
196
+    @Test
197
+    @SuppressWarnings("unchecked")
198
+    public void testGetLong(){
199
+        MyArrayList myArrayList = new MyArrayList();
200
+        myArrayList.add(233L);
201
+        myArrayList.add(62L);
202
+        myArrayList.add(334L);
203
+        myArrayList.add(984L);
204
+        myArrayList.add(302L);
205
+
206
+        Long expected = 62L;
207
+        Long actual = (Long) myArrayList.get(1);
208
+
209
+        Assert.assertEquals(expected, actual);
210
+    }
211
+
212
+    @Test
213
+    @SuppressWarnings("unchecked")
214
+    public void testGetDouble(){
215
+        MyArrayList myArrayList = new MyArrayList();
216
+        myArrayList.add(23);
217
+        myArrayList.add(6.5);
218
+        myArrayList.add(34);
219
+        myArrayList.add(98.5);
220
+        myArrayList.add(0);
221
+
222
+        Double expected = 98.5;
223
+        Double actual = (Double) myArrayList.get(3);
224
+
225
+        Assert.assertEquals(expected, actual);
226
+    }
227
+
228
+
229
+
230
+
231
+
232
+    @Test
233
+    @SuppressWarnings("unchecked")
234
+    public void testRemoveInt(){
235
+        MyArrayList myArrayList = new MyArrayList();
236
+        myArrayList.add(1);
237
+        myArrayList.add(2);
238
+        myArrayList.add(3);
239
+        myArrayList.add(4);
240
+
241
+        myArrayList.remove(2);
242
+
243
+        int expected = 3;
244
+        int actual = myArrayList.size();
245
+
246
+        Assert.assertEquals(expected, actual);
247
+    }
248
+
249
+    @Test
250
+    @SuppressWarnings("unchecked")
251
+    public void testRemoveString(){
252
+        MyArrayList myArrayList = new MyArrayList();
253
+        myArrayList.add("This");
254
+        myArrayList.add("is");
255
+        myArrayList.add("so");
256
+        myArrayList.add("amazing");
257
+
258
+        myArrayList.remove(2);
259
+
260
+        int expected = 3;
261
+        int actual = myArrayList.size();
262
+
263
+        Assert.assertEquals(expected, actual);
264
+    }
265
+
266
+    @Test
267
+    @SuppressWarnings("unchecked")
268
+    public void testRemoveLong(){
269
+        MyArrayList myArrayList = new MyArrayList();
270
+        myArrayList.add(1);
271
+        myArrayList.add(23);
272
+        myArrayList.add(3000);
273
+        myArrayList.add(4203);
274
+
275
+        myArrayList.remove(2);
276
+
277
+        int expected = 3;
278
+        int actual = myArrayList.size();
279
+
280
+        Assert.assertEquals(expected, actual);
281
+    }
282
+
283
+    @Test
284
+    @SuppressWarnings("unchecked")
285
+    public void testRemoveDouble(){
286
+        MyArrayList myArrayList = new MyArrayList();
287
+        myArrayList.add(1.23);
288
+        myArrayList.add(2.4);
289
+        myArrayList.add(3.1);
290
+        myArrayList.add(4);
291
+
292
+        myArrayList.remove(2);
293
+
294
+        int expected = 3;
295
+        int actual = myArrayList.size();
296
+
297
+        Assert.assertEquals(expected, actual);
298
+    }
299
+
300
+
301
+
302
+
303
+
304
+    @Test
305
+    @SuppressWarnings("unchecked")
306
+    public void testClearInt(){
307
+        MyArrayList myArrayList = new MyArrayList();
308
+        myArrayList.add(1);
309
+        myArrayList.add(2);
310
+        myArrayList.add(3);
311
+        myArrayList.add(4);
312
+
313
+        myArrayList.clear();
314
+
315
+        int expected = 0;
316
+        int actual = myArrayList.size();
317
+
318
+        Assert.assertEquals(expected, actual);
319
+    }
320
+
321
+    @Test
322
+    @SuppressWarnings("unchecked")
323
+    public void testClearString(){
324
+        MyArrayList myArrayList = new MyArrayList();
325
+        myArrayList.add("This");
326
+        myArrayList.add("is");
327
+        myArrayList.add("so");
328
+        myArrayList.add("amazing");
329
+
330
+        myArrayList.clear();
331
+
332
+        int expected = 0;
333
+        int actual = myArrayList.size();
334
+
335
+        Assert.assertEquals(expected, actual);
336
+    }
337
+
338
+    @Test
339
+    @SuppressWarnings("unchecked")
340
+    public void testClearLong(){
341
+        MyArrayList myArrayList = new MyArrayList();
342
+        myArrayList.add(1);
343
+        myArrayList.add(23);
344
+        myArrayList.add(3000);
345
+        myArrayList.add(4203);
346
+
347
+        myArrayList.clear();
348
+
349
+        int expected = 0;
350
+        int actual = myArrayList.size();
351
+
352
+        Assert.assertEquals(expected, actual);
353
+    }
354
+
355
+    @Test
356
+    @SuppressWarnings("unchecked")
357
+    public void testClearDouble(){
358
+        MyArrayList myArrayList = new MyArrayList();
359
+        myArrayList.add(1.23);
360
+        myArrayList.add(2.4);
361
+        myArrayList.add(3.1);
362
+        myArrayList.add(4);
363
+
364
+        myArrayList.clear();
365
+
366
+        int expected = 0;
367
+        int actual = myArrayList.size();
368
+
369
+        Assert.assertEquals(expected, actual);
370
+    }
371
+
372
+
373
+
374
+
375
+
376
+    @Test
377
+    @SuppressWarnings("unchecked")
378
+    public void testIsEmptyIntTrue(){
379
+        MyArrayList myArrayList = new MyArrayList();
380
+
381
+        Assert.assertTrue(myArrayList.isEmpty());
382
+    }
383
+
384
+    @Test
385
+    @SuppressWarnings("unchecked")
386
+    public void testIsEmptyFalse(){
387
+        MyArrayList myArrayList = new MyArrayList();
388
+        myArrayList.add(4);
389
+
390
+        Assert.assertFalse(myArrayList.isEmpty());
391
+    }
392
+
393
+
394
+
395
+
396
+
397
+    @Test
398
+    @SuppressWarnings("unchecked")
399
+    public void testContainsIntTrue(){
400
+        MyArrayList myArrayList = new MyArrayList();
401
+        myArrayList.add(4);
402
+
403
+        Assert.assertFalse(myArrayList.contains(3));
404
+    }
405
+
406
+    @Test
407
+    @SuppressWarnings("unchecked")
408
+    public void testContainsFalse(){
409
+        MyArrayList myArrayList = new MyArrayList();
410
+        myArrayList.add(4);
411
+
412
+        Assert.assertTrue(myArrayList.contains(4));
413
+    }
414
+
415
+
416
+
417
+
418
+
419
+    @Test
420
+    @SuppressWarnings("unchecked")
421
+    public void testSetInt(){
422
+        MyArrayList myArrayList = new MyArrayList();
423
+        myArrayList.add(1);
424
+        myArrayList.add(2);
425
+        myArrayList.add(3);
426
+        myArrayList.add(4);
427
+
428
+        myArrayList.set(2, 6);
429
+
430
+        Assert.assertEquals(4, myArrayList.size());
431
+        Assert.assertTrue(myArrayList.contains(6));
432
+    }
433
+
434
+    @Test
435
+    @SuppressWarnings("unchecked")
436
+    public void testSetString(){
437
+        MyArrayList myArrayList = new MyArrayList();
438
+        myArrayList.add("Well");
439
+        myArrayList.add("Hello");
440
+        myArrayList.add("There");
441
+
442
+        myArrayList.set(2, "Oops");
443
+
444
+        Assert.assertEquals(3, myArrayList.size());
445
+        Assert.assertTrue(myArrayList.contains("Oops"));
446
+    }
447
+
448
+    @Test
449
+    @SuppressWarnings("unchecked")
450
+    public void testSetLong(){
451
+        MyArrayList myArrayList = new MyArrayList();
452
+        myArrayList.add(1234);
453
+        myArrayList.add(3222);
454
+        myArrayList.add(390);
455
+        myArrayList.add(4234);
456
+
457
+        myArrayList.set(2, 6);
458
+
459
+        Assert.assertEquals(4, myArrayList.size());
460
+        Assert.assertTrue(myArrayList.contains(6));
461
+    }
462
+
463
+    @Test
464
+    @SuppressWarnings("unchecked")
465
+    public void testSetDouble(){
466
+        MyArrayList myArrayList = new MyArrayList();
467
+        myArrayList.add(1.2);
468
+        myArrayList.add(2);
469
+        myArrayList.add(3.23);
470
+        myArrayList.add(4.7);
471
+
472
+        myArrayList.set(2, 6.23);
473
+
474
+        Assert.assertEquals(4, myArrayList.size());
475
+        Assert.assertTrue(myArrayList.contains(6.23));
476
+    }
477
+}