-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package exists; | ||
|
||
import java.util.Collection; | ||
|
||
public class ExistsJava { | ||
public <E> boolean exists(final Collection<E> collection, final E element) { | ||
return collection.stream().anyMatch(e -> e.equals(element)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package exists; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
public class ExistsJavaTest { | ||
@Test | ||
public void exists_True() { | ||
final Collection<String> strings = Arrays.asList("a", "b"); | ||
final ExistsJava existsJava = new ExistsJava(); | ||
assertTrue(existsJava.exists(strings, "a")); | ||
} | ||
|
||
@Test | ||
public void exists_False() { | ||
final Collection<String> strings = Arrays.asList("a", "b"); | ||
final ExistsJava existsJava = new ExistsJava(); | ||
assertFalse(existsJava.exists(strings, "c")); | ||
} | ||
} |