Skip to content

Instantly share code, notes, and snippets.

@alexandreaquiles
Created July 15, 2015 15:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexandreaquiles/383e70491f3f435584b4 to your computer and use it in GitHub Desktop.
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/
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