Skip to content

Commit

Permalink
lombok inspo
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonwatson committed Jul 30, 2024
1 parent eea41b7 commit 66c569d
Show file tree
Hide file tree
Showing 29 changed files with 438 additions and 575 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ $RECYCLE.BIN/

### Gradle ###
.gradle
/build/
/checker/build/
*/build/

# Ignore Gradle GUI config
gradle-app.setting
Expand Down
4 changes: 4 additions & 0 deletions lib/src/main/java/org/frc5572/util/profiler/AutoProfile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.frc5572.util.profiler;

/** Automatically profile a method. */
public @interface AutoProfile {}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.frc5572.util.profiler;

import it.unimi.dsi.fastutil.Pair;
import org.jetbrains.annotations.Nullable;

import java.util.Set;
import java.util.function.Supplier;

public final class EmptyProfiler implements ReadableProfiler {
Expand Down
34 changes: 25 additions & 9 deletions lib/src/main/java/org/frc5572/util/profiler/LoggingProfiler.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.frc5572.util.profiler;

import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import it.unimi.dsi.fastutil.longs.LongList;
import it.unimi.dsi.fastutil.objects.Object2LongMap;
import it.unimi.dsi.fastutil.objects.Object2LongMaps;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArraySet;
import org.jetbrains.annotations.Nullable;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.*;
import java.util.function.IntSupplier;
import java.util.function.LongSupplier;
Expand Down Expand Up @@ -60,13 +61,28 @@ public LocatedInfo getInfo(String name) {

@Override
public void save() {

try {
try(var outStream = new PrintStream(new FileOutputStream(filePath))) {
outStream.println("Performance Log\n================================================================================");
for(var entry : locationInfos.entrySet()) {
var info = entry.getValue();
outStream.println(entry.getKey().replace(SPLIT_CHAR, '.'));
outStream.println(" visitCount: " + info.getVisitCount());
outStream.println(" totalTime: " + info.getTotalTime());
outStream.println(" maxTime: " + info.getMaxTime());
outStream.println(" minTime: " + info.minTime);
outStream.println(" avgTime: " + info.getTotalTime() / info.getVisitCount());
}
}
} catch(IOException e) {
e.printStackTrace();
}
}

@Override
public void startTick() {
if(this.tickStarted) {
// TODO error: Profiler tick already started - missing endTick()?
throw new RuntimeException("Profiler tick already started. Missing endTick()?");
} else {
this.tickStarted = true;
this.fullPath = "";
Expand All @@ -78,20 +94,20 @@ public void startTick() {
@Override
public void endTick() {
if(!this.tickStarted) {
// TODO error: Profiler tick already ended - missing startTick()?
throw new RuntimeException("Profiler tick already ended. Missing startTick()?");
} else {
this.pop();
this.tickStarted = false;
if(!this.fullPath.isEmpty()) {
// TODO error: Profiler tick ended before path was fully popped (remainder: '{}'). Mismatched push/pop?
throw new RuntimeException("Profiler tick ended before path was fully popped. Mismatched push/pop?");
}
}
}

@Override
public void push(String location) {
if(!this.tickStarted) {
// TODO error: Cannot push '{}' to profiler if profiler tick hasn't started - missing startTick()?
throw new RuntimeException("Cannot push '" + location + "' to the profiler if profiler tick hasn't started. Missing startTick()?");
} else {
if(!this.fullPath.isEmpty()) {
this.fullPath = this.fullPath + SPLIT_CHAR;
Expand All @@ -111,9 +127,9 @@ public void push(Supplier<String> locationGetter) {
@Override
public void pop() {
if(!this.tickStarted) {
// TODO error: Cannot pop from profiler if profiler tick hasn't started - missing startTick()?
throw new RuntimeException("Cannot pop from profiler if profiler tick hasn't started. Missing startTick()?");
} else if(this.timeList.isEmpty()) {
// TODO error: Tried to pop one too many times! Mismatched push() and pop()?
throw new RuntimeException("Tried to pop one too many times! Mismatched push() and pop()?");
} else {
this.path.remove(this.path.size() - 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import it.unimi.dsi.fastutil.objects.Object2LongMap;
import it.unimi.dsi.fastutil.objects.Object2LongMaps;

import java.nio.file.Path;
import java.util.*;

public final class ProfileResultImpl implements ProfileResult {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.frc5572.util.profiler;

import it.unimi.dsi.fastutil.Pair;
import org.jetbrains.annotations.Nullable;

import java.util.Set;

public sealed interface ReadableProfiler extends Profiler permits EmptyProfiler, LoggingProfiler, ValidatingProfiler {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void save() {
@Override
public void startTick() {
if(this.tickStarted) {
// TODO error: Profiler tick already started - missing endTick()?
throw new RuntimeException("Profiler tick already started. Missing endTick()?");
} else {
tickStarted = true;
pathLen = 0;
Expand All @@ -45,20 +45,19 @@ public void startTick() {
@Override
public void endTick() {
if(!this.tickStarted) {
// TODO error: Profiler tick already ended - missing startTick()?
throw new RuntimeException("Profiler tick already ended. Missing startTick()?");
} else {
this.pop();
this.tickStarted = false;
if(!this.fullPathEmpty) {
// TODO error: Profiler tick ended before path was fully popped (remainder: '{}'). Mismatched push/pop?
}
throw new RuntimeException("Profiler tick ended before path was fully popped. Mismatched push/pop?"); }
}
}

@Override
public void push(String location) {
if(!this.tickStarted) {
// TODO error: Cannot push '{}' to profiler if profiler tick hasn't started - missing startTick()?
throw new RuntimeException("Cannot push '" + location + "' to the profiler if profiler tick hasn't started. Missing startTick()?");
} else {
fullPathEmpty = false;
pathLen += 1;
Expand All @@ -73,9 +72,9 @@ public void push(Supplier<String> locationGetter) {
@Override
public void pop() {
if(!this.tickStarted) {
// TODO error: Cannot pop from profiler if profiler tick hasn't started - missing startTick()?
throw new RuntimeException("Cannot pop from profiler if profiler tick hasn't started. Missing startTick()?");
} else if(pathLen == 0) {
// TODO error: Tried to pop one too many times! Mismatched push() and pop()?
throw new RuntimeException("Tried to pop one too many times! Mismatched push() and pop()?");
} else {
pathLen -= 1;
}
Expand Down
15 changes: 15 additions & 0 deletions lib/src/main/java/org/frc5572/util/serde/Alias.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.frc5572.util.serde;

import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/** Additional name this field could go by. Only used for deserialization, and only used if previous names/aliases are missing in log files. */

Check warning on line 9 in lib/src/main/java/org/frc5572/util/serde/Alias.java

View workflow job for this annotation

GitHub Actions / Linting

[testtool] reported by reviewdog 🐶 Line is longer than 100 characters (found 143). Raw Output: /github/workspace/./lib/src/main/java/org/frc5572/util/serde/Alias.java:9:0: warning: Line is longer than 100 characters (found 143). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.FIELD})
@Repeatable(Aliases.class)
public @interface Alias {
String value();

Check warning on line 14 in lib/src/main/java/org/frc5572/util/serde/Alias.java

View workflow job for this annotation

GitHub Actions / Linting

[testtool] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./lib/src/main/java/org/frc5572/util/serde/Alias.java:14:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
}
12 changes: 12 additions & 0 deletions lib/src/main/java/org/frc5572/util/serde/Aliases.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.frc5572.util.serde;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.SOURCE)

Check warning on line 8 in lib/src/main/java/org/frc5572/util/serde/Aliases.java

View workflow job for this annotation

GitHub Actions / Linting

[testtool] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./lib/src/main/java/org/frc5572/util/serde/Aliases.java:8:1: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck)
@Target({ElementType.FIELD})
public @interface Aliases {
Alias[] value();

Check warning on line 11 in lib/src/main/java/org/frc5572/util/serde/Aliases.java

View workflow job for this annotation

GitHub Actions / Linting

[testtool] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./lib/src/main/java/org/frc5572/util/serde/Aliases.java:11:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
}
12 changes: 12 additions & 0 deletions lib/src/main/java/org/frc5572/util/serde/Casing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.frc5572.util.serde;

public enum Casing {

Check warning on line 3 in lib/src/main/java/org/frc5572/util/serde/Casing.java

View workflow job for this annotation

GitHub Actions / Linting

[testtool] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./lib/src/main/java/org/frc5572/util/serde/Casing.java:3:1: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck)
LOWERCASE,
UPPERCASE,
PASCAL_CASE,
CAMEL_CASE,
SNAKE_CASE,
SCREAMING_SNAKE_CASE,
KEBAB_CASE,
SCREAMING_KEBAB_CASE,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.frc5572.util.serde;

/** Mark this class as the default serialization implementation for a given class. */
public @interface DefaultSerializer {
Class<?> value();

Check warning on line 5 in lib/src/main/java/org/frc5572/util/serde/DefaultSerializer.java

View workflow job for this annotation

GitHub Actions / Linting

[testtool] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./lib/src/main/java/org/frc5572/util/serde/DefaultSerializer.java:5:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
}
13 changes: 13 additions & 0 deletions lib/src/main/java/org/frc5572/util/serde/Rename.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.frc5572.util.serde;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/** Rename field in log table using the given name. */
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.FIELD})
public @interface Rename {
String value();

Check warning on line 12 in lib/src/main/java/org/frc5572/util/serde/Rename.java

View workflow job for this annotation

GitHub Actions / Linting

[testtool] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./lib/src/main/java/org/frc5572/util/serde/Rename.java:12:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
}
13 changes: 13 additions & 0 deletions lib/src/main/java/org/frc5572/util/serde/RenameAll.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.frc5572.util.serde;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/** Rename all fields in serialized table using the given case conversions. This is ignored for any field with an explicit {@link Rename} annotation. */
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.TYPE})
public @interface RenameAll {
Casing value();
}
11 changes: 11 additions & 0 deletions lib/src/main/java/org/frc5572/util/serde/Serde.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.frc5572.util.serde;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/** File supports serialization to and from a log table. */
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.TYPE})
public @interface Serde {}
9 changes: 9 additions & 0 deletions lib/src/main/java/org/frc5572/util/serde/Serialize.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.frc5572.util.serde;

/** Implementation for serialization/deserialization of a type. */
public interface Serialize<T> {

void toTable(String name, T value);
T fromTable(String name);

Check warning on line 7 in lib/src/main/java/org/frc5572/util/serde/Serialize.java

View workflow job for this annotation

GitHub Actions / Linting

[testtool] reported by reviewdog 🐶 'METHOD_DEF' should be separated from previous line. Raw Output: /github/workspace/./lib/src/main/java/org/frc5572/util/serde/Serialize.java:7:5: warning: 'METHOD_DEF' should be separated from previous line. (com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck)

}
7 changes: 7 additions & 0 deletions lib/src/main/java/org/frc5572/util/serde/SingleSerdeItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.frc5572.util.serde;

/** Indicates this item should be updated every call to `periodic()`. */
public @interface SingleSerdeItem {
String name();

Check warning on line 5 in lib/src/main/java/org/frc5572/util/serde/SingleSerdeItem.java

View workflow job for this annotation

GitHub Actions / Linting

[testtool] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./lib/src/main/java/org/frc5572/util/serde/SingleSerdeItem.java:5:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
String updateInputs();

Check warning on line 6 in lib/src/main/java/org/frc5572/util/serde/SingleSerdeItem.java

View workflow job for this annotation

GitHub Actions / Linting

[testtool] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./lib/src/main/java/org/frc5572/util/serde/SingleSerdeItem.java:6:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
}
5 changes: 5 additions & 0 deletions lib/src/main/java/org/frc5572/util/serde/Skip.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.frc5572.util.serde;


/** Indicates this field should be skipped during serialization and deserialization. */
public @interface Skip {}
13 changes: 13 additions & 0 deletions lib/src/main/java/org/frc5572/util/serde/With.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.frc5572.util.serde;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/** Use a field with type that implements {@link Serialize} for serialization instead of the default. */
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.FIELD})
public @interface With {
Class<? extends Serialize<?>> value();
}
20 changes: 0 additions & 20 deletions processor/src/main/java/org/frc5572/robotools/Checks.java

This file was deleted.

Loading

0 comments on commit 66c569d

Please sign in to comment.