Skip to content

Instantly share code, notes, and snippets.

Stuart Marks stuart-marks

Block or report user

Report or block stuart-marks

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@stuart-marks
stuart-marks / ReadFileJavaApplicationBufferedReader.diff56.java
Last active Jan 7, 2019
Processing Large Files in Java, Variation 6
View ReadFileJavaApplicationBufferedReader.diff56.java
--- ReadFileJavaApplicationBufferedReader5.java 2019-01-05 20:40:11.000000000 -0800
+++ ReadFileJavaApplicationBufferedReader6.java 2019-01-05 20:40:15.000000000 -0800
@@ -115,16 +115,9 @@
}
}
- LinkedList<Entry<String, Integer>> list = new LinkedList<>(map.entrySet());
+ Entry<String, Integer> common = Collections.max(map.entrySet(), Entry.comparingByValue());
- Collections.sort(list, new Comparator<Map.Entry<String, Integer> >() {
@stuart-marks
stuart-marks / ReadFileJavaApplicationBufferedReader.diff45.java
Last active Jan 7, 2019
Processing Large Files in Java, Variation 5
View ReadFileJavaApplicationBufferedReader.diff45.java
--- ReadFileJavaApplicationBufferedReader4.java 2019-01-05 20:40:05.000000000 -0800
+++ ReadFileJavaApplicationBufferedReader5.java 2019-01-05 20:40:11.000000000 -0800
@@ -46,6 +46,8 @@
ArrayList<String> firstNames = new ArrayList<>();
var namePat = Pattern.compile(", \\s*([^, ]+)");
+ char[] chars = new char[6];
+ StringBuilder sb = new StringBuilder(7);
System.out.println("Reading file using " + Caller.getName());
@stuart-marks
stuart-marks / ReadFileJavaApplicationBufferedReader.diff34.java
Last active Jan 7, 2019
Processing Large Files in Java, Variation 4
View ReadFileJavaApplicationBufferedReader.diff34.java
--- ReadFileJavaApplicationBufferedReader3.java 2019-01-05 20:40:01.000000000 -0800
+++ ReadFileJavaApplicationBufferedReader4.java 2019-01-05 20:40:05.000000000 -0800
@@ -45,7 +45,7 @@
Instant commonNameStart = Instant.now();
ArrayList<String> firstNames = new ArrayList<>();
- var namePat = Pattern.compile(", \\s*(([^ ]*), |([^ ]+))");
+ var namePat = Pattern.compile(", \\s*([^, ]+)");
System.out.println("Reading file using " + Caller.getName());
@stuart-marks
stuart-marks / ReadFileJavaApplicationBufferedReader.diff23.java
Last active Jan 7, 2019
Processing Large Files in Java, Variation 3
View ReadFileJavaApplicationBufferedReader.diff23.java
--- ReadFileJavaApplicationBufferedReader2.java
+++ ReadFileJavaApplicationBufferedReader3.java
@@ -44,6 +45,7 @@
Instant commonNameStart = Instant.now();
ArrayList<String> firstNames = new ArrayList<>();
+ var namePat = Pattern.compile(", \\s*(([^ ]*), |([^ ]+))");
System.out.println("Reading file using " + Caller.getName());
@stuart-marks
stuart-marks / ReadFileJavaApplicationBufferedReader.diff01.java
Last active Jan 7, 2019
Processing Large Files in Java, Variation 1
View ReadFileJavaApplicationBufferedReader.diff01.java
--- ReadFileJavaApplicationBufferedReader0.java
+++ ReadFileJavaApplicationBufferedReader1.java
@@ -57,8 +57,8 @@
// System.out.println(readLine);
// get all the names
- String array1[] = readLine.split("\\s*\\|\\s*");
- String name = array1[7];
+ String array1[] = readLine.split("\\|", 9);
+ String name = array1[7].strip();
@stuart-marks
stuart-marks / ReadFileJavaApplicationBufferedReader.diff12.java
Last active Jan 7, 2019
Processing Large Files in Java, Variation 2
View ReadFileJavaApplicationBufferedReader.diff12.java
--- ReadFileJavaApplicationBufferedReader1.java
+++ ReadFileJavaApplicationBufferedReader2.java
@@ -29,17 +29,12 @@
// get total line count
Instant lineCountStart = Instant.now();
- int lines = 0;
Instant namesStart = Instant.now();
ArrayList<String> names = new ArrayList<>();
@stuart-marks
stuart-marks / ReadFileJavaApplicationBufferedReader7.java
Last active Jun 9, 2019
Processing Large Files in Java, Variation 7
View ReadFileJavaApplicationBufferedReader7.java
package com.example.readFile.readFileJava;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
@stuart-marks
stuart-marks / MasterClass.java
Created Nov 10, 2018
data and utilities for Lambda/Streams Master Class
View MasterClass.java
package masterclass;
import java.util.*;
import java.util.stream.*;
import java.util.Map.Entry;
import static java.util.Map.entry;
import static java.util.stream.Collectors.*;
public class MasterClass {
@stuart-marks
stuart-marks / FlatMapping.java
Created Apr 11, 2018
Utilities for streams flatmapping from collections, arrays, and optionals.
View FlatMapping.java
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Stream;
// Suppose we have an API where:
// - a Clazz has a List of Methods,
View gist:da122da352e6091fa088d1a35cff4db0
$ cat Printf.java
public class Printf {
public static void main(String[] args) {
System.out.println("Locale.getDefault()=" + java.util.Locale.getDefault());
System.out.printf("%.3f%n", 123.45);
}
}
$ javac Printf.java
$ java -version
You can’t perform that action at this time.