Created
July 15, 2015 15:03
-
-
Save alexandreaquiles/383e70491f3f435584b4 to your computer and use it in GitHub Desktop.
Versão alternativa do código do post "Manipulando arquivos com recursos do Java 8" do blog da Caelum com sugestões do http://github.com/csokol. Veja em: http://blog.caelum.com.br/manipulando-arquivos-com-recursos-do-java-8/
This file contains 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 cargaHorariaDosServidores; | |
import java.io.IOException; | |
import java.nio.charset.StandardCharsets; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.util.TreeMap; | |
import java.util.function.Function; | |
import java.util.function.Predicate; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
import java.util.stream.Collectors; | |
public class CargaHorariaServidores { | |
private static final Pattern HORAS = Pattern | |
.compile(".*([0-9]{2}(,[0-9])? HORAS SEMANAIS|DEDICACAO EXCLUSIVA).*"); | |
public static void main(String[] args) throws IOException { | |
Predicate<String> isEmpty = String::isEmpty; | |
Path caminho = Paths.get(System.getProperty("user.home"), | |
"Downloads/201402_Servidores/20140228_Cadastro.csv"); | |
Files.lines(caminho, StandardCharsets.ISO_8859_1) | |
.map(linha -> { | |
Matcher matcher = HORAS.matcher(linha); | |
return matcher.matches() ? matcher.group(1) : ""; | |
}) | |
.filter(isEmpty.negate()) | |
.collect( | |
Collectors.groupingBy(Function.identity(), | |
TreeMap::new, Collectors.counting())) | |
.forEach((k, v) -> System.out.println(v + "\t" + k)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment