function | function signature | call |
---|---|---|
Getters | Function<City, String> fun = City::getName; | fun.apply(); |
Setters | BiConsumer<City, String> fun = City::setName; | fun.accept(); |
Default Constructor | Supplier< City> fun = City::new; | fun.get(); |
Parameter Constructors | BiFunction fun =City::new; | fun.apply(); |
This file contains hidden or 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
public interface CarRepository extends JpaRepository<Car, Long> { | |
List<Car> findByManufacturer(String manufacturer, Pageable pageable); | |
List<Car> findByModel(String model, Pageable pageable); | |
List<Car> findByManufacturerAndModel(String manufacturer, String model, Pageable pageable); | |
// other combinations omitted for sanity | |
} |
This file contains hidden or 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
files.stream() | |
.parallel() | |
.map(wrapper(file->file.getInputStream())) | |
.forEach(inputStream -> carService.saveCars(inputStream)); |
This file contains hidden or 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
private <T, R, E extends Exception> | |
Function<T, R> wrapper(FunctionWithException<T, R, E> fun) { | |
return arg -> { | |
try { | |
return fun.apply(arg); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
}; | |
} |
This file contains hidden or 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
@FunctionalInterface | |
interface FunctionWithException<T, R, E extends Exception> { | |
R apply(T t) throws E; | |
} |
This file contains hidden or 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
private InputStream extractInputStream(MultipartFile file) { | |
try { | |
return file.getInputStream(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} |
This file contains hidden or 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
files.stream() | |
.parallel() | |
.map(file-> extractInputStream(file)) | |
.forEach(inputStream -> carService.saveCars(inputStream)); |
This file contains hidden or 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
files.stream() | |
.parallel() | |
.map(file-> { | |
try { | |
return file.getInputStream(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
return null; | |
} | |
}) |
This file contains hidden or 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
for (final MultipartFile file : files) { | |
try { | |
carService.saveCars(file.getInputStream()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} |
This file contains hidden or 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
// Use the City's constructor method reference to create | |
// a two-parameter constructor reference. | |
BiFunction<String, String, City> twoParameterConstructor = City::new; | |
City dc = twoParameterConstructor.apply("Washington, D.C.", "DC"); |