浏览代码

{finished MyArrayList}

Jacqueline Joson 6 年前
父节点
当前提交
ffd3afe2ac
共有 4 个文件被更改,包括 104 次插入52 次删除
  1. 83
    41
      .idea/workspace.xml
  2. 16
    9
      src/main/java/MyArrayList.java
  3. 3
    0
      src/main/java/MySet.java
  4. 2
    2
      src/test/java/MyArrayListTest.java

+ 83
- 41
.idea/workspace.xml 查看文件

@@ -25,30 +25,30 @@
25 25
           <entry key="JAVA/" value="2" />
26 26
           <entry key="JAVA/MyArrayList" value="1" />
27 27
           <entry key="MODULES/mdl-generics" value="1" />
28
-          <entry key="class" value="3" />
28
+          <entry key="class" value="4" />
29 29
           <entry key="iml" value="1" />
30
-          <entry key="java" value="2" />
30
+          <entry key="java" value="3" />
31 31
           <entry key="md" value="1" />
32 32
         </counts>
33 33
       </usages-collector>
34 34
       <usages-collector id="statistics.file.types.open">
35 35
         <counts>
36
-          <entry key="CLASS" value="3" />
36
+          <entry key="CLASS" value="4" />
37 37
           <entry key="IDEA_MODULE" value="1" />
38
-          <entry key="JAVA" value="2" />
38
+          <entry key="JAVA" value="3" />
39 39
           <entry key="Markdown" value="1" />
40 40
           <entry key="UML" value="4" />
41 41
         </counts>
42 42
       </usages-collector>
43 43
       <usages-collector id="statistics.file.extensions.edit">
44 44
         <counts>
45
-          <entry key="java" value="3930" />
45
+          <entry key="java" value="4322" />
46 46
           <entry key="txt" value="59" />
47 47
         </counts>
48 48
       </usages-collector>
49 49
       <usages-collector id="statistics.file.types.edit">
50 50
         <counts>
51
-          <entry key="JAVA" value="3930" />
51
+          <entry key="JAVA" value="4322" />
52 52
           <entry key="PLAIN_TEXT" value="59" />
53 53
         </counts>
54 54
       </usages-collector>
@@ -69,8 +69,8 @@
69 69
       <file pinned="false" current-in-tab="false">
70 70
         <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
71 71
           <provider selected="true" editor-type-id="text-editor">
72
-            <state relative-caret-position="217">
73
-              <caret line="78" column="13" lean-forward="true" selection-start-line="78" selection-start-column="13" selection-end-line="78" selection-end-column="13" />
72
+            <state relative-caret-position="335">
73
+              <caret line="89" lean-forward="true" selection-start-line="89" selection-end-line="89" />
74 74
               <folding>
75 75
                 <element signature="e#67#68#0" expanded="true" />
76 76
                 <element signature="e#107#108#0" expanded="true" />
@@ -83,11 +83,20 @@
83 83
           </provider>
84 84
         </entry>
85 85
       </file>
86
+      <file pinned="false" current-in-tab="false">
87
+        <entry file="file://$PROJECT_DIR$/src/main/java/MySet.java">
88
+          <provider selected="true" editor-type-id="text-editor">
89
+            <state relative-caret-position="17">
90
+              <caret line="1" lean-forward="true" selection-start-line="1" selection-end-line="1" />
91
+            </state>
92
+          </provider>
93
+        </entry>
94
+      </file>
86 95
       <file pinned="false" current-in-tab="true">
87 96
         <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
88 97
           <provider selected="true" editor-type-id="text-editor">
89
-            <state relative-caret-position="254">
90
-              <caret line="134" column="40" lean-forward="true" selection-start-line="134" selection-start-column="40" selection-end-line="134" selection-end-column="40" />
98
+            <state relative-caret-position="148">
99
+              <caret line="129" column="82" lean-forward="true" selection-start-line="129" selection-start-column="82" selection-end-line="129" selection-end-column="82" />
91 100
               <folding>
92 101
                 <element signature="imports" expanded="true" />
93 102
                 <element signature="e#282#291#0" expanded="true" />
@@ -126,8 +135,8 @@
126 135
   <component name="FileTemplateManagerImpl">
127 136
     <option name="RECENT_TEMPLATES">
128 137
       <list>
129
-        <option value="Class" />
130 138
         <option value="JUnit4 Test Class" />
139
+        <option value="Class" />
131 140
       </list>
132 141
     </option>
133 142
   </component>
@@ -137,8 +146,9 @@
137 146
   <component name="IdeDocumentHistory">
138 147
     <option name="CHANGED_PATHS">
139 148
       <list>
140
-        <option value="$PROJECT_DIR$/src/main/java/MyArrayList.java" />
149
+        <option value="$PROJECT_DIR$/src/main/java/MySet.java" />
141 150
         <option value="$PROJECT_DIR$/src/test/java/MyArrayListTest.java" />
151
+        <option value="$PROJECT_DIR$/src/main/java/MyArrayList.java" />
142 152
       </list>
143 153
     </option>
144 154
   </component>
@@ -212,7 +222,7 @@
212 222
   <component name="PropertiesComponent">
213 223
     <property name="WebServerToolWindowFactoryState" value="false" />
214 224
     <property name="aspect.path.notification.shown" value="true" />
215
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542340110766" />
225
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542386512999" />
216 226
     <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrary" value="JUnit4" />
217 227
     <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrarySuperClass.JUnit4" value="" />
218 228
     <property name="last_opened_file_path" value="$PROJECT_DIR$/pom.xml" />
@@ -243,7 +253,7 @@
243 253
       </list>
244 254
     </option>
245 255
   </component>
246
-  <component name="RunManager" selected="JUnit.MyArrayListTest.addOverrideTest">
256
+  <component name="RunManager" selected="JUnit.MyArrayListTest">
247 257
     <configuration name="MyArrayListTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
248 258
       <module name="generics" />
249 259
       <option name="PACKAGE_NAME" value="" />
@@ -301,10 +311,10 @@
301 311
     </list>
302 312
     <recent_temporary>
303 313
       <list>
314
+        <item itemvalue="JUnit.MyArrayListTest" />
304 315
         <item itemvalue="JUnit.MyArrayListTest.addOverrideTest" />
305 316
         <item itemvalue="JUnit.MyArrayListTest.containsFalseTest" />
306 317
         <item itemvalue="JUnit.MyArrayListTest.containsTest" />
307
-        <item itemvalue="JUnit.MyArrayListTest" />
308 318
         <item itemvalue="JUnit.MyArrayListTest.isEmptyTest" />
309 319
       </list>
310 320
     </recent_temporary>
@@ -319,44 +329,44 @@
319 329
       <option name="number" value="Default" />
320 330
       <option name="presentableId" value="Default" />
321 331
       <updated>1542236797011</updated>
322
-      <workItem from="1542236798436" duration="16476000" />
332
+      <workItem from="1542236798436" duration="20962000" />
323 333
     </task>
324 334
     <servers />
325 335
   </component>
326 336
   <component name="TestHistory">
327
-    <history-entry file="MyArrayListTest_setTest - 2018.11.15 at 18h 18m 10s.xml">
328
-      <configuration name="MyArrayListTest.setTest" configurationId="JUnit" />
337
+    <history-entry file="MyArrayListTest_addOverrideTest - 2018.11.16 at 08h 56m 05s.xml">
338
+      <configuration name="MyArrayListTest.addOverrideTest" configurationId="JUnit" />
329 339
     </history-entry>
330
-    <history-entry file="MyArrayListTest_setTest - 2018.11.15 at 18h 20m 58s.xml">
331
-      <configuration name="MyArrayListTest.setTest" configurationId="JUnit" />
340
+    <history-entry file="MyArrayListTest_addOverrideTest - 2018.11.16 at 08h 56m 16s.xml">
341
+      <configuration name="MyArrayListTest.addOverrideTest" configurationId="JUnit" />
332 342
     </history-entry>
333
-    <history-entry file="MyArrayListTest_setTest - 2018.11.15 at 18h 25m 09s.xml">
334
-      <configuration name="MyArrayListTest.setTest" configurationId="JUnit" />
343
+    <history-entry file="MyArrayListTest_addOverrideTest - 2018.11.16 at 08h 58m 50s.xml">
344
+      <configuration name="MyArrayListTest.addOverrideTest" configurationId="JUnit" />
335 345
     </history-entry>
336
-    <history-entry file="MyArrayListTest_clearTest - 2018.11.15 at 18h 33m 46s.xml">
337
-      <configuration name="MyArrayListTest.clearTest" configurationId="JUnit" />
346
+    <history-entry file="MyArrayListTest_addOverrideTest - 2018.11.16 at 10h 57m 57s.xml">
347
+      <configuration name="MyArrayListTest.addOverrideTest" configurationId="JUnit" />
338 348
     </history-entry>
339
-    <history-entry file="MyArrayListTest_clearTest - 2018.11.15 at 18h 34m 39s.xml">
340
-      <configuration name="MyArrayListTest.clearTest" configurationId="JUnit" />
349
+    <history-entry file="MyArrayListTest_addOverrideTest - 2018.11.16 at 10h 58m 04s.xml">
350
+      <configuration name="MyArrayListTest.addOverrideTest" configurationId="JUnit" />
341 351
     </history-entry>
342
-    <history-entry file="MyArrayListTest - 2018.11.15 at 22h 13m 39s.xml">
343
-      <configuration name="MyArrayListTest" configurationId="JUnit" />
352
+    <history-entry file="MyArrayListTest_addOverrideTest - 2018.11.16 at 10h 59m 54s.xml">
353
+      <configuration name="MyArrayListTest.addOverrideTest" configurationId="JUnit" />
344 354
     </history-entry>
345
-    <history-entry file="MyArrayListTest_isEmptyTest - 2018.11.15 at 22h 21m 29s.xml">
346
-      <configuration name="MyArrayListTest.isEmptyTest" configurationId="JUnit" />
355
+    <history-entry file="MyArrayListTest_addOverrideTest - 2018.11.16 at 11h 00m 33s.xml">
356
+      <configuration name="MyArrayListTest.addOverrideTest" configurationId="JUnit" />
347 357
     </history-entry>
348
-    <history-entry file="MyArrayListTest - 2018.11.15 at 22h 23m 27s.xml">
349
-      <configuration name="MyArrayListTest" configurationId="JUnit" />
358
+    <history-entry file="MyArrayListTest_addOverrideTest - 2018.11.16 at 11h 02m 07s.xml">
359
+      <configuration name="MyArrayListTest.addOverrideTest" configurationId="JUnit" />
350 360
     </history-entry>
351
-    <history-entry file="MyArrayListTest_containsTest - 2018.11.15 at 22h 31m 02s.xml">
352
-      <configuration name="MyArrayListTest.containsTest" configurationId="JUnit" />
361
+    <history-entry file="MyArrayListTest_addOverrideTest - 2018.11.16 at 11h 02m 10s.xml">
362
+      <configuration name="MyArrayListTest.addOverrideTest" configurationId="JUnit" />
353 363
     </history-entry>
354
-    <history-entry file="MyArrayListTest_containsFalseTest - 2018.11.15 at 22h 31m 53s.xml">
355
-      <configuration name="MyArrayListTest.containsFalseTest" configurationId="JUnit" />
364
+    <history-entry file="MyArrayListTest_addOverrideTest - 2018.11.16 at 11h 35m 04s.xml">
365
+      <configuration name="MyArrayListTest.addOverrideTest" configurationId="JUnit" />
356 366
     </history-entry>
357 367
   </component>
358 368
   <component name="TimeTrackingManager">
359
-    <option name="totallyTimeSpent" value="16476000" />
369
+    <option name="totallyTimeSpent" value="20962000" />
360 370
   </component>
361 371
   <component name="ToolWindowManager">
362 372
     <frame x="0" y="23" width="1280" height="712" extended-state="0" />
@@ -398,6 +408,20 @@
398 408
   <component name="VcsContentAnnotationSettings">
399 409
     <option name="myLimit" value="2678400000" />
400 410
   </component>
411
+  <component name="XDebuggerManager">
412
+    <breakpoint-manager>
413
+      <breakpoints>
414
+        <line-breakpoint enabled="true" type="java-method">
415
+          <url>file://$PROJECT_DIR$/src/main/java/MyArrayList.java</url>
416
+          <line>71</line>
417
+          <properties class="MyArrayList" method="add">
418
+            <option name="EMULATED" value="true" />
419
+          </properties>
420
+          <option name="timeStamp" value="9" />
421
+        </line-breakpoint>
422
+      </breakpoints>
423
+    </breakpoint-manager>
424
+  </component>
401 425
   <component name="editorHistoryManager">
402 426
     <entry file="file://$PROJECT_DIR$/generics.iml">
403 427
       <provider selected="true" editor-type-id="text-editor" />
@@ -497,10 +521,28 @@
497 521
         </state>
498 522
       </provider>
499 523
     </entry>
524
+    <entry file="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/org/junit/Assert.class">
525
+      <provider selected="true" editor-type-id="text-editor">
526
+        <state relative-caret-position="94">
527
+          <caret line="333" selection-start-line="333" selection-end-line="333" />
528
+          <folding>
529
+            <element signature="e#8323#8324#0" expanded="true" />
530
+            <element signature="e#8383#8384#0" expanded="true" />
531
+          </folding>
532
+        </state>
533
+      </provider>
534
+    </entry>
535
+    <entry file="file://$PROJECT_DIR$/src/main/java/MySet.java">
536
+      <provider selected="true" editor-type-id="text-editor">
537
+        <state relative-caret-position="17">
538
+          <caret line="1" lean-forward="true" selection-start-line="1" selection-end-line="1" />
539
+        </state>
540
+      </provider>
541
+    </entry>
500 542
     <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
501 543
       <provider selected="true" editor-type-id="text-editor">
502
-        <state relative-caret-position="217">
503
-          <caret line="78" column="13" lean-forward="true" selection-start-line="78" selection-start-column="13" selection-end-line="78" selection-end-column="13" />
544
+        <state relative-caret-position="335">
545
+          <caret line="89" lean-forward="true" selection-start-line="89" selection-end-line="89" />
504 546
           <folding>
505 547
             <element signature="e#67#68#0" expanded="true" />
506 548
             <element signature="e#107#108#0" expanded="true" />
@@ -514,8 +556,8 @@
514 556
     </entry>
515 557
     <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
516 558
       <provider selected="true" editor-type-id="text-editor">
517
-        <state relative-caret-position="254">
518
-          <caret line="134" column="40" lean-forward="true" selection-start-line="134" selection-start-column="40" selection-end-line="134" selection-end-column="40" />
559
+        <state relative-caret-position="148">
560
+          <caret line="129" column="82" lean-forward="true" selection-start-line="129" selection-start-column="82" selection-end-line="129" selection-end-column="82" />
519 561
           <folding>
520 562
             <element signature="imports" expanded="true" />
521 563
             <element signature="e#282#291#0" expanded="true" />

+ 16
- 9
src/main/java/MyArrayList.java 查看文件

@@ -68,15 +68,22 @@ public class MyArrayList<T> {
68 68
            return theArray.length;
69 69
         }
70 70
 
71
-//        @Override
72
-//        public void add(int index, T elementToAdd) {
73
-//            T [] newArray = (T[]) new Object[theArray.length + 1];
74
-//            for (int i = 0; i < theArray.length; i++) {
75
-//                newArray[i] = theArray[i];
76
-//                if (i == theArray.length-1) {
77
-//                  newArray[i] = elementToAdd;
71
+
72
+        public void add(int index, T elementToAdd) {
73
+            T[] newArray = (T[]) new Object[theArray.length + 1];
74
+//            int track = 0;
75
+            for (int i = 0; i < theArray.length; i++) {
76
+                newArray[i] = theArray[i];
77
+                if (i == index) {
78
+                    set(i, elementToAdd);
79
+                    i = i+1;
80
+                }
81
+            }
82
+//                if (i == index) {
83
+//                    newArray[track] = elementToAdd;
78 84
 //                }
85
+//                newArray[track] = theArray[i];
86
+//                track++;
79 87
 //            }
80
-//        } Make a super or abstract class of AbstractList??
81
-
88
+        }
82 89
 }

+ 3
- 0
src/main/java/MySet.java 查看文件

@@ -0,0 +1,3 @@
1
+public class MySet <T, E> extends MyArrayList {
2
+
3
+}

+ 2
- 2
src/test/java/MyArrayListTest.java 查看文件

@@ -130,8 +130,8 @@ public class MyArrayListTest {
130 130
         MyArrayList<Integer> myArrayList = new MyArrayList<>(testOverrideAddInts);
131 131
         //when
132 132
         myArrayList.add(1, 2);
133
-        boolean hasBeenAdded = myArrayList.contains(2);
133
+        int actual = myArrayList.get(1);
134 134
         //then
135
-        Assert.assertTrue(hasBeenAdded);
135
+        Assert.assertEquals(2, actual);
136 136
     }
137 137
 }