Explorar el Código

everything but clear function

Michelle DiMarino hace 6 años
padre
commit
20fc4e814f
Se han modificado 3 ficheros con 239 adiciones y 94 borrados
  1. 159
    53
      .idea/workspace.xml
  2. 67
    30
      src/main/java/MyArrayList.java
  3. 13
    11
      src/test/java/MyArrayListTest.java

+ 159
- 53
.idea/workspace.xml Ver fichero

@@ -2,11 +2,9 @@
2 2
 <project version="4">
3 3
   <component name="ChangeListManager">
4 4
     <list default="true" id="b4e56f8e-cf07-42ba-a071-f009e3608fb2" name="Default Changelist" comment="">
5
-      <change afterPath="$PROJECT_DIR$/generics.iml" afterDir="false" />
6
-      <change afterPath="$PROJECT_DIR$/src/main/java/MyArrayList.java" afterDir="false" />
7
-      <change afterPath="$PROJECT_DIR$/src/test/java/MyArrayListTest.java" 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$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
6
+      <change beforePath="$PROJECT_DIR$/src/main/java/MyArrayList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/MyArrayList.java" afterDir="false" />
7
+      <change beforePath="$PROJECT_DIR$/src/test/java/MyArrayListTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/MyArrayListTest.java" afterDir="false" />
10 8
     </list>
11 9
     <ignored path="$PROJECT_DIR$/target/" />
12 10
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -19,38 +17,41 @@
19 17
     <session id="-666158232">
20 18
       <usages-collector id="statistics.lifecycle.project">
21 19
         <counts>
20
+          <entry key="project.closed" value="2" />
21
+          <entry key="project.open.time.1" value="1" />
22
+          <entry key="project.open.time.2" value="1" />
22 23
           <entry key="project.open.time.4" value="1" />
23
-          <entry key="project.opened" value="1" />
24
+          <entry key="project.opened" value="3" />
24 25
         </counts>
25 26
       </usages-collector>
26 27
       <usages-collector id="statistics.file.extensions.open">
27 28
         <counts>
28
-          <entry key="java" value="2" />
29
+          <entry key="java" value="6" />
29 30
           <entry key="md" value="1" />
30 31
           <entry key="xml" value="1" />
31 32
         </counts>
32 33
       </usages-collector>
33 34
       <usages-collector id="statistics.file.types.open">
34 35
         <counts>
35
-          <entry key="JAVA" value="2" />
36
+          <entry key="JAVA" value="6" />
36 37
           <entry key="Markdown" value="1" />
37 38
           <entry key="XML" value="1" />
38 39
         </counts>
39 40
       </usages-collector>
40 41
       <usages-collector id="statistics.file.extensions.edit">
41 42
         <counts>
42
-          <entry key="java" value="2556" />
43
+          <entry key="java" value="3486" />
43 44
         </counts>
44 45
       </usages-collector>
45 46
       <usages-collector id="statistics.file.types.edit">
46 47
         <counts>
47
-          <entry key="JAVA" value="2556" />
48
+          <entry key="JAVA" value="3486" />
48 49
         </counts>
49 50
       </usages-collector>
50 51
     </session>
51 52
   </component>
52 53
   <component name="FileEditorManager">
53
-    <leaf>
54
+    <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
54 55
       <file pinned="false" current-in-tab="false">
55 56
         <entry file="file://$PROJECT_DIR$/README.md">
56 57
           <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
@@ -62,28 +63,26 @@
62 63
         </entry>
63 64
       </file>
64 65
       <file pinned="false" current-in-tab="false">
65
-        <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
66
+        <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
66 67
           <provider selected="true" editor-type-id="text-editor">
67
-            <state relative-caret-position="105">
68
-              <caret line="7" column="44" selection-start-line="7" selection-start-column="44" selection-end-line="7" selection-end-column="44" />
68
+            <state relative-caret-position="-495">
69
+              <caret line="59" selection-start-line="59" selection-end-line="59" />
69 70
               <folding>
70 71
                 <element signature="imports" expanded="true" />
72
+                <element signature="e#191#192#0" expanded="true" />
73
+                <element signature="e#284#285#0" expanded="true" />
71 74
               </folding>
72 75
             </state>
73 76
           </provider>
74 77
         </entry>
75 78
       </file>
76 79
       <file pinned="false" current-in-tab="true">
77
-        <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
80
+        <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
78 81
           <provider selected="true" editor-type-id="text-editor">
79
-            <state relative-caret-position="911">
80
-              <caret line="72" column="10" selection-start-line="72" selection-start-column="10" selection-end-line="72" selection-end-column="10" />
82
+            <state relative-caret-position="276">
83
+              <caret line="106" lean-forward="true" selection-start-line="106" selection-end-line="106" />
81 84
               <folding>
82 85
                 <element signature="imports" expanded="true" />
83
-                <element signature="e#185#186#0" expanded="true" />
84
-                <element signature="e#235#236#0" expanded="true" />
85
-                <element signature="e#1519#1520#0" expanded="true" />
86
-                <element signature="e#1543#1544#0" expanded="true" />
87 86
               </folding>
88 87
             </state>
89 88
           </provider>
@@ -126,7 +125,7 @@
126 125
       <foldersAlwaysOnTop value="true" />
127 126
     </navigator>
128 127
     <panes>
129
-      <pane id="PackagesPane" />
128
+      <pane id="Scope" />
130 129
       <pane id="ProjectPane">
131 130
         <subPane>
132 131
           <expand>
@@ -169,13 +168,13 @@
169 168
           <select />
170 169
         </subPane>
171 170
       </pane>
172
-      <pane id="Scope" />
171
+      <pane id="PackagesPane" />
173 172
     </panes>
174 173
   </component>
175 174
   <component name="PropertiesComponent">
176 175
     <property name="WebServerToolWindowFactoryState" value="false" />
177 176
     <property name="aspect.path.notification.shown" value="true" />
178
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542226614775" />
177
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542245580538" />
179 178
     <property name="last_opened_file_path" value="$PROJECT_DIR$/pom.xml" />
180 179
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
181 180
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
@@ -192,20 +191,71 @@
192 191
       </list>
193 192
     </option>
194 193
   </component>
195
-  <component name="RunManager">
196
-    <configuration name="MyArrayListTest.sizeTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
194
+  <component name="RunManager" selected="JUnit.MyArrayListTest.clearTest">
195
+    <configuration name="MyArrayListTest.addAtIndexTest" 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="addAtIndexTest" />
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.addEndofListTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
197 206
       <module name="generics" />
198 207
       <option name="PACKAGE_NAME" value="" />
199 208
       <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
200
-      <option name="METHOD_NAME" value="sizeTest" />
209
+      <option name="METHOD_NAME" value="addEndofListTest" />
201 210
       <option name="TEST_OBJECT" value="method" />
202 211
       <method v="2">
203 212
         <option name="Make" enabled="true" />
204 213
       </method>
205 214
     </configuration>
215
+    <configuration name="MyArrayListTest.clearTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
216
+      <module name="generics" />
217
+      <option name="PACKAGE_NAME" value="" />
218
+      <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
219
+      <option name="METHOD_NAME" value="clearTest" />
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.getTest" 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="getTest" />
230
+      <option name="TEST_OBJECT" value="method" />
231
+      <method v="2">
232
+        <option name="Make" enabled="true" />
233
+      </method>
234
+    </configuration>
235
+    <configuration name="MyArrayListTest.removeTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
236
+      <module name="generics" />
237
+      <option name="PACKAGE_NAME" value="" />
238
+      <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
239
+      <option name="METHOD_NAME" value="removeTest" />
240
+      <option name="TEST_OBJECT" value="method" />
241
+      <method v="2">
242
+        <option name="Make" enabled="true" />
243
+      </method>
244
+    </configuration>
245
+    <list>
246
+      <item itemvalue="JUnit.MyArrayListTest.addEndofListTest" />
247
+      <item itemvalue="JUnit.MyArrayListTest.addAtIndexTest" />
248
+      <item itemvalue="JUnit.MyArrayListTest.getTest" />
249
+      <item itemvalue="JUnit.MyArrayListTest.clearTest" />
250
+      <item itemvalue="JUnit.MyArrayListTest.removeTest" />
251
+    </list>
206 252
     <recent_temporary>
207 253
       <list>
208
-        <item itemvalue="JUnit.MyArrayListTest.sizeTest" />
254
+        <item itemvalue="JUnit.MyArrayListTest.clearTest" />
255
+        <item itemvalue="JUnit.MyArrayListTest.removeTest" />
256
+        <item itemvalue="JUnit.MyArrayListTest.addAtIndexTest" />
257
+        <item itemvalue="JUnit.MyArrayListTest.getTest" />
258
+        <item itemvalue="JUnit.MyArrayListTest.addEndofListTest" />
209 259
       </list>
210 260
     </recent_temporary>
211 261
   </component>
@@ -219,36 +269,70 @@
219 269
       <option name="number" value="Default" />
220 270
       <option name="presentableId" value="Default" />
221 271
       <updated>1542220766885</updated>
222
-      <workItem from="1542220770531" duration="5385000" />
272
+      <workItem from="1542220770531" duration="5472000" />
273
+      <workItem from="1542235718301" duration="7000" />
274
+      <workItem from="1542240547208" duration="5140000" />
223 275
     </task>
224 276
     <servers />
225 277
   </component>
278
+  <component name="TestHistory">
279
+    <history-entry file="MyArrayListTest_getTest - 2018.11.14 at 20h 27m 27s.xml">
280
+      <configuration name="MyArrayListTest.getTest" configurationId="JUnit" />
281
+    </history-entry>
282
+    <history-entry file="MyArrayListTest_getTest - 2018.11.14 at 20h 27m 52s.xml">
283
+      <configuration name="MyArrayListTest.getTest" configurationId="JUnit" />
284
+    </history-entry>
285
+    <history-entry file="MyArrayListTest_clearTest - 2018.11.14 at 20h 28m 27s.xml">
286
+      <configuration name="MyArrayListTest.clearTest" configurationId="JUnit" />
287
+    </history-entry>
288
+    <history-entry file="MyArrayListTest_addAtIndexTest - 2018.11.14 at 20h 29m 03s.xml">
289
+      <configuration name="MyArrayListTest.addAtIndexTest" configurationId="JUnit" />
290
+    </history-entry>
291
+    <history-entry file="MyArrayListTest_removeTest - 2018.11.14 at 20h 29m 32s.xml">
292
+      <configuration name="MyArrayListTest.removeTest" configurationId="JUnit" />
293
+    </history-entry>
294
+    <history-entry file="MyArrayListTest_removeTest - 2018.11.14 at 20h 30m 00s.xml">
295
+      <configuration name="MyArrayListTest.removeTest" configurationId="JUnit" />
296
+    </history-entry>
297
+    <history-entry file="MyArrayListTest_addAtIndexTest - 2018.11.14 at 20h 30m 14s.xml">
298
+      <configuration name="MyArrayListTest.addAtIndexTest" configurationId="JUnit" />
299
+    </history-entry>
300
+    <history-entry file="MyArrayListTest_addAtIndexTest - 2018.11.14 at 20h 32m 24s.xml">
301
+      <configuration name="MyArrayListTest.addAtIndexTest" configurationId="JUnit" />
302
+    </history-entry>
303
+    <history-entry file="MyArrayListTest_removeTest - 2018.11.14 at 20h 32m 52s.xml">
304
+      <configuration name="MyArrayListTest.removeTest" configurationId="JUnit" />
305
+    </history-entry>
306
+    <history-entry file="MyArrayListTest_clearTest - 2018.11.14 at 20h 33m 01s.xml">
307
+      <configuration name="MyArrayListTest.clearTest" configurationId="JUnit" />
308
+    </history-entry>
309
+  </component>
226 310
   <component name="TimeTrackingManager">
227
-    <option name="totallyTimeSpent" value="5385000" />
311
+    <option name="totallyTimeSpent" value="10619000" />
228 312
   </component>
229 313
   <component name="ToolWindowManager">
230 314
     <frame x="0" y="23" width="1260" height="708" extended-state="0" />
231 315
     <editor active="true" />
232 316
     <layout>
233
-      <window_info id="Image Layers" />
234
-      <window_info id="Designer" />
235
-      <window_info id="UI Designer" />
236
-      <window_info id="Capture Tool" />
237
-      <window_info id="Favorites" side_tool="true" />
238
-      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.24958949" />
317
+      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25779969" />
239 318
       <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
240
-      <window_info active="true" anchor="bottom" id="Messages" visible="true" weight="0.32954547" />
241
-      <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
242
-      <window_info anchor="bottom" id="Version Control" show_stripe_button="false" />
243
-      <window_info anchor="bottom" id="Terminal" />
244
-      <window_info anchor="bottom" id="Event Log" side_tool="true" />
319
+      <window_info id="Image Layers" order="2" />
320
+      <window_info id="Designer" order="3" />
321
+      <window_info id="UI Designer" order="4" />
322
+      <window_info id="Capture Tool" order="5" />
323
+      <window_info id="Favorites" order="6" side_tool="true" />
245 324
       <window_info anchor="bottom" id="Message" order="0" />
246 325
       <window_info anchor="bottom" id="Find" order="1" />
247
-      <window_info anchor="bottom" id="Run" order="2" />
248
-      <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
326
+      <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32954547" />
327
+      <window_info anchor="bottom" id="Debug" order="3" weight="0.39935064" />
249 328
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
250 329
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
251 330
       <window_info anchor="bottom" id="TODO" order="6" />
331
+      <window_info anchor="bottom" id="Version Control" order="7" show_stripe_button="false" />
332
+      <window_info anchor="bottom" id="Database Changes" order="8" show_stripe_button="false" />
333
+      <window_info anchor="bottom" id="Terminal" order="9" />
334
+      <window_info anchor="bottom" id="Event Log" order="10" side_tool="true" />
335
+      <window_info anchor="bottom" id="Messages" order="11" weight="0.32954547" />
252 336
       <window_info anchor="right" id="Palette" order="0" />
253 337
       <window_info anchor="right" id="Theme Preview" order="1" />
254 338
       <window_info anchor="right" id="Capture Analysis" order="2" />
@@ -266,6 +350,24 @@
266 350
   <component name="VcsContentAnnotationSettings">
267 351
     <option name="myLimit" value="2678400000" />
268 352
   </component>
353
+  <component name="XDebuggerManager">
354
+    <breakpoint-manager>
355
+      <breakpoints>
356
+        <line-breakpoint enabled="true" type="java-line">
357
+          <url>file://$PROJECT_DIR$/src/main/java/MyArrayList.java</url>
358
+          <line>25</line>
359
+          <properties />
360
+          <option name="timeStamp" value="2" />
361
+        </line-breakpoint>
362
+        <line-breakpoint enabled="true" type="java-line">
363
+          <url>file://$PROJECT_DIR$/src/main/java/MyArrayList.java</url>
364
+          <line>43</line>
365
+          <properties />
366
+          <option name="timeStamp" value="4" />
367
+        </line-breakpoint>
368
+      </breakpoints>
369
+    </breakpoint-manager>
370
+  </component>
269 371
   <component name="antWorkspaceConfiguration">
270 372
     <option name="IS_AUTOSCROLL_TO_SOURCE" value="false" />
271 373
     <option name="FILTER_TARGETS" value="false" />
@@ -274,6 +376,9 @@
274 376
     <entry file="file://$PROJECT_DIR$/pom.xml">
275 377
       <provider selected="true" editor-type-id="text-editor" />
276 378
     </entry>
379
+    <entry file="file://$PROJECT_DIR$/../Week5/CR-MesoLabs-Generics-ArrayUtility/src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java">
380
+      <provider selected="true" editor-type-id="text-editor" />
381
+    </entry>
277 382
     <entry file="file://$PROJECT_DIR$/README.md">
278 383
       <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
279 384
         <state split_layout="SPLIT">
@@ -282,26 +387,27 @@
282 387
         </state>
283 388
       </provider>
284 389
     </entry>
285
-    <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
390
+    <entry file="file://$PROJECT_DIR$/../Week5/CR-MesoLabs-Generics-ArrayUtility/src/test/java/com/zipcodewilmington/arrayutility/GetNumberOfOccurrencesTest.java">
391
+      <provider selected="true" editor-type-id="text-editor" />
392
+    </entry>
393
+    <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
286 394
       <provider selected="true" editor-type-id="text-editor">
287
-        <state relative-caret-position="105">
288
-          <caret line="7" column="44" selection-start-line="7" selection-start-column="44" selection-end-line="7" selection-end-column="44" />
395
+        <state relative-caret-position="-495">
396
+          <caret line="59" selection-start-line="59" selection-end-line="59" />
289 397
           <folding>
290 398
             <element signature="imports" expanded="true" />
399
+            <element signature="e#191#192#0" expanded="true" />
400
+            <element signature="e#284#285#0" expanded="true" />
291 401
           </folding>
292 402
         </state>
293 403
       </provider>
294 404
     </entry>
295
-    <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
405
+    <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
296 406
       <provider selected="true" editor-type-id="text-editor">
297
-        <state relative-caret-position="911">
298
-          <caret line="72" column="10" selection-start-line="72" selection-start-column="10" selection-end-line="72" selection-end-column="10" />
407
+        <state relative-caret-position="276">
408
+          <caret line="106" lean-forward="true" selection-start-line="106" selection-end-line="106" />
299 409
           <folding>
300 410
             <element signature="imports" expanded="true" />
301
-            <element signature="e#185#186#0" expanded="true" />
302
-            <element signature="e#235#236#0" expanded="true" />
303
-            <element signature="e#1519#1520#0" expanded="true" />
304
-            <element signature="e#1543#1544#0" expanded="true" />
305 411
           </folding>
306 412
         </state>
307 413
       </provider>

+ 67
- 30
src/main/java/MyArrayList.java Ver fichero

@@ -1,38 +1,69 @@
1 1
 import java.lang.reflect.Array;
2 2
 import java.util.ArrayList;
3 3
 
4
-public class MyArrayList {
4
+public class MyArrayList <T> {
5 5
 
6
-    private Object[] array1;
6
+    private T[] array1;
7 7
 
8
-    public MyArrayList(){
8
+    public MyArrayList(T[] array){
9
+        this.array1 = array;
9 10
 
10 11
     }
11 12
 
12 13
     public MyArrayList(int size){
13
-        Object[] array1 = new Object[size];
14
+        this.array1 = (T[])Array.newInstance(array1.getClass().getComponentType(),size);
14 15
     }
15 16
 
16 17
     public int size(){
17 18
         int counter = 0;
18
-        for (Object element: array1){
19
+        for (T element: array1){
19 20
             counter++;
20 21
         }
21 22
         return counter;
22 23
     }
23 24
 
24
-    public void add(){
25
+    public T[] add(T valueToAdd){
26
+        ArrayList <T> arrayWithAdd = new ArrayList<>();
27
+
28
+        for (T element : array1){
29
+            arrayWithAdd.add(element);
30
+        }
31
+
32
+        arrayWithAdd.add(valueToAdd);
33
+
34
+        T[] objs =  (T[])Array.newInstance(array1.getClass().getComponentType(), arrayWithAdd.size());
35
+
36
+        array1 = arrayWithAdd.toArray(objs);
37
+
38
+        return array1;
25 39
 
26 40
 
27 41
     }
28 42
 
29
-    public void add(int index, Object value){
43
+    public T[] add(int index, T value){
44
+        ArrayList<T>  arrayWithAdd = new ArrayList<>();
45
+
46
+        for (T element : array1){
47
+            arrayWithAdd.add(element);
48
+        }
49
+
50
+        for(int i = 0; i < array1.length; i++){
51
+            if (i == index){
52
+                arrayWithAdd.add(value);
53
+            }
54
+        }
55
+
56
+        T[] objs =  (T[])Array.newInstance(array1.getClass().getComponentType(), arrayWithAdd.size());
57
+
58
+        array1 = arrayWithAdd.toArray(objs);
59
+
60
+        return array1;
30 61
 
31 62
     }
32 63
 
33 64
 
34
-    public Object get(int index){
35
-        Object value = null;
65
+    public T get(int index){
66
+        T value = null;
36 67
         for (int i = 0; i < array1.length; i++) {
37 68
             if (i == index){
38 69
                 value = array1[i];
@@ -41,22 +72,22 @@ public class MyArrayList {
41 72
         return value;
42 73
     }
43 74
 
44
-//    public T[] remove(Object valueToRemove) {
45
-//        ArrayList<T> valuesNotRemoved = new ArrayList<>();
46
-//
47
-//        for (T data:newList) {
48
-//            if (!data.equals(valueToRemove)) {
49
-//                valuesNotRemoved.add(data);
50
-//            }
51
-//        }
52
-//        System.out.println(content.getClass().getComponentType());
53
-//        //was creating the new array but was empty.
54
-//        T[] objs =  (T[])Array.newInstance(content.getClass().getComponentType(), valuesNotRemoved.size());
55
-//
56
-//        return valuesNotRemoved.toArray(objs);
57
-//    }
58
-
59
-    public void set(int index, Object value){
75
+    public T[] remove(T valueToRemove) {
76
+        ArrayList<T> valuesNotRemoved = new ArrayList<>();
77
+
78
+        for (T data:array1) {
79
+            if (!data.equals(valueToRemove)) {
80
+                valuesNotRemoved.add(data);
81
+            }
82
+        }
83
+
84
+        T[] objs =  (T[])Array.newInstance(array1.getClass().getComponentType(), valuesNotRemoved.size());
85
+
86
+        array1 =valuesNotRemoved.toArray(objs);
87
+        return array1;
88
+    }
89
+
90
+    public void set(int index, T value){
60 91
         for (int i = 0; i < array1.length; i++){
61 92
             if (i == index){
62 93
                 array1[i] = value;
@@ -65,19 +96,25 @@ public class MyArrayList {
65 96
 
66 97
     }
67 98
 
68
-    public void clear(){
69
-
99
+    public T[] clear(){
100
+        T[] emptyArray = (T[])Array.newInstance(array1.getClass().getComponentType(), array1.length);
101
+        array1 = emptyArray;
102
+        return array1;
70 103
     }
71 104
 
72 105
     public boolean isEmpty(){
73
-    return false;
106
+        if (array1[0].equals(null)){
107
+            return true;
108
+        }else {
109
+            return false;
110
+        }
74 111
     }
75 112
 
76
-    public boolean contains(Object value){
113
+    public boolean contains(T value){
77 114
         boolean contains = false;
78 115
 
79 116
         for (int i = 0; i < array1.length; i++){
80
-            if (value == array1[i]) {
117
+            if (value.equals(array1[i])) {
81 118
                 contains = true;
82 119
                 break;
83 120
             }

+ 13
- 11
src/test/java/MyArrayListTest.java Ver fichero

@@ -5,12 +5,14 @@ import org.junit.Assert;
5 5
 
6 6
 public class MyArrayListTest {
7 7
 
8
-    MyArrayList array1 = new MyArrayList(8);
8
+    Integer[] inputArray = {1,2,3,4,5};
9
+    MyArrayList<Integer> array1 = new MyArrayList<>(inputArray);
10
+
9 11
 
10 12
 
11 13
     @Test
12 14
     public void sizeTest(){
13
-        int expectedOutput = 8;
15
+        int expectedOutput = 5;
14 16
 
15 17
         int actualOutput = array1.size();
16 18
 
@@ -20,7 +22,7 @@ public class MyArrayListTest {
20 22
 
21 23
     @Test
22 24
     public void addEndofListTest(){
23
-        int expectedOutput = 9;
25
+        int expectedOutput = 6;
24 26
 
25 27
         array1.add(5);
26 28
         int actualOutput = array1.size();
@@ -31,7 +33,7 @@ public class MyArrayListTest {
31 33
 
32 34
     @Test
33 35
     public void addAtIndexTest(){
34
-        int expectedOutput = 10;
36
+        int expectedOutput = 6;
35 37
 
36 38
         array1.add(4,5);
37 39
         int actualOutput = array1.size();
@@ -41,9 +43,9 @@ public class MyArrayListTest {
41 43
 
42 44
     @Test
43 45
     public void removeTest(){
44
-        int expectedOutput = 9;
46
+        int expectedOutput = 4;
45 47
 
46
-        array.remove(4);
48
+        array1.remove(5);
47 49
         int actualOutput = array1.size();
48 50
 
49 51
         Assert.assertEquals(expectedOutput, actualOutput);
@@ -52,9 +54,9 @@ public class MyArrayListTest {
52 54
 
53 55
     @Test
54 56
     public void getTest(){
55
-        int expectedOutput = 5;
57
+        Object expectedOutput = 3;
56 58
 
57
-        int actualOutput = array1.get(2);
59
+        Object actualOutput = array1.get(2);
58 60
 
59 61
         Assert.assertEquals(expectedOutput, actualOutput);
60 62
 
@@ -63,10 +65,10 @@ public class MyArrayListTest {
63 65
 
64 66
     @Test
65 67
     public void setTest(){
66
-        int expectedOutput = 3;
68
+        Object expectedOutput = 3;
67 69
 
68 70
         array1.set(1,3);
69
-        int actualOutput = array1.get(1);
71
+        Object actualOutput = array1.get(1);
70 72
 
71 73
         Assert.assertEquals(expectedOutput, actualOutput);
72 74
 
@@ -75,7 +77,7 @@ public class MyArrayListTest {
75 77
 
76 78
     @Test
77 79
     public void containsTest(){
78
-        boolean actualOutput = array1.contains(value);
80
+        boolean actualOutput = array1.contains(5);
79 81
 
80 82
         Assert.assertTrue(actualOutput);
81 83