nafis nibir 6 vuotta sitten
vanhempi
commit
444a2043fd
3 muutettua tiedostoa jossa 127 lisäystä ja 56 poistoa
  1. 73
    54
      .idea/workspace.xml
  2. 42
    0
      src/main/java/MyArrayList.java
  3. 12
    2
      src/test/java/MyArrayListTest.java

+ 73
- 54
.idea/workspace.xml Näytä tiedosto

@@ -2,11 +2,8 @@
2 2
 <project version="4">
3 3
   <component name="ChangeListManager">
4 4
     <list default="true" id="3963277c-7c3f-43f5-81ec-6d260afd1592" name="Default" 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$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
8
-      <change beforePath="$PROJECT_DIR$/src/main/java/.deleteme" beforeDir="false" />
9
-      <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" />
10 7
     </list>
11 8
     <ignored path="$PROJECT_DIR$/target/" />
12 9
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -23,11 +20,12 @@
23 20
           <file leaf-file-name="MyArrayList.java" pinned="false" current-in-tab="true">
24 21
             <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
25 22
               <provider selected="true" editor-type-id="text-editor">
26
-                <state relative-caret-position="427">
27
-                  <caret line="36" column="25" lean-forward="true" selection-start-line="36" selection-start-column="25" selection-end-line="36" selection-end-column="25" />
23
+                <state relative-caret-position="492">
24
+                  <caret line="76" column="25" selection-start-line="76" selection-start-column="25" selection-end-line="76" selection-end-column="25" />
28 25
                   <folding>
29 26
                     <element signature="imports" expanded="true" />
30
-                    <element signature="e#822#823#0" expanded="true" />
27
+                    <element signature="e#1164#1165#0" expanded="true" />
28
+                    <element signature="e#1200#1201#0" expanded="true" />
31 29
                   </folding>
32 30
                 </state>
33 31
               </provider>
@@ -36,8 +34,8 @@
36 34
           <file leaf-file-name="ArrayList.java" pinned="false" current-in-tab="false">
37 35
             <entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/src.zip!/java/util/ArrayList.java">
38 36
               <provider selected="true" editor-type-id="text-editor">
39
-                <state relative-caret-position="-2">
40
-                  <caret line="222" column="15" selection-start-line="222" selection-start-column="15" selection-end-line="222" selection-end-column="15" />
37
+                <state relative-caret-position="4307">
38
+                  <caret line="529" column="16" lean-forward="true" selection-start-line="529" selection-start-column="16" selection-end-line="529" selection-end-column="16" />
41 39
                 </state>
42 40
               </provider>
43 41
             </entry>
@@ -49,8 +47,8 @@
49 47
           <file leaf-file-name="MyArrayListTest.java" pinned="false" current-in-tab="true">
50 48
             <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
51 49
               <provider selected="true" editor-type-id="text-editor">
52
-                <state relative-caret-position="331">
53
-                  <caret line="48" column="20" selection-start-line="48" selection-start-column="20" selection-end-line="48" selection-end-column="20" />
50
+                <state relative-caret-position="569">
51
+                  <caret line="73" lean-forward="true" selection-start-line="73" selection-end-line="73" />
54 52
                   <folding>
55 53
                     <element signature="imports" expanded="true" />
56 54
                     <element signature="e#184#193#0" expanded="true" />
@@ -70,6 +68,11 @@
70 68
       </list>
71 69
     </option>
72 70
   </component>
71
+  <component name="FindInProjectRecents">
72
+    <findStrings>
73
+      <find>remove</find>
74
+    </findStrings>
75
+  </component>
73 76
   <component name="Git.Settings">
74 77
     <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
75 78
   </component>
@@ -179,17 +182,17 @@
179 182
       </list>
180 183
     </option>
181 184
   </component>
182
-  <component name="RunManager" selected="JUnit.MyArrayListTest.get2Test">
185
+  <component name="RunManager" selected="JUnit.MyArrayListTest.setTest">
183 186
     <configuration default="true" type="Application" factoryName="Application">
184 187
       <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
185 188
     </configuration>
186
-    <configuration name="MyArrayListTest.add1Test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
189
+    <configuration name="MyArrayListTest.get1Test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
187 190
       <module name="generics" />
188 191
       <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
189 192
       <option name="ALTERNATIVE_JRE_PATH" />
190 193
       <option name="PACKAGE_NAME" value="" />
191 194
       <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
192
-      <option name="METHOD_NAME" value="add1Test" />
195
+      <option name="METHOD_NAME" value="get1Test" />
193 196
       <option name="TEST_OBJECT" value="method" />
194 197
       <option name="VM_PARAMETERS" value="-ea" />
195 198
       <option name="PARAMETERS" />
@@ -200,13 +203,13 @@
200 203
       </option>
201 204
       <patterns />
202 205
     </configuration>
203
-    <configuration name="MyArrayListTest.addTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
206
+    <configuration name="MyArrayListTest.get2Test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
204 207
       <module name="generics" />
205 208
       <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
206 209
       <option name="ALTERNATIVE_JRE_PATH" />
207 210
       <option name="PACKAGE_NAME" value="" />
208 211
       <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
209
-      <option name="METHOD_NAME" value="addTest" />
212
+      <option name="METHOD_NAME" value="get2Test" />
210 213
       <option name="TEST_OBJECT" value="method" />
211 214
       <option name="VM_PARAMETERS" value="-ea" />
212 215
       <option name="PARAMETERS" />
@@ -217,13 +220,13 @@
217 220
       </option>
218 221
       <patterns />
219 222
     </configuration>
220
-    <configuration name="MyArrayListTest.get1Test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
223
+    <configuration name="MyArrayListTest.getTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
221 224
       <module name="generics" />
222 225
       <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
223 226
       <option name="ALTERNATIVE_JRE_PATH" />
224 227
       <option name="PACKAGE_NAME" value="" />
225 228
       <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
226
-      <option name="METHOD_NAME" value="get1Test" />
229
+      <option name="METHOD_NAME" value="getTest" />
227 230
       <option name="TEST_OBJECT" value="method" />
228 231
       <option name="VM_PARAMETERS" value="-ea" />
229 232
       <option name="PARAMETERS" />
@@ -234,13 +237,13 @@
234 237
       </option>
235 238
       <patterns />
236 239
     </configuration>
237
-    <configuration name="MyArrayListTest.get2Test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
240
+    <configuration name="MyArrayListTest.removeTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
238 241
       <module name="generics" />
239 242
       <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
240 243
       <option name="ALTERNATIVE_JRE_PATH" />
241 244
       <option name="PACKAGE_NAME" value="" />
242 245
       <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
243
-      <option name="METHOD_NAME" value="get2Test" />
246
+      <option name="METHOD_NAME" value="removeTest" />
244 247
       <option name="TEST_OBJECT" value="method" />
245 248
       <option name="VM_PARAMETERS" value="-ea" />
246 249
       <option name="PARAMETERS" />
@@ -251,13 +254,13 @@
251 254
       </option>
252 255
       <patterns />
253 256
     </configuration>
254
-    <configuration name="MyArrayListTest.getTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
257
+    <configuration name="MyArrayListTest.setTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
255 258
       <module name="generics" />
256 259
       <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
257 260
       <option name="ALTERNATIVE_JRE_PATH" />
258 261
       <option name="PACKAGE_NAME" value="" />
259 262
       <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
260
-      <option name="METHOD_NAME" value="getTest" />
263
+      <option name="METHOD_NAME" value="setTest" />
261 264
       <option name="TEST_OBJECT" value="method" />
262 265
       <option name="VM_PARAMETERS" value="-ea" />
263 266
       <option name="PARAMETERS" />
@@ -307,19 +310,19 @@
307 310
       <listeners />
308 311
     </configuration>
309 312
     <list>
310
-      <item itemvalue="JUnit.MyArrayListTest.addTest" />
311
-      <item itemvalue="JUnit.MyArrayListTest.add1Test" />
312 313
       <item itemvalue="JUnit.MyArrayListTest.getTest" />
313 314
       <item itemvalue="JUnit.MyArrayListTest.get1Test" />
314 315
       <item itemvalue="JUnit.MyArrayListTest.get2Test" />
316
+      <item itemvalue="JUnit.MyArrayListTest.removeTest" />
317
+      <item itemvalue="JUnit.MyArrayListTest.setTest" />
315 318
     </list>
316 319
     <recent_temporary>
317 320
       <list>
321
+        <item itemvalue="JUnit.MyArrayListTest.setTest" />
322
+        <item itemvalue="JUnit.MyArrayListTest.removeTest" />
318 323
         <item itemvalue="JUnit.MyArrayListTest.get2Test" />
319 324
         <item itemvalue="JUnit.MyArrayListTest.get1Test" />
320 325
         <item itemvalue="JUnit.MyArrayListTest.getTest" />
321
-        <item itemvalue="JUnit.MyArrayListTest.add1Test" />
322
-        <item itemvalue="JUnit.MyArrayListTest.addTest" />
323 326
       </list>
324 327
     </recent_temporary>
325 328
   </component>
@@ -334,26 +337,11 @@
334 337
       <option name="presentableId" value="Default" />
335 338
       <updated>1530106571709</updated>
336 339
       <workItem from="1530106581652" duration="58000" />
337
-      <workItem from="1530122909636" duration="7331000" />
340
+      <workItem from="1530122909636" duration="10967000" />
338 341
     </task>
339 342
     <servers />
340 343
   </component>
341 344
   <component name="TestHistory">
342
-    <history-entry file="MyArrayListTest_addTest - 2018.06.27 at 15h 18m 29s.xml">
343
-      <configuration name="MyArrayListTest.addTest" configurationId="JUnit" />
344
-    </history-entry>
345
-    <history-entry file="MyArrayListTest_addTest - 2018.06.27 at 15h 27m 44s.xml">
346
-      <configuration name="MyArrayListTest.addTest" configurationId="JUnit" />
347
-    </history-entry>
348
-    <history-entry file="MyArrayListTest_addTest - 2018.06.27 at 16h 19m 58s.xml">
349
-      <configuration name="MyArrayListTest.addTest" configurationId="JUnit" />
350
-    </history-entry>
351
-    <history-entry file="MyArrayListTest_addTest - 2018.06.27 at 16h 20m 02s.xml">
352
-      <configuration name="MyArrayListTest.addTest" configurationId="JUnit" />
353
-    </history-entry>
354
-    <history-entry file="MyArrayListTest_addTest - 2018.06.27 at 16h 20m 06s.xml">
355
-      <configuration name="MyArrayListTest.addTest" configurationId="JUnit" />
356
-    </history-entry>
357 345
     <history-entry file="MyArrayListTest_add1Test - 2018.06.27 at 16h 22m 27s.xml">
358 346
       <configuration name="MyArrayListTest.add1Test" configurationId="JUnit" />
359 347
     </history-entry>
@@ -369,9 +357,24 @@
369 357
     <history-entry file="MyArrayListTest_get1Test - 2018.06.27 at 16h 40m 04s.xml">
370 358
       <configuration name="MyArrayListTest.get1Test" configurationId="JUnit" />
371 359
     </history-entry>
360
+    <history-entry file="MyArrayListTest_get2Test - 2018.06.27 at 16h 42m 41s.xml">
361
+      <configuration name="MyArrayListTest.get2Test" configurationId="JUnit" />
362
+    </history-entry>
363
+    <history-entry file="MyArrayListTest_get2Test - 2018.06.27 at 16h 45m 56s.xml">
364
+      <configuration name="MyArrayListTest.get2Test" configurationId="JUnit" />
365
+    </history-entry>
366
+    <history-entry file="MyArrayListTest_removeTest - 2018.06.27 at 17h 07m 04s.xml">
367
+      <configuration name="MyArrayListTest.removeTest" configurationId="JUnit" />
368
+    </history-entry>
369
+    <history-entry file="MyArrayListTest_removeTest - 2018.06.27 at 17h 11m 14s.xml">
370
+      <configuration name="MyArrayListTest.removeTest" configurationId="JUnit" />
371
+    </history-entry>
372
+    <history-entry file="MyArrayListTest_removeTest - 2018.06.27 at 17h 11m 25s.xml">
373
+      <configuration name="MyArrayListTest.removeTest" configurationId="JUnit" />
374
+    </history-entry>
372 375
   </component>
373 376
   <component name="TimeTrackingManager">
374
-    <option name="totallyTimeSpent" value="7389000" />
377
+    <option name="totallyTimeSpent" value="11025000" />
375 378
   </component>
376 379
   <component name="ToolWindowManager">
377 380
     <frame x="-208" y="-927" width="1881" height="941" extended-state="0" />
@@ -386,9 +389,9 @@
386 389
       <window_info anchor="bottom" id="Event Log" order="7" side_tool="true" />
387 390
       <window_info anchor="right" id="Maven Projects" order="3" />
388 391
       <window_info anchor="bottom" id="Database Changes" order="7" show_stripe_button="false" />
389
-      <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32886723" />
392
+      <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.12423874" />
390 393
       <window_info anchor="bottom" id="Version Control" order="7" />
391
-      <window_info anchor="bottom" id="Terminal" order="7" />
394
+      <window_info anchor="bottom" id="Terminal" order="7" weight="0.32886723" />
392 395
       <window_info id="Capture Tool" order="2" />
393 396
       <window_info id="Designer" order="2" />
394 397
       <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.23327896" />
@@ -397,7 +400,7 @@
397 400
       <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
398 401
       <window_info id="UI Designer" order="2" />
399 402
       <window_info anchor="right" id="Theme Preview" order="3" />
400
-      <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
403
+      <window_info anchor="bottom" id="Debug" order="3" weight="0.3995128" />
401 404
       <window_info id="Favorites" order="2" side_tool="true" />
402 405
       <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
403 406
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@@ -413,29 +416,45 @@
413 416
   <component name="VcsContentAnnotationSettings">
414 417
     <option name="myLimit" value="2678400000" />
415 418
   </component>
419
+  <component name="XDebuggerManager">
420
+    <breakpoint-manager>
421
+      <option name="time" value="1" />
422
+    </breakpoint-manager>
423
+  </component>
416 424
   <component name="editorHistoryManager">
425
+    <entry file="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/org/junit/Assert.class">
426
+      <provider selected="true" editor-type-id="text-editor">
427
+        <state relative-caret-position="151">
428
+          <caret line="236" selection-start-line="236" selection-end-line="236" />
429
+          <folding>
430
+            <element signature="e#8383#8384#0" expanded="true" />
431
+          </folding>
432
+        </state>
433
+      </provider>
434
+    </entry>
417 435
     <entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/src.zip!/java/util/ArrayList.java">
418 436
       <provider selected="true" editor-type-id="text-editor">
419
-        <state relative-caret-position="-2">
420
-          <caret line="222" column="15" selection-start-line="222" selection-start-column="15" selection-end-line="222" selection-end-column="15" />
437
+        <state relative-caret-position="4307">
438
+          <caret line="529" column="16" lean-forward="true" selection-start-line="529" selection-start-column="16" selection-end-line="529" selection-end-column="16" />
421 439
         </state>
422 440
       </provider>
423 441
     </entry>
424 442
     <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
425 443
       <provider selected="true" editor-type-id="text-editor">
426
-        <state relative-caret-position="427">
427
-          <caret line="36" column="25" lean-forward="true" selection-start-line="36" selection-start-column="25" selection-end-line="36" selection-end-column="25" />
444
+        <state relative-caret-position="492">
445
+          <caret line="76" column="25" selection-start-line="76" selection-start-column="25" selection-end-line="76" selection-end-column="25" />
428 446
           <folding>
429 447
             <element signature="imports" expanded="true" />
430
-            <element signature="e#822#823#0" expanded="true" />
448
+            <element signature="e#1164#1165#0" expanded="true" />
449
+            <element signature="e#1200#1201#0" expanded="true" />
431 450
           </folding>
432 451
         </state>
433 452
       </provider>
434 453
     </entry>
435 454
     <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
436 455
       <provider selected="true" editor-type-id="text-editor">
437
-        <state relative-caret-position="331">
438
-          <caret line="48" column="20" selection-start-line="48" selection-start-column="20" selection-end-line="48" selection-end-column="20" />
456
+        <state relative-caret-position="569">
457
+          <caret line="73" lean-forward="true" selection-start-line="73" selection-end-line="73" />
439 458
           <folding>
440 459
             <element signature="imports" expanded="true" />
441 460
             <element signature="e#184#193#0" expanded="true" />

+ 42
- 0
src/main/java/MyArrayList.java Näytä tiedosto

@@ -23,7 +23,17 @@ public class MyArrayList <T>{
23 23
 
24 24
     public void checkCurrentCap(){
25 25
         if (!(element[element.length-1] == null)){
26
+            Object[] temp = element;
26 27
             element = new Object[element.length*2];
28
+            arrCopy(element, temp);
29
+        }
30
+    }
31
+
32
+    public void arrCopy(Object[] arrTo, Object[] arrFrom){
33
+        int index = 0;
34
+        for(Object o: arrFrom){
35
+            arrTo[index] = o;
36
+            index++;
27 37
         }
28 38
     }
29 39
 
@@ -34,7 +44,39 @@ public class MyArrayList <T>{
34 44
         return (int) size;
35 45
     }
36 46
 
47
+    public void trimArray(){
48
+        Object[] trimmed = Arrays.stream(element)
49
+                                 .filter((s->(s!=null)))
50
+                                 .toArray();
51
+        element = trimmed;
52
+    }
53
+
37 54
     public T get(int i) {
38 55
         return (T)element[i];
39 56
     }
57
+
58
+    public void remove(T i) {
59
+        int index = 0;
60
+        for(Object e: element){
61
+            if(e.equals(i)){
62
+                element[index] = null;
63
+                break;
64
+            }
65
+            index++;
66
+        }
67
+        trimArray();
68
+    }
69
+
70
+    public void set(int i, T thing) {
71
+        if(i > element.length-1){
72
+            arrayExpander(i);
73
+        }
74
+        this.element[i] = thing;
75
+    }
76
+
77
+    public void arrayExpander(int i){
78
+        Object[] temp = element;
79
+        element = new Object[element.length+i];
80
+        arrCopy(element, temp);
81
+    }
40 82
 }

+ 12
- 2
src/test/java/MyArrayListTest.java Näytä tiedosto

@@ -54,12 +54,22 @@ public class MyArrayListTest {
54 54
 
55 55
     @Test
56 56
     public void removeTest(){
57
-
57
+        MyArrayList<Integer> myArrayList = new MyArrayList<>();
58
+        myArrayList.add(2);
59
+        myArrayList.add(1);
60
+        myArrayList.remove(2);
61
+        int expected = 1;
62
+        int actual = myArrayList.size();
63
+        Assert.assertEquals(expected, actual);
58 64
     }
59 65
 
60 66
     @Test
61 67
     public void setTest(){
62
-
68
+        MyArrayList<String> myArrayList = new MyArrayList<>();
69
+        myArrayList.set(1, "dog");
70
+        String expected = "dog";
71
+        String actual = myArrayList.get(1);
72
+        Assert.assertEquals(expected, actual);
63 73
     }
64 74
 
65 75
     @Test