Seth 6 år sedan
förälder
incheckning
0825754497
3 ändrade filer med 317 tillägg och 62 borttagningar
  1. 123
    56
      .idea/workspace.xml
  2. 46
    4
      src/main/java/MyArrayList.java
  3. 148
    2
      src/test/java/MyArrayListTest.java

+ 123
- 56
.idea/workspace.xml Visa fil

2
 <project version="4">
2
 <project version="4">
3
   <component name="ChangeListManager">
3
   <component name="ChangeListManager">
4
     <list default="true" id="7ad04558-d1a8-448f-add7-490f9c754201" name="Default Changelist" comment="">
4
     <list default="true" id="7ad04558-d1a8-448f-add7-490f9c754201" name="Default Changelist" comment="">
5
-      <change afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" />
6
-      <change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__junit_junit_4_12.xml" afterDir="false" />
7
-      <change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml" afterDir="false" />
8
-      <change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
9
-      <change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
10
-      <change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
11
-      <change afterPath="$PROJECT_DIR$/generics.iml" afterDir="false" />
12
-      <change afterPath="$PROJECT_DIR$/src/main/java/MyArrayList.java" afterDir="false" />
13
-      <change afterPath="$PROJECT_DIR$/src/test/java/MyArrayListTest.java" afterDir="false" />
14
-      <change beforePath="$PROJECT_DIR$/src/main/java/.deleteme" beforeDir="false" />
15
-      <change beforePath="$PROJECT_DIR$/src/test/java/.deleteme" beforeDir="false" />
5
+      <change beforePath="$PROJECT_DIR$/src/main/java/MyArrayList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/MyArrayList.java" afterDir="false" />
6
+      <change beforePath="$PROJECT_DIR$/src/test/java/MyArrayListTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/MyArrayListTest.java" afterDir="false" />
16
     </list>
7
     </list>
17
     <ignored path="$PROJECT_DIR$/target/" />
8
     <ignored path="$PROJECT_DIR$/target/" />
18
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
9
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
31
       </usages-collector>
22
       </usages-collector>
32
       <usages-collector id="statistics.file.extensions.open">
23
       <usages-collector id="statistics.file.extensions.open">
33
         <counts>
24
         <counts>
25
+          <entry key="class" value="2" />
34
           <entry key="gitignore" value="1" />
26
           <entry key="gitignore" value="1" />
35
-          <entry key="java" value="3" />
27
+          <entry key="java" value="5" />
36
         </counts>
28
         </counts>
37
       </usages-collector>
29
       </usages-collector>
38
       <usages-collector id="statistics.file.types.open">
30
       <usages-collector id="statistics.file.types.open">
39
         <counts>
31
         <counts>
40
-          <entry key="JAVA" value="3" />
32
+          <entry key="CLASS" value="2" />
33
+          <entry key="JAVA" value="5" />
41
           <entry key="PLAIN_TEXT" value="1" />
34
           <entry key="PLAIN_TEXT" value="1" />
42
         </counts>
35
         </counts>
43
       </usages-collector>
36
       </usages-collector>
44
       <usages-collector id="statistics.file.extensions.edit">
37
       <usages-collector id="statistics.file.extensions.edit">
45
         <counts>
38
         <counts>
46
-          <entry key="java" value="1080" />
39
+          <entry key="java" value="3332" />
47
         </counts>
40
         </counts>
48
       </usages-collector>
41
       </usages-collector>
49
       <usages-collector id="statistics.file.types.edit">
42
       <usages-collector id="statistics.file.types.edit">
50
         <counts>
43
         <counts>
51
-          <entry key="JAVA" value="1080" />
44
+          <entry key="JAVA" value="3332" />
52
         </counts>
45
         </counts>
53
       </usages-collector>
46
       </usages-collector>
54
     </session>
47
     </session>
55
   </component>
48
   </component>
56
   <component name="FileEditorManager">
49
   <component name="FileEditorManager">
57
     <leaf>
50
     <leaf>
58
-      <file pinned="false" current-in-tab="true">
51
+      <file pinned="false" current-in-tab="false">
59
         <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
52
         <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
60
           <provider selected="true" editor-type-id="text-editor">
53
           <provider selected="true" editor-type-id="text-editor">
61
-            <state relative-caret-position="465">
62
-              <caret line="31" column="44" selection-start-line="31" selection-start-column="44" selection-end-line="31" selection-end-column="44" />
54
+            <state relative-caret-position="-7">
55
+              <caret line="134" column="23" lean-forward="true" selection-start-line="134" selection-start-column="23" selection-end-line="134" selection-end-column="23" />
63
               <folding>
56
               <folding>
64
                 <element signature="imports" expanded="true" />
57
                 <element signature="imports" expanded="true" />
65
                 <element signature="e#143#144#0" expanded="true" />
58
                 <element signature="e#143#144#0" expanded="true" />
69
           </provider>
62
           </provider>
70
         </entry>
63
         </entry>
71
       </file>
64
       </file>
72
-      <file pinned="false" current-in-tab="false">
65
+      <file pinned="false" current-in-tab="true">
73
         <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
66
         <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
74
           <provider selected="true" editor-type-id="text-editor">
67
           <provider selected="true" editor-type-id="text-editor">
75
-            <state relative-caret-position="360">
76
-              <caret line="26" column="13" lean-forward="true" selection-start-line="26" selection-start-column="13" selection-end-line="26" selection-end-column="13" />
68
+            <state relative-caret-position="332">
69
+              <caret line="71" selection-start-line="71" selection-end-line="71" />
77
               <folding>
70
               <folding>
78
-                <element signature="e#338#339#0" expanded="true" />
79
-                <element signature="e#372#373#0" expanded="true" />
71
+                <element signature="e#729#730#0" expanded="true" />
72
+                <element signature="e#763#764#0" expanded="true" />
73
+                <element signature="e#1365#1366#0" expanded="true" />
74
+                <element signature="e#1399#1400#0" expanded="true" />
75
+                <element signature="e#1433#1434#0" expanded="true" />
76
+                <element signature="e#1464#1465#0" expanded="true" />
80
               </folding>
77
               </folding>
81
             </state>
78
             </state>
82
           </provider>
79
           </provider>
168
   <component name="PropertiesComponent">
165
   <component name="PropertiesComponent">
169
     <property name="WebServerToolWindowFactoryState" value="false" />
166
     <property name="WebServerToolWindowFactoryState" value="false" />
170
     <property name="aspect.path.notification.shown" value="true" />
167
     <property name="aspect.path.notification.shown" value="true" />
171
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542151954778" />
168
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542200951534" />
172
     <property name="last_opened_file_path" value="$PROJECT_DIR$" />
169
     <property name="last_opened_file_path" value="$PROJECT_DIR$" />
173
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
170
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
174
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
171
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
186
       </list>
183
       </list>
187
     </option>
184
     </option>
188
   </component>
185
   </component>
189
-  <component name="RunManager" selected="JUnit.MyArrayListTest.sizeAddTest">
190
-    <configuration name="MyArrayListTest.sizeAddTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
186
+  <component name="RunManager" selected="JUnit.MyArrayListTest">
187
+    <configuration name="MyArrayListTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
188
+      <module name="generics" />
189
+      <option name="PACKAGE_NAME" value="" />
190
+      <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
191
+      <method v="2">
192
+        <option name="Make" enabled="true" />
193
+      </method>
194
+    </configuration>
195
+    <configuration name="MyArrayListTest.clearTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
196
+      <module name="generics" />
197
+      <option name="PACKAGE_NAME" value="" />
198
+      <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
199
+      <option name="METHOD_NAME" value="clearTest" />
200
+      <option name="TEST_OBJECT" value="method" />
201
+      <method v="2">
202
+        <option name="Make" enabled="true" />
203
+      </method>
204
+    </configuration>
205
+    <configuration name="MyArrayListTest.contains" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
191
       <module name="generics" />
206
       <module name="generics" />
192
       <option name="PACKAGE_NAME" value="" />
207
       <option name="PACKAGE_NAME" value="" />
193
       <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
208
       <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
194
-      <option name="METHOD_NAME" value="sizeAddTest" />
209
+      <option name="METHOD_NAME" value="contains" />
195
       <option name="TEST_OBJECT" value="method" />
210
       <option name="TEST_OBJECT" value="method" />
196
       <method v="2">
211
       <method v="2">
197
         <option name="Make" enabled="true" />
212
         <option name="Make" enabled="true" />
198
       </method>
213
       </method>
199
     </configuration>
214
     </configuration>
200
-    <configuration name="MyArrayListTest.sizeNoElementsTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
215
+    <configuration name="MyArrayListTest.containsNotThere" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
201
       <module name="generics" />
216
       <module name="generics" />
202
       <option name="PACKAGE_NAME" value="" />
217
       <option name="PACKAGE_NAME" value="" />
203
       <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
218
       <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
204
-      <option name="METHOD_NAME" value="sizeNoElementsTest" />
219
+      <option name="METHOD_NAME" value="containsNotThere" />
220
+      <option name="TEST_OBJECT" value="method" />
221
+      <method v="2">
222
+        <option name="Make" enabled="true" />
223
+      </method>
224
+    </configuration>
225
+    <configuration name="MyArrayListTest.isEmptyTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
226
+      <module name="generics" />
227
+      <option name="PACKAGE_NAME" value="" />
228
+      <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
229
+      <option name="METHOD_NAME" value="isEmptyTest" />
205
       <option name="TEST_OBJECT" value="method" />
230
       <option name="TEST_OBJECT" value="method" />
206
       <method v="2">
231
       <method v="2">
207
         <option name="Make" enabled="true" />
232
         <option name="Make" enabled="true" />
208
       </method>
233
       </method>
209
     </configuration>
234
     </configuration>
210
     <list>
235
     <list>
211
-      <item itemvalue="JUnit.MyArrayListTest.sizeAddTest" />
212
-      <item itemvalue="JUnit.MyArrayListTest.sizeNoElementsTest" />
236
+      <item itemvalue="JUnit.MyArrayListTest.clearTest" />
237
+      <item itemvalue="JUnit.MyArrayListTest.isEmptyTest" />
238
+      <item itemvalue="JUnit.MyArrayListTest.contains" />
239
+      <item itemvalue="JUnit.MyArrayListTest.containsNotThere" />
240
+      <item itemvalue="JUnit.MyArrayListTest" />
213
     </list>
241
     </list>
214
     <recent_temporary>
242
     <recent_temporary>
215
       <list>
243
       <list>
216
-        <item itemvalue="JUnit.MyArrayListTest.sizeAddTest" />
217
-        <item itemvalue="JUnit.MyArrayListTest.sizeNoElementsTest" />
244
+        <item itemvalue="JUnit.MyArrayListTest" />
245
+        <item itemvalue="JUnit.MyArrayListTest.containsNotThere" />
246
+        <item itemvalue="JUnit.MyArrayListTest.contains" />
247
+        <item itemvalue="JUnit.MyArrayListTest.isEmptyTest" />
248
+        <item itemvalue="JUnit.MyArrayListTest.clearTest" />
218
       </list>
249
       </list>
219
     </recent_temporary>
250
     </recent_temporary>
220
   </component>
251
   </component>
228
       <option name="number" value="Default" />
259
       <option name="number" value="Default" />
229
       <option name="presentableId" value="Default" />
260
       <option name="presentableId" value="Default" />
230
       <updated>1542149227412</updated>
261
       <updated>1542149227412</updated>
231
-      <workItem from="1542149228819" duration="2638000" />
262
+      <workItem from="1542149228819" duration="10441000" />
232
     </task>
263
     </task>
233
     <servers />
264
     <servers />
234
   </component>
265
   </component>
235
   <component name="TestHistory">
266
   <component name="TestHistory">
236
-    <history-entry file="MyArrayListTest_sizeAddTest - 2018.11.13 at 18h 21m 51s.xml">
237
-      <configuration name="MyArrayListTest.sizeAddTest" configurationId="JUnit" />
267
+    <history-entry file="MyArrayListTest_setTest - 2018.11.13 at 19h 50m 07s.xml">
268
+      <configuration name="MyArrayListTest.setTest" configurationId="JUnit" />
269
+    </history-entry>
270
+    <history-entry file="MyArrayListTest_addAtIndexTest - 2018.11.13 at 19h 50m 15s.xml">
271
+      <configuration name="MyArrayListTest.addAtIndexTest" configurationId="JUnit" />
272
+    </history-entry>
273
+    <history-entry file="MyArrayListTest_setTest - 2018.11.13 at 19h 51m 02s.xml">
274
+      <configuration name="MyArrayListTest.setTest" configurationId="JUnit" />
275
+    </history-entry>
276
+    <history-entry file="MyArrayListTest_setTest - 2018.11.13 at 19h 52m 21s.xml">
277
+      <configuration name="MyArrayListTest.setTest" configurationId="JUnit" />
238
     </history-entry>
278
     </history-entry>
239
-    <history-entry file="MyArrayListTest_sizeNoElementsTest - 2018.11.13 at 18h 21m 56s.xml">
240
-      <configuration name="MyArrayListTest.sizeNoElementsTest" configurationId="JUnit" />
279
+    <history-entry file="MyArrayListTest_clearTest - 2018.11.14 at 07h 32m 09s.xml">
280
+      <configuration name="MyArrayListTest.clearTest" configurationId="JUnit" />
241
     </history-entry>
281
     </history-entry>
242
-    <history-entry file="MyArrayListTest_sizeAddTest - 2018.11.13 at 18h 22m 00s.xml">
243
-      <configuration name="MyArrayListTest.sizeAddTest" configurationId="JUnit" />
282
+    <history-entry file="MyArrayListTest_isEmptyTest - 2018.11.14 at 07h 38m 01s.xml">
283
+      <configuration name="MyArrayListTest.isEmptyTest" configurationId="JUnit" />
244
     </history-entry>
284
     </history-entry>
245
-    <history-entry file="MyArrayListTest_sizeAddTest - 2018.11.13 at 18h 23m 18s.xml">
246
-      <configuration name="MyArrayListTest.sizeAddTest" configurationId="JUnit" />
285
+    <history-entry file="MyArrayListTest_isEmptyTest - 2018.11.14 at 07h 46m 53s.xml">
286
+      <configuration name="MyArrayListTest.isEmptyTest" configurationId="JUnit" />
287
+    </history-entry>
288
+    <history-entry file="MyArrayListTest_contains - 2018.11.14 at 07h 53m 33s.xml">
289
+      <configuration name="MyArrayListTest.contains" configurationId="JUnit" />
290
+    </history-entry>
291
+    <history-entry file="MyArrayListTest_containsNotThere - 2018.11.14 at 07h 54m 51s.xml">
292
+      <configuration name="MyArrayListTest.containsNotThere" configurationId="JUnit" />
293
+    </history-entry>
294
+    <history-entry file="MyArrayListTest - 2018.11.14 at 08h 04m 52s.xml">
295
+      <configuration name="MyArrayListTest" configurationId="JUnit" />
247
     </history-entry>
296
     </history-entry>
248
   </component>
297
   </component>
249
   <component name="TimeTrackingManager">
298
   <component name="TimeTrackingManager">
250
-    <option name="totallyTimeSpent" value="2638000" />
299
+    <option name="totallyTimeSpent" value="10441000" />
251
   </component>
300
   </component>
252
   <component name="ToolWindowManager">
301
   <component name="ToolWindowManager">
253
     <frame x="0" y="23" width="1440" height="807" extended-state="0" />
302
     <frame x="0" y="23" width="1440" height="807" extended-state="0" />
258
       <window_info id="UI Designer" />
307
       <window_info id="UI Designer" />
259
       <window_info id="Capture Tool" />
308
       <window_info id="Capture Tool" />
260
       <window_info id="Favorites" side_tool="true" />
309
       <window_info id="Favorites" side_tool="true" />
261
-      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24964234" />
310
+      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.24964234" />
262
       <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
311
       <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
263
       <window_info anchor="bottom" id="Messages" />
312
       <window_info anchor="bottom" id="Messages" />
264
       <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
313
       <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
267
       <window_info anchor="bottom" id="Event Log" side_tool="true" />
316
       <window_info anchor="bottom" id="Event Log" side_tool="true" />
268
       <window_info anchor="bottom" id="Message" order="0" />
317
       <window_info anchor="bottom" id="Message" order="0" />
269
       <window_info anchor="bottom" id="Find" order="1" />
318
       <window_info anchor="bottom" id="Find" order="1" />
270
-      <window_info anchor="bottom" id="Run" order="2" weight="0.32867134" />
319
+      <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32867134" />
271
       <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
320
       <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
272
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
321
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
273
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
322
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
294
       <breakpoints>
343
       <breakpoints>
295
         <line-breakpoint enabled="true" type="java-method">
344
         <line-breakpoint enabled="true" type="java-method">
296
           <url>file://$PROJECT_DIR$/src/main/java/MyArrayList.java</url>
345
           <url>file://$PROJECT_DIR$/src/main/java/MyArrayList.java</url>
297
-          <line>20</line>
346
+          <line>26</line>
298
           <properties class="MyArrayList" method="add">
347
           <properties class="MyArrayList" method="add">
299
             <option name="EMULATED" value="true" />
348
             <option name="EMULATED" value="true" />
300
           </properties>
349
           </properties>
301
-          <option name="timeStamp" value="1" />
350
+          <option name="timeStamp" value="3" />
302
         </line-breakpoint>
351
         </line-breakpoint>
303
       </breakpoints>
352
       </breakpoints>
304
     </breakpoint-manager>
353
     </breakpoint-manager>
307
     <entry file="file://$PROJECT_DIR$/.gitignore">
356
     <entry file="file://$PROJECT_DIR$/.gitignore">
308
       <provider selected="true" editor-type-id="text-editor" />
357
       <provider selected="true" editor-type-id="text-editor" />
309
     </entry>
358
     </entry>
310
-    <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
359
+    <entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/src.zip!/java/lang/Object.java">
311
       <provider selected="true" editor-type-id="text-editor">
360
       <provider selected="true" editor-type-id="text-editor">
312
-        <state relative-caret-position="360">
313
-          <caret line="26" column="13" lean-forward="true" selection-start-line="26" selection-start-column="13" selection-end-line="26" selection-end-column="13" />
314
-          <folding>
315
-            <element signature="e#338#339#0" expanded="true" />
316
-            <element signature="e#372#373#0" expanded="true" />
317
-          </folding>
361
+        <state relative-caret-position="151">
362
+          <caret line="36" column="13" selection-start-line="36" selection-start-column="13" selection-end-line="36" selection-end-column="13" />
363
+        </state>
364
+      </provider>
365
+    </entry>
366
+    <entry file="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/org/junit/internal/runners/model/ReflectiveCallable.class">
367
+      <provider selected="true" editor-type-id="text-editor">
368
+        <state relative-caret-position="195">
369
+          <caret line="16" selection-start-line="16" selection-end-line="16" />
318
         </state>
370
         </state>
319
       </provider>
371
       </provider>
320
     </entry>
372
     </entry>
321
     <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
373
     <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
322
       <provider selected="true" editor-type-id="text-editor">
374
       <provider selected="true" editor-type-id="text-editor">
323
-        <state relative-caret-position="465">
324
-          <caret line="31" column="44" selection-start-line="31" selection-start-column="44" selection-end-line="31" selection-end-column="44" />
375
+        <state relative-caret-position="-7">
376
+          <caret line="134" column="23" lean-forward="true" selection-start-line="134" selection-start-column="23" selection-end-line="134" selection-end-column="23" />
325
           <folding>
377
           <folding>
326
             <element signature="imports" expanded="true" />
378
             <element signature="imports" expanded="true" />
327
             <element signature="e#143#144#0" expanded="true" />
379
             <element signature="e#143#144#0" expanded="true" />
330
         </state>
382
         </state>
331
       </provider>
383
       </provider>
332
     </entry>
384
     </entry>
385
+    <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
386
+      <provider selected="true" editor-type-id="text-editor">
387
+        <state relative-caret-position="332">
388
+          <caret line="71" selection-start-line="71" selection-end-line="71" />
389
+          <folding>
390
+            <element signature="e#729#730#0" expanded="true" />
391
+            <element signature="e#763#764#0" expanded="true" />
392
+            <element signature="e#1365#1366#0" expanded="true" />
393
+            <element signature="e#1399#1400#0" expanded="true" />
394
+            <element signature="e#1433#1434#0" expanded="true" />
395
+            <element signature="e#1464#1465#0" expanded="true" />
396
+          </folding>
397
+        </state>
398
+      </provider>
399
+    </entry>
333
   </component>
400
   </component>
334
   <component name="masterDetails">
401
   <component name="masterDetails">
335
     <states>
402
     <states>

+ 46
- 4
src/main/java/MyArrayList.java Visa fil

1
 import java.util.Arrays;
1
 import java.util.Arrays;
2
 
2
 
3
-public class MyArrayList {
3
+
4
+public class MyArrayList<T> {
4
     private static final int INITIAL_SIZE = 0;
5
     private static final int INITIAL_SIZE = 0;
5
     private Object[] list;
6
     private Object[] list;
6
     private int size;
7
     private int size;
20
 
21
 
21
     public boolean add(Object o) {
22
     public boolean add(Object o) {
22
         list = Arrays.copyOf(list, list.length + 1);
23
         list = Arrays.copyOf(list, list.length + 1);
23
-        for (int i = 0; i < list.length - 1 ; i++) {
24
-            if (i == list.length - 1){
24
+        list[list.length - 1] = o;
25
+        return true;
26
+    }
27
+    public void add(T o, int index) {
28
+        list = Arrays.copyOf(list, list.length + 1);
29
+        System.arraycopy(list, index, list, index + 1, size - index);
30
+        list[index] = o;
31
+    }
32
+
33
+    public Object get(int index) {
34
+        return list[index];
35
+    }
36
+
37
+    public void remove(T o) {
38
+        Object[] tempArray = new Object[list.length];
39
+        int newIdx = 0;
40
+        for (int i = 0; i < list.length; i++) {
41
+            if (list[i] != o) {
42
+                tempArray[newIdx] = list[i];
43
+                newIdx++;
44
+            }
45
+        }
46
+        list = Arrays.copyOf(tempArray, list.length - 1);
47
+    }
48
+
49
+    public void set(T o, int index) {
50
+        for (int i = 0; i < list.length; i++) {
51
+            if(i == index) {
25
                 list[i] = o;
52
                 list[i] = o;
26
-                return true;
27
             }
53
             }
28
         }
54
         }
55
+    }
56
+
57
+    public void clear() {
58
+        list = new Object[0];
59
+    }
60
+
61
+    public boolean isEmpty() {
62
+        return size == 0;
63
+    }
64
+
65
+    public boolean contains(T o) {
66
+        for (Object each: list) {
67
+            if (each.equals(o)) { return true; }
68
+        }
29
         return false;
69
         return false;
30
     }
70
     }
71
+
72
+
31
 }
73
 }

+ 148
- 2
src/test/java/MyArrayListTest.java Visa fil

10
         list = new MyArrayList();
10
         list = new MyArrayList();
11
     }
11
     }
12
 
12
 
13
+
14
+    @Test
15
+    public void sizeNoElementsTest() {
16
+        int expected = 0;
17
+        int actual = list.size();
18
+
19
+        Assert.assertEquals(expected, actual);
20
+    }
21
+
13
     @Test
22
     @Test
14
     public void sizeAddTest() {
23
     public void sizeAddTest() {
15
         Integer add1 = 5;
24
         Integer add1 = 5;
23
         Assert.assertEquals(expected, actual);
32
         Assert.assertEquals(expected, actual);
24
 
33
 
25
     }
34
     }
35
+    @Test
36
+    public void addCharTest() {
37
+        Character add1 = 'f';
38
+        Character add2 = 'u';
39
+        list.add(add1);
40
+        list.add(add2);
26
 
41
 
42
+        int expected = 2;
43
+        int actual = list.size();
44
+
45
+        Assert.assertEquals(expected, actual);
46
+    }
27
     @Test
47
     @Test
28
-    public void sizeNoElementsTest() {
29
-        int expected = 0;
48
+    public void addStringTest() {
49
+        String add1 = "Wilhem";
50
+        String add2 = "Nhu";
51
+        list.add(add1);
52
+        list.add(add2);
53
+
54
+        int expected = 2;
55
+        int actual =list.size();
56
+
57
+        Assert.assertEquals(expected, actual);
58
+    }
59
+    @Test
60
+    public void addDoubleTest() {
61
+        Double add1 = 10.0;
62
+        Double add2 = 56.8;
63
+        list.add(add1);
64
+        list.add(add2);
65
+
66
+        int expected = 2;
67
+        int actual =list.size();
68
+
69
+        Assert.assertEquals(expected, actual);
70
+    }
71
+
72
+
73
+    @Test
74
+    public void addAtIndexTest() {
75
+        Character add1 = 'f';
76
+        Character add2 = 'u';
77
+        Character add3 = 'b';
78
+        list.add(add1);
79
+        list.add(add2);
80
+        list.add(add3, 1);
81
+
82
+        Character expected = 'b';
83
+        Object actual = list.get(1);
84
+
85
+        Assert.assertEquals(expected, actual);
86
+
87
+    }
88
+
89
+    @Test
90
+    public void removeTest() {
91
+        String add1 = "Wilhem";
92
+        String add2 = "Nhu";
93
+        list.add(add1);
94
+        list.add(add2);
95
+
96
+        int expected = 1;
97
+        list.remove("Wilhem");
30
         int actual = list.size();
98
         int actual = list.size();
31
 
99
 
32
         Assert.assertEquals(expected, actual);
100
         Assert.assertEquals(expected, actual);
33
     }
101
     }
102
+
103
+    @Test
104
+    public void removeInt() {
105
+        Integer add1 = 5;
106
+        Integer add2 = 6;
107
+        list.add(add1);
108
+        list.add(add2);
109
+
110
+        int expected = 1;
111
+        list.remove(6);
112
+        int actual = list.size();
113
+
114
+        Assert.assertEquals(expected, actual);
115
+    }
116
+
117
+    @Test
118
+    public void setTest() {
119
+        String add1 = "Wilhem";
120
+        String add2 = "Nhu";
121
+        list.add(add1);
122
+        list.add(add2);
123
+
124
+        String expected = "Leon";
125
+        list.set("Leon", 1);
126
+        Object actual = list.get(1);
127
+        Assert.assertEquals(expected, actual);
128
+    }
129
+
130
+    @Test
131
+    public void clearTest() {
132
+        Character add1 = 'f';
133
+        Character add2 = 'u';
134
+        Character add3 = 'b';
135
+        list.add(add1);
136
+        list.add(add2);
137
+        list.add(add3);
138
+
139
+        int expected = 0;
140
+        list.clear();
141
+        int actual  = list.size();
142
+
143
+        Assert.assertEquals(expected, actual);
144
+    }
145
+
146
+    @Test
147
+    public void isEmptyTest() {
148
+        list.clear();
149
+        boolean actual = list.isEmpty();
150
+
151
+        Assert.assertTrue(actual);
152
+    }
153
+
154
+    @Test
155
+    public void contains() {
156
+        Integer add1 = 5;
157
+        Integer add2 = 6;
158
+        list.add(add1);
159
+        list.add(add2);
160
+
161
+        boolean expected = true;
162
+        boolean actual = list.contains(5);
163
+
164
+        Assert.assertEquals(expected, actual);
165
+    }
166
+
167
+    @Test
168
+    public void containsNotThere() {
169
+        String add1 = "Wilhem";
170
+        String add2 = "Nhu";
171
+        list.add(add1);
172
+        list.add(add2);
173
+
174
+        boolean expeted = false;
175
+        boolean actual = list.contains("Kris");
176
+
177
+        Assert.assertFalse(actual);
178
+    }
179
+
34
 }
180
 }