Skip to content

Updating JDK to 17 and GSON to 2.8.9 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: start
Choose a base branch
from
Prev Previous commit
Next Next commit
Get all yellow cars under 20k
  • Loading branch information
SylvesterLoreto committed Jul 15, 2023
commit 779f17d0d2cfeab68501dabb94b787f776750d10
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
package com.amigoscode.examples;

import com.amigoscode.beans.Car;
import com.amigoscode.beans.Person;
import com.amigoscode.mockdata.MockData;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;
import java.util.OptionalInt;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Filtering {
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

class FilteringTest {

@Test
public void filter() throws Exception {
List<Car> cars = MockData.getCars();
void get_all_yellow_cars_under_20k() throws Exception {
var cars = MockData.getCars();

Predicate<Car> price = car -> car.getPrice() < 20_000.00;
Predicate<Car> color = car -> car.getColor().equals("Yellow");

var carsUnder20k = cars.stream()
.filter(price)
.filter(color)
.toList();

assertThat(carsUnder20k.size()).isEqualTo(9);
carsUnder20k.forEach(car ->
assertThat(car.getPrice()).isLessThan(20_000.00));
}

@Test
public void dropWhile() throws Exception {
void dropWhile() throws Exception {
System.out.println("using filter");
Stream.of(2, 4, 6, 8, 9, 10, 12).filter(n -> n % 2 == 0)
.forEach(n -> System.out.print(n + " "));
Expand All @@ -29,7 +38,7 @@ public void dropWhile() throws Exception {
}

@Test
public void takeWhile() throws Exception {
void takeWhile() throws Exception {
// using filter
System.out.println("using filter");
Stream.of(2, 4, 6, 8, 9, 10, 12).filter(n -> n % 2 == 0)
Expand All @@ -40,22 +49,22 @@ public void takeWhile() throws Exception {
}

@Test
public void findFirst() throws Exception {
void findFirst() throws Exception {
int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
}

@Test
public void findAny() throws Exception {
void findAny() throws Exception {
int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10};
}

@Test
public void allMatch() throws Exception {
void allMatch() throws Exception {
int[] even = {2, 4, 6, 8, 10};
}

@Test
public void anyMatch() throws Exception {
void anyMatch() throws Exception {
int[] evenAndOneOdd = {2, 4, 6, 8, 10, 11};
}

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy