Created
December 5, 2013 18:22
-
-
Save keefmarshall/7810570 to your computer and use it in GitHub Desktop.
Lambda expressions demo - difference between Java 7 and 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
MapFileParser parser = new MapFileParser(filename); | |
parser.readMapFile(new MapProcessor() { | |
@Override | |
public void process(Map<String, String> map) | |
{ | |
database.add(map); | |
} | |
}); |
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
MapFileParser parser = new MapFileParser(filename); | |
parser.readMapFile( (map) -> { database.add(map); } ); |
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
public void readMapFile(MapProcessor processor) throws IOException | |
{ | |
try (BufferedReader reader = new BufferedReader(new FileReader(filename))) | |
{ | |
String line = reader.readLine(); | |
while (line != null) | |
{ | |
Map<String, String> map = parseLineIntoMap(line); | |
processor.process(map); | |
line = reader.readLine(); | |
} | |
} | |
} |
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
public void readMapFile(final Consumer<Map<String, String>> processor) throws IOException | |
{ | |
try (BufferedReader reader = new BufferedReader(new FileReader(filename))) | |
{ | |
String line = reader.readLine(); | |
while (line != null) | |
{ | |
Map<String, String> map = parseLineIntoMap(line); | |
processor.accept(map); | |
line = reader.readLine(); | |
} | |
} | |
} |
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
public interface MapProcessor | |
{ | |
void process(Map<String, String> map); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment