Skip to content

Instantly share code, notes, and snippets.

View Raouf25's full-sized avatar

ABDERRAOUF MAKHLOUF Raouf25

View GitHub Profile
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
}
files.stream()
.parallel()
.map(wrapper(file->file.getInputStream()))
.forEach(inputStream -> carService.saveCars(inputStream));
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);
}
};
}
@FunctionalInterface
interface FunctionWithException<T, R, E extends Exception> {
R apply(T t) throws E;
}
private InputStream extractInputStream(MultipartFile file) {
try {
return file.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
files.stream()
.parallel()
.map(file-> extractInputStream(file))
.forEach(inputStream -> carService.saveCars(inputStream));
files.stream()
.parallel()
.map(file-> {
try {
return file.getInputStream();
} catch (IOException e) {
e.printStackTrace();
return null;
}
})
for (final MultipartFile file : files) {
try {
carService.saveCars(file.getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
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();
// 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");