Skip to content

Instantly share code, notes, and snippets.

View agentgt's full-sized avatar

Adam Gent agentgt

View GitHub Profile
@agentgt
agentgt / CustomJavaGenerator.java
Created January 9, 2025 16:07
jOOQ generator extension to add @default for MapStruct and to create package info for JSpecify annotations
public class CustomJavaGenerator extends JavaGenerator {
private final ThreadLocal<@Nullable JavaWriter> currentJavaWriter = new ThreadLocal<>();
private final ConcurrentHashMap<String, String> packageMap = new ConcurrentHashMap<>();
@Override
protected void generateRecord(
TableDefinition table) {
String packageName = getStrategy().getJavaPackageName(table, Mode.RECORD);
File recordFile = getFile(table, Mode.RECORD);
@agentgt
agentgt / mnemosyne_ai_dupe.md
Created August 1, 2024 14:55
mnemosyne_ai_dupe.md

This code defines a Java class ELFUCache that implements a Least Frequently Used (LFU) cache. The cache stores key-value pairs and evicts the least frequently used items when the capacity is reached. Here’s an overview and analysis of the code:

Structure and Key Components

  1. Imports and Package

    • The package and imports suggest that this is part of a larger project, specifically under the com.gmalandrakis.mnemosyne.cache package.
    • The imports include classes for data structures and concurrent utilities.
  2. Class Definition

    • The class ELFUCache<K, V> is generic, taking a key type K and a value type V.
  • ExecutorService internalThreadService; is declared but not properly initialized.
----------------------------------- SOURCE END -------------------------------------
!STACK 0
java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Objects.java:209)
at java.base/java.util.Arrays$ArrayList.<init>(Arrays.java:4137)
at java.base/java.util.Arrays.asList(Arrays.java:4122)
at org.eclipse.jdt.internal.compiler.ast.SwitchStatement.getAllPermittedTypes(SwitchStatement.java:1381)
at org.eclipse.jdt.internal.compiler.ast.SwitchStatement.checkAndFlagDefaultSealed(SwitchStatement.java:1368)
at org.eclipse.jdt.internal.compiler.ast.SwitchStatement.resolve(SwitchStatement.java:1248)
at org.eclipse.jdt.internal.compiler.ast.SwitchExpression.resolveType(SwitchExpression.java:418)
@agentgt
agentgt / debugoptions
Created March 11, 2024 15:24
Debug printing of annotation processing in Eclipse
org.eclipse.jdt.apt.core/debug=true
@agentgt
agentgt / eclipse_null_bugs.md
Last active August 18, 2023 20:15
Eclipse null analysis issues

Eclipse does not allow generic parameters on record attributes to be passed on to accessor methods.

public record Blah(List<String> strings) {}

public static void process(List<String> s) {}

var blah = new Blah(List.of("hello"));

process(blah.strings()); // null warning here because it does not know that strings is List&lt;@NonNull String&gt;
@agentgt
agentgt / Config.java
Last active February 12, 2023 15:18
Config.java
public interface Config extends Iterable<PropertyString> {
/*
* Required methods to implement
*/
public Config withPrefix(String prefix);
public Stream<PropertyString> stream();
@agentgt
agentgt / gist:97db11fadafed1579564b630138fc769
Created March 12, 2020 13:38
Using evolve for branching
hg init
echo Upstream1 > main.txt
hg add main.txt
hg commit -m "Master1"
hg branch -q feature
@agentgt
agentgt / ColumnPrism.java
Created May 14, 2019 14:57
Example of Hickory generating a prism for JPA column
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.VariableElement;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.type.TypeMirror;
import net.java.dev.hickory.prism.internal.*;
import java.util.HashMap;
@agentgt
agentgt / LoggerService.java
Last active March 17, 2017 15:49
A wrapper SLF4j to avoid default static initialization
package com.snaphop.slf4j;
import java.util.ServiceLoader;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.helpers.NOPLoggerFactory;
public interface LoggerService {
/*
* EXAMPLE USAGE. NOT TESTED THOUGH.
*/
public class Example {
public static void example() {
//do a double lock synchronization block if you are setting a singleton
PomManifest pm = null;
try {