Bael 1585 (#3750)
* Different Types of Bean Injection in Spring * BAEL-1585 * Revert "Different Types of Bean Injection in Spring" This reverts commit ae47827879d0e9396ad5de5f979f495629a35838. * Revert "BAEL-1585" This reverts commit e792f17f82f863850d07884f4638c53beca7f52f. * BAEL-1585 * rev1
This commit is contained in:
parent
64e9b41aef
commit
61504c948b
@ -0,0 +1,31 @@
|
|||||||
|
package com.baeldung.java_8_features;
|
||||||
|
|
||||||
|
public class Car {
|
||||||
|
|
||||||
|
private String model;
|
||||||
|
private int topSpeed;
|
||||||
|
|
||||||
|
public Car(String model, int topSpeed) {
|
||||||
|
super();
|
||||||
|
this.model = model;
|
||||||
|
this.topSpeed = topSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModel() {
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModel(String model) {
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTopSpeed() {
|
||||||
|
return topSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTopSpeed(int topSpeed) {
|
||||||
|
this.topSpeed = topSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package com.baeldung.java8;
|
package com.baeldung.java8;
|
||||||
|
|
||||||
|
import com.baeldung.java_8_features.Car;
|
||||||
import com.baeldung.java_8_features.Person;
|
import com.baeldung.java_8_features.Person;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -44,4 +46,29 @@ public class Java8MaxMinUnitTest {
|
|||||||
assertEquals("Should be Alex", alex, minByAge);
|
assertEquals("Should be Alex", alex, minByAge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenArrayIsOfIntegerThenMinUsesIntegerComparator() {
|
||||||
|
int[] integers = new int[] { 20, 98, 12, 7, 35 };
|
||||||
|
|
||||||
|
int min = Arrays.stream(integers)
|
||||||
|
.min()
|
||||||
|
.getAsInt();
|
||||||
|
|
||||||
|
assertEquals(7, min);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenArrayIsOfCustomTypeThenMaxUsesCustomComparator() {
|
||||||
|
final Car porsche = new Car("Porsche 959", 319);
|
||||||
|
final Car ferrari = new Car("Ferrari 288 GTO", 303);
|
||||||
|
final Car bugatti = new Car("Bugatti Veyron 16.4 Super Sport", 415);
|
||||||
|
final Car mcLaren = new Car("McLaren F1", 355);
|
||||||
|
final Car[] fastCars = { porsche, ferrari, bugatti, mcLaren };
|
||||||
|
|
||||||
|
final Car maxBySpeed = Arrays.stream(fastCars)
|
||||||
|
.max(Comparator.comparing(Car::getTopSpeed))
|
||||||
|
.orElseThrow(NoSuchElementException::new);
|
||||||
|
|
||||||
|
assertEquals(bugatti, maxBySpeed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user