diff --git a/src/com/github/deividfrancis/Carrinho.java b/src/com/github/deividfrancis/Carrinho.java new file mode 100644 index 0000000..e8ccd55 --- /dev/null +++ b/src/com/github/deividfrancis/Carrinho.java @@ -0,0 +1,119 @@ +package com.github.deividfrancis; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +import com.github.deividfrancis.backup.Person; + +public class Carrinho { + private static List produtoList = new ArrayList(); + + static { + produtoList.add(new Produtos(744, "Redragon Kumara" , 243.35, "Tecnologia", 'S')); + produtoList.add(new Produtos(850, "Redragon Cobra" , 190.20, "Tecnologia", 'S')); + produtoList.add(new Produtos(022, "SSD M.2" , 102.02, "Tecnologia", 'S')); + produtoList.add(new Produtos(848, "Monitor 24p 165hz" , 1153.0, "Tecnologia", 'N')); + produtoList.add(new Produtos(254, "Oculos de ciclismo" , 104.02, "Esporte" , 'S')); + produtoList.add(new Produtos(78, "Molinete de pesca" , 175.00, "Esporte" , 'N')); + produtoList.add(new Produtos(415, "Tenis allstar" , 167.00, "Vestuario" , 'S')); + produtoList.add(new Produtos(403, "Luva de motociclista" , 134.00, "Vestuario" , 'N')); + produtoList.add(new Produtos(625, "Chave de fenda magnética", 55.00, "Equipamentos", 'S')); + produtoList.add(new Produtos(573, "Tapete Geometrico", 114.00, "Lazer", 'S')); + } + + + public static void main(String[] args) { + // filtroTecnologia(); + // filtroEstoqueValor200(); + // filtroTemEstoque(); + // filtroEsporte(); + // filtroPrimeiraEquipamentos(); + // agrupaAlfabetica(); + // groupByCategoria(); + // getMaiorValor(); + // getListIds(); + } + + + private static void filtroTecnologia() { + List produtoTempList = Carrinho.produtoList.stream() + .filter(p -> "Tecnologia" == p.getCategoria()) + .collect(Collectors.toList()); + + System.out.println(produtoTempList); + } + + private static void filtroEstoqueValor200() { + List produtoTempList = produtoList.stream() + .filter(p -> 'S' == p.getTemEstoque() && p.getValor() > 200.00) + .collect(Collectors.toList()); + + System.out.println(produtoTempList); + } + + private static void filtroTemEstoque() { + List produtoTempList = produtoList.stream() + .filter(p -> 'S' == p.getTemEstoque()) + .collect(Collectors.toList()); + + produtoTempList.stream().forEach(p -> { + System.out.println(p.getNome()); + }); + } + + private static void filtroEsporte() { + Long produtoTempList = produtoList.stream() + .filter(p -> "Esporte" == p.getCategoria()) + .collect(Collectors.counting()); + + System.out.println(produtoTempList); + } + + private static void filtroPrimeiraEquipamentos() { + Produtos produtoTempList = produtoList.stream() + .filter(p -> p.getCategoria() == "Equipamentos") + .findFirst() + .orElse(null); + + System.out.println(produtoTempList); + } + + public static void agrupaAlfabetica() { + List produtoTempList = produtoList.stream() + .sorted((x1 , x2) -> x1.getNome().compareTo(x2.getNome())) + .toList(); + + System.out.println(produtoTempList); + } + + public static void groupByCategoria() { + Map> produtoMap = produtoList.stream().collect(Collectors.groupingBy(Produtos::getCategoria)); + + System.out.println(produtoMap); + } + + private static void getMaiorValor() { + Optional produtoTempList = produtoList.stream() + .sorted((x1 , x2) -> x2.getValor().compareTo(x1.getValor())) + .findFirst(); + + produtoTempList.stream().forEach(p -> { + System.out.println(p.getCategoria()); + }); + } + private static void getListIds() { + List produtoTempList = produtoList.stream() + .filter(p -> 850 == p.getId() || 403 == p.getId() || 625 == p.getId()) + .toList(); + + System.out.println(produtoTempList); + } + } + + + diff --git a/src/com/github/deividfrancis/Produtos.java b/src/com/github/deividfrancis/Produtos.java new file mode 100644 index 0000000..c79a843 --- /dev/null +++ b/src/com/github/deividfrancis/Produtos.java @@ -0,0 +1,55 @@ +package com.github.deividfrancis; + +import java.math.BigDecimal; + +public class Produtos { + private Integer id; + private String nome; + private Double valor; + private String categoria; + private char temEstoque; + + public Produtos(Integer id, String name, Double valor, String categoria, char temEstoque) { + this.id = id; + this.nome = name; + this.valor= valor; + this.categoria = categoria; + this.temEstoque = temEstoque; + } + + public Integer getId() { + return id; + } + public void setId(Integer id) { + this.id = id; + } + public String getNome() { + return nome; + } + public void setNome(String nome) { + this.nome = nome; + } + public Double getValor() { + return valor; + } + public void setValor(Double valor) { + this.valor = valor; + } + public String getCategoria() { + return categoria; + } + public void setCategoria(String categoria) { + this.categoria = categoria; + } + public char getTemEstoque() { + return temEstoque; + } + public void setTemEstoque(char temEstoque) { + this.temEstoque = temEstoque; + } + + @Override + public String toString() { + return "Id=" + id + ", Nome=" + nome + ", Valor=R$" + valor + ", categoria=" + categoria + ", temEstoque=" + temEstoque +"\n\n"; + } +} diff --git a/src/com/github/deividfrancis/Main.java b/src/com/github/deividfrancis/backup/Main.java similarity index 91% rename from src/com/github/deividfrancis/Main.java rename to src/com/github/deividfrancis/backup/Main.java index 9a636cc..6b2acd4 100644 --- a/src/com/github/deividfrancis/Main.java +++ b/src/com/github/deividfrancis/backup/Main.java @@ -1,4 +1,4 @@ -package com.github.deividfrancis; +package com.github.deividfrancis.backup; import java.util.ArrayList; import java.util.Arrays; @@ -60,7 +60,7 @@ private static void groupByLambda() { imprimeTitulo("groupByLambda"); - // Objetivo é agrupar Person pelo sex + // Objetivo � agrupar Person pelo sex Map> personMap = personList.stream().collect(Collectors.groupingBy(Person::getSex)); @@ -72,7 +72,7 @@ private static void groupByLambda() { private static void groupByNormal() { imprimeTitulo("groupByNormal"); - // Objetivo é agrupar Person pelo sex + // Objetivo � agrupar Person pelo sex Map> personMap = new HashMap>(); @@ -96,7 +96,7 @@ private static void groupByNormal() { private static void filtroCompostoLambda() { imprimeTitulo("filtroCompostoLambda"); - // Objetivo é mostrar somente os nomes das person do sexo masculino com age maior que 22; + // Objetivo � mostrar somente os nomes das person do sexo masculino com age maior que 22; List nomes = personList.stream() .filter(p -> p.getSex() == 'M') @@ -112,7 +112,7 @@ private static void filtroCompostoLambda() { private static void filtroCompostoNormal() { imprimeTitulo("filtroCompostoNormal"); - // Objetivo é mostrar somente os nomes das person do sexo masculino com age maior que 22; + // Objetivo � mostrar somente os nomes das person do sexo masculino com age maior que 22; List nomes = new ArrayList(); diff --git a/src/com/github/deividfrancis/Person.java b/src/com/github/deividfrancis/backup/Person.java similarity index 88% rename from src/com/github/deividfrancis/Person.java rename to src/com/github/deividfrancis/backup/Person.java index a3bb65b..510d1ea 100644 --- a/src/com/github/deividfrancis/Person.java +++ b/src/com/github/deividfrancis/backup/Person.java @@ -1,4 +1,4 @@ -package com.github.deividfrancis; +package com.github.deividfrancis.backup; public class Person { @@ -13,7 +13,7 @@ public Person(Integer id, String name, char sex, Integer age) { this.sex = sex; this.age = age; } - + public Integer getId() { return id; }