Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed Selector to generic

  • Loading branch information...
commit 38c385439dcac45b1cc1b8c94438c9b9921c1223 1 parent 55a0123
jan-tomsa authored
View
2  src/main/java/com/tomsovi/SelectableList.java
@@ -31,7 +31,7 @@ public int size() {
return result;
}
- public List<Integer> select( Selector selector ) {
+ public List<Integer> select( Selector<Integer> selector ) {
List result = new ArrayList<Integer>();
for (Integer i : list) {
if (selector.evaluate(i) )
View
4 src/main/java/com/tomsovi/Selector.java
@@ -4,6 +4,6 @@
*
* @author P3400177
*/
-interface Selector {
- public boolean evaluate(Integer n);
+interface Selector<T> {
+ public boolean evaluate(T n);
}
View
14 src/test/java/com/tomsovi/AppTest.java → src/test/java/com/tomsovi/IntegerTest.java
@@ -8,7 +8,7 @@
/**
* Unit test for simple App.
*/
-public class AppTest extends TestCase {
+public class IntegerTest extends TestCase {
private SelectableList sl;
@@ -17,7 +17,7 @@
*
* @param testName name of the test case
*/
- public AppTest( String testName ) {
+ public IntegerTest( String testName ) {
super( testName );
}
@@ -25,7 +25,7 @@ public AppTest( String testName ) {
* @return the suite of tests being tested
*/
public static Test suite() {
- return new TestSuite( AppTest.class );
+ return new TestSuite( IntegerTest.class );
}
@Override
@@ -60,7 +60,7 @@ public void testLessThan100ShouldReturn6Items() {
* Test selector as anonymous class
*/
public void testAnonymousSelectorShouldSelectAll9() {
- Selector allSelector = new Selector() {
+ Selector<Integer> allSelector = new Selector<Integer>() {
public boolean evaluate(Integer n) {
return true;
}
@@ -74,7 +74,7 @@ public boolean evaluate(Integer n) {
* Test selector as anonymous class
*/
public void testAnonymousSelectorGreaterThan100ShouldSelect2() {
- Selector greaterThan100Selector = new Selector() {
+ Selector<Integer> greaterThan100Selector = new Selector<Integer>() {
public boolean evaluate(Integer n) {
return n > 100;
}
@@ -88,7 +88,7 @@ public boolean evaluate(Integer n) {
* Test selector as anonymous class - concise syntax
*/
public void testAnonymousSelectorGreaterThan100ShouldSelect2Concise() {
- List<Integer> reducedList = sl.select( new Selector() {
+ List<Integer> reducedList = sl.select( new Selector<Integer>() {
public boolean evaluate(Integer n) {
return n > 100;
}
@@ -101,7 +101,7 @@ public boolean evaluate(Integer n) {
* Test selector as anonymous class - more concise syntax
*/
public void testAnonymousSelectorLessThan10ShouldSelect3MoreConcise() {
- int size = sl.select( new Selector() {
+ int size = sl.select( new Selector<Integer>() {
public boolean evaluate(Integer n) {
return n < 10;
}
View
36 src/test/java/com/tomsovi/StringTest.java
@@ -0,0 +1,36 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.tomsovi;
+
+import java.util.Arrays;
+import java.util.List;
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author P3400177
+ */
+public class StringTest extends TestCase {
+ private List<String> list;
+ public StringTest(String testName) {
+ super(testName);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ list = Arrays.asList("A", "B", "C", "Hello", "World", "Do", "You", "Like", "Java", "?");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testHello() {
+ ;
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.