Skip to content

Instantly share code, notes, and snippets.


Joe Wolf bdkosher

  • Alexandria, VA
View GitHub Profile
View java_concrete_v_interface.txt
When concrete classes are preferrable to interfaces
String vs. CharSequence
- better relays immutability?
- so widespread that it can be an inconvenience to accept a CharSequence and have to do something with it, like pass to another 3rd party library method
Exception vs. Throwable
- error details object in REST application, don't want people to attempt to create these if there's an Error
LocalDate vs. ChronoLocalDate
import java.time.temporal.*;
import static java.time.Month.OCTOBER;
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
import static java.time.temporal.ChronoField.YEAR;
* Temporal fields that are commonly used within the Federal government.
* More fields may be added in the future (e.g. Leave Year, Bi-Weekly Pay Period)
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.MonthDay;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
View SearchActiveDirectory.groovy
@Grab(group='', module='spring-security-core', version='3.2.5.RELEASE')
@Grab(group='', module='spring-security-ldap', version='3.2.5.RELEASE')
import groovy.transform.*
import javax.naming.NamingException
import org.springframework.ldap.core.*
View JsonPrettyPrint.groovy
println groovy.json.JsonOutput.prettyPrint(new File(args[0]).text)
View FindNonUTF8Char.groovy
import groovy.transform.*
import java.nio.*
import java.nio.charset.*
@Field CharsetDecoder cs = Charset.forName('UTF-8').newDecoder()
InputStream.metaClass.eachChunk << { int preferredChunkSize, Closure closure ->
delegate.eachByte(preferredChunkSize) { buffer, bytesRead ->
if (bytesRead == preferredChunkSize) {
} else if (bytesRead > 0) {
View EachWithLast.groovy
/*def imewi = Iterable.metaClass.eachWithIndex
def lmewi = List.metaClass.eachWithIndex
println imewi
println lmewi
def iewi = Iterable.&eachWithIndex
def lewi = List.&eachWithIndex
def eachWithLast = { Closure c ->
int size = delegate.size()
bdkosher /
Created Apr 29, 2020
Some of this is now irrelevant in our Java 14+ world
package gov.uspto.iqs;
import java.time.DayOfWeek;
import java.util.Arrays;
public class SadCompiler {
int sadInstanceOf(Object o) {
if (o instanceof List) {
return ((List) o).size();

Say I've got a controller class, that effectively delegates to a service, retrieves some domain objects, and converts them to another data type that better serializes to JSON and contains some additional metadata.

public class RawFoo {
  private long id;
  private String name;

bdkosher /
Created Mar 18, 2020
Sorting on a potentially null field

Say I have a class with a potentially-null field and I want to sort a List of class instances on that field first (nulls last), then fall back on a second non-null field.

class Foo {
    String bar;
    int baz
You can’t perform that action at this time.