Skip to content

Instantly share code, notes, and snippets.

View stuart-marks's full-sized avatar

Stuart Marks stuart-marks

View GitHub Profile
import java.util.*;
public class EmptyFinalizer {
static class A {
protected void finalize() {
System.out.println(this + " was finalized");
}
}
static class B extends A {
// https://twitter.com/stuartmarks/status/1304654956146745344
import java.lang.reflect.Field;
public class StillAlive {
@SuppressWarnings("deprecation") // oh shut up
static Boolean truе = new Boolean(true);
static void WearMask() { }
static void Stay6ftApart() { }
@stuart-marks
stuart-marks / ReadFileJavaApplicationBufferedReader.diff56.java
Last active January 7, 2019 00:07
Processing Large Files in Java, Variation 6
--- 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 January 7, 2019 00:06
Processing Large Files in Java, Variation 5
--- 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 January 7, 2019 00:06
Processing Large Files in Java, Variation 4
--- 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 January 7, 2019 00:06
Processing Large Files in Java, Variation 3
--- 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 January 7, 2019 00:06
Processing Large Files in Java, Variation 1
--- 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 January 7, 2019 00:06
Processing Large Files in Java, Variation 2
--- 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 May 3, 2021 10:39
Processing Large Files in Java, Variation 7
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 November 10, 2018 06:29
data and utilities for Lambda/Streams Master Class
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 {