浏览代码

Everything extending Stack works, combiner stubs

vvmk 6 年前
父节点
当前提交
21de74bab5

+ 5
- 0
src/main/java/ArrayListCombiner/ArrayListCombiner.java 查看文件

@@ -9,4 +9,9 @@ import java.util.ArrayList;
9 9
  * The second method should be called superCombiner and should use ? super E
10 10
  */
11 11
 public class ArrayListCombiner {
12
+    public static <E> void superCombiner(ArrayList<? super E> parent, ArrayList<E> child) {
13
+    }
14
+
15
+    public static <E> void extendCombiner(ArrayList<E> parent, ArrayList<? extends E> child) {
16
+    }
12 17
 }

+ 16
- 2
src/main/java/Pair/Arrays.java 查看文件

@@ -1,7 +1,6 @@
1 1
 package Pair;
2 2
 
3 3
 import java.util.ArrayList;
4
-import java.util.Collections;
5 4
 
6 5
 /**
7 6
  * In here you must make firstLast, which will return a pair of the first element in the array list and the last
@@ -11,7 +10,22 @@ import java.util.Collections;
11 10
  * And a minmax method that returns a pair containing the largest and smallest items from the array list
12 11
  */
13 12
 public class Arrays {
14
-    public static <E> Pair<E> firstLast(ArrayList<?> a) {
13
+    public static <E> Pair<E> firstLast(ArrayList<E> a) {
14
+        E first = a.get(0);
15
+        E second = a.get(a.size() - 1);
16
+
17
+        return new Pair<>(first, second);
18
+    }
19
+
20
+    public <E> E max(ArrayList<E> a) {
21
+        return null;
22
+    }
23
+
24
+    public <E> E min(ArrayList<E> a) {
25
+        return null;
26
+    }
27
+
28
+    public <E> Pair<E> minmax(ArrayList<E> a) {
15 29
         return null;
16 30
     }
17 31
 }

+ 22
- 0
src/main/java/Pair/Pair.java 查看文件

@@ -8,5 +8,27 @@ package Pair;
8 8
  * max -> returns the maximum of the pair
9 9
  */
10 10
 public class Pair<E> {
11
+    private E first;
12
+    private E second;
11 13
 
14
+    public Pair(E first, E second) {
15
+        this.first = first;
16
+        this.second = second;
17
+    }
18
+
19
+    public E getFirst() {
20
+        return first;
21
+    }
22
+
23
+    public E getSecond() {
24
+        return second;
25
+    }
26
+
27
+    public E min() {
28
+        return null;
29
+    }
30
+
31
+    public E max() {
32
+        return null;
33
+    }
12 34
 }

+ 1
- 3
src/main/java/StackArray/ObjectStack.java 查看文件

@@ -11,7 +11,5 @@ import StackArrayList.Stack;
11 11
 public class ObjectStack<E> extends Stack<E> {
12 12
     private Object[] elements;
13 13
 
14
-    public ObjectStack() {
15
-
16
-    }
14
+    public ObjectStack() {}
17 15
 }

+ 37
- 37
src/test/java/ArrayListCombiner/ArrayListCombinerTest.java 查看文件

@@ -2,47 +2,47 @@ package ArrayListCombiner;
2 2
 
3 3
 import Employee.Employee;
4 4
 import Employee.Manager;
5
-import org.junit.Test;
6
-
7 5
 import org.junit.Assert;
6
+import org.junit.Test;
8 7
 
9 8
 import java.util.ArrayList;
10 9
 
11 10
 public class ArrayListCombinerTest {
12
-//    Employee foo = new Employee("FOO", 100);
13
-//    Manager bar = new Manager("BAR", 100);
14
-//    @Test
15
-//    public void testExtendCombiner() throws Exception {
16
-//        // Given an array list with employees
17
-//        ArrayList<Employee> first = new ArrayList<>();
18
-//        first.add(foo);
19
-//        // An an array list with managers
20
-//        ArrayList<Manager> second = new ArrayList<>();
21
-//        second.add(bar);
22
-//        // When  I combine them
23
-//        ArrayListCombiner.extendCombiner(first, second);
24
-//        // Then I should get an arrayList with both
25
-//        ArrayList<Employee> expected = new ArrayList<>();
26
-//        expected.add(foo);
27
-//        expected.add(bar);
28
-//        Assert.assertEquals(expected, first);
29
-//    }
30
-//
31
-//    @Test
32
-//    public void testSuperCombiner() throws Exception {
33
-//        // Given an array list with employees
34
-//        ArrayList<Employee> first = new ArrayList<>();
35
-//        first.add(foo);
36
-//        // An an array list with managers
37
-//        ArrayList<Manager> second = new ArrayList<>();
38
-//        second.add(bar);
39
-//        // When  I combine them
40
-//        ArrayListCombiner.superCombiner(first, second);
41
-//        // Then I should get an arrayList with both
42
-//        ArrayList<Employee> expected = new ArrayList<>();
43
-//        expected.add(foo);
44
-//        expected.add(bar);
45
-//        Assert.assertEquals(expected, first);
46
-//    }
11
+    Employee foo = new Employee("FOO", 100);
12
+    Manager bar = new Manager("BAR", 100);
13
+
14
+    @Test
15
+    public void testExtendCombiner() throws Exception {
16
+        // Given an array list with employees
17
+        ArrayList<Employee> first = new ArrayList<>();
18
+        first.add(foo);
19
+        // An an array list with managers
20
+        ArrayList<Manager> second = new ArrayList<>();
21
+        second.add(bar);
22
+        // When  I combine them
23
+        ArrayListCombiner.extendCombiner(first, second);
24
+        // Then I should get an arrayList with both
25
+        ArrayList<Employee> expected = new ArrayList<>();
26
+        expected.add(foo);
27
+        expected.add(bar);
28
+        Assert.assertEquals(expected, first);
29
+    }
30
+
31
+    @Test
32
+    public void testSuperCombiner() throws Exception {
33
+        // Given an array list with employees
34
+        ArrayList<Employee> first = new ArrayList<>();
35
+        first.add(foo);
36
+        // An an array list with managers
37
+        ArrayList<Manager> second = new ArrayList<>();
38
+        second.add(bar);
39
+        // When  I combine them
40
+        ArrayListCombiner.superCombiner(first, second);
41
+        // Then I should get an arrayList with both
42
+        ArrayList<Employee> expected = new ArrayList<>();
43
+        expected.add(foo);
44
+        expected.add(bar);
45
+        Assert.assertEquals(expected, first);
46
+    }
47 47
 
48 48
 }