Created
July 5, 2017 02:34
-
-
Save rodrigooler/d0c0b3c5e3342de48301cfce9acfde1a to your computer and use it in GitHub Desktop.
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
package com.luizalabs.repository; | |
import com.luizalabs.entity.Product; | |
import com.luizalabs.entity.ProductGroup; | |
import info.debatty.java.stringsimilarity.Levenshtein; | |
import org.springframework.stereotype.Repository; | |
import java.util.*; | |
import java.util.stream.Collectors; | |
@Repository | |
public class ProductGroupRepository { | |
public List<ProductGroup> group(List<Product> products) { | |
final Map<String, List<Product>> ean = products | |
.stream() | |
.collect(Collectors.groupingBy(p -> p.getEan())); | |
List<Product> eanProduct = ean.get("7898100848355").stream().sorted(Comparator.comparing(Product::getStock).reversed().thenComparing(Product::getPrice)).collect(Collectors.toList()); | |
final Map<String, List<Product>> title = products | |
.stream() | |
.filter(product -> !Objects.equals(product.getEan(), "7898100848355")) | |
.collect(Collectors.groupingBy(p -> p.getTitle())); | |
final Map<String, List<Product>> brand = products | |
.stream() | |
.filter(product -> !Objects.equals(product.getEan(), "7898100848355")) | |
.collect(Collectors.groupingBy(p -> p.getBrand())); | |
List<ProductGroup> productGroupList = Arrays.asList( | |
new ProductGroup(eanProduct.get(0).getTitle(), eanProduct) | |
); | |
return productGroupList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment