Skip to content

Commit 0d792e0

Browse files
Modernize - Ran many openrewrite recipes
1 parent 85cbc2b commit 0d792e0

File tree

14 files changed

+94
-32
lines changed

14 files changed

+94
-32
lines changed

action-node/src/main/java/me/retrodaredevil/action/node/expression/type/PrimitiveExpressionType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ public enum PrimitiveExpressionType implements ExpressionType {
77
NUMERIC,
88
STRING,
99
BOOLEAN,
10-
;
10+
1111
}

buildSrc/src/main/kotlin/buildlogic.java-common-conventions.gradle.kts

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,71 @@ rewrite {
234234
// https://docs.openrewrite.org/recipes/java/shortenfullyqualifiedtypereferences
235235
activeRecipe("org.openrewrite.java.ShortenFullyQualifiedTypeReferences")
236236

237+
// activeRecipe("org.openrewrite.java.migrate.util.SequencedCollection") // TODO this was enabled, but it won't compile for all language versions
238+
activeRecipe("org.openrewrite.java.migrate.lang.SwitchCaseAssignmentsToSwitchExpression")
239+
activeRecipe("org.openrewrite.java.migrate.lang.SwitchCaseReturnsToSwitchExpression")
240+
activeRecipe("org.openrewrite.java.jspecify.MigrateToJSpecify") // probably not necessary, but will point out "wrong" nullability imports
241+
activeRecipe("org.openrewrite.java.ShortenFullyQualifiedTypeReferences")
242+
237243
// Lots of static analysis
238-
// activeRecipe("org.openrewrite.staticanalysis.RemoveExtraSemicolons")
244+
activeRecipe("org.openrewrite.staticanalysis.RemoveExtraSemicolons")
239245
activeRecipe("org.openrewrite.staticanalysis.AnnotateNullableParameters") // if you check for null, it should be @Nullable
246+
activeRecipe("org.openrewrite.staticanalysis.CatchClauseOnlyRethrows")
247+
activeRecipe("org.openrewrite.staticanalysis.CompareEnumsWithEqualityOperator")
248+
// activeRecipe("org.openrewrite.staticanalysis.FinalClass") // maybe consider in the future
249+
activeRecipe("org.openrewrite.staticanalysis.ForLoopIncrementInUpdate")
250+
// activeRecipe("org.openrewrite.staticanalysis.UpperCaseLiteralSuffixes") // eventually maybe we can consider this
251+
// activeRecipe("org.openrewrite.staticanalysis.UseDiamondOperator") // TODO see what this does independently
252+
activeRecipe("org.openrewrite.staticanalysis.BooleanChecksNotInverted")
253+
// activeRecipe("org.openrewrite.staticanalysis.NeedBraces") // consider in the future
254+
// activeRecipe("org.openrewrite.staticanalysis.HideUtilityClassConstructor") // tries to make spring application class have private constructor
255+
// activeRecipe("org.openrewrite.staticanalysis.JavaApiBestPractices") // TODO enable
256+
activeRecipe("org.openrewrite.staticanalysis.ModifierOrder")
257+
activeRecipe("org.openrewrite.staticanalysis.NestedEnumsAreNotStatic")
258+
activeRecipe("org.openrewrite.staticanalysis.UseJavaStyleArrayDeclarations")
259+
activeRecipe("org.openrewrite.staticanalysis.NoDoubleBraceInitialization")
260+
// activeRecipe("org.openrewrite.staticanalysis.MultipleVariableDeclarations") // maybe consider in the future
261+
// activeRecipe("org.openrewrite.staticanalysis.OperatorWrap") // TODO enable - this is a good thing, but results in many many changes
262+
activeRecipe("org.openrewrite.staticanalysis.PreferSystemGetPropertyOverGetenv")
263+
activeRecipe("org.openrewrite.staticanalysis.PreferEqualityComparisonOverDifferenceCheck")
264+
activeRecipe("org.openrewrite.staticanalysis.PreferIncrementOperator")
265+
// activeRecipe("org.openrewrite.staticanalysis.CommonDeclarationSiteTypeVariances") // Could be useful, but honestly the `? super asdf` and `? extends asdf` gets old when it's unnecessary
266+
activeRecipe("org.openrewrite.staticanalysis.UnnecessaryPrimitiveAnnotations")
267+
activeRecipe("org.openrewrite.staticanalysis.UnnecessaryCatch")
268+
activeRecipe("org.openrewrite.staticanalysis.EmptyBlock")
269+
// activeRecipe("org.openrewrite.staticanalysis.RemoveRedundantTypeCast") // bug where it will sometimes remove (T) in unchecked code
270+
activeRecipe("org.openrewrite.staticanalysis.RemoveRedundantNullCheckBeforeInstanceof")
271+
activeRecipe("org.openrewrite.staticanalysis.RemoveRedundantNullCheckBeforeLiteralEquals")
272+
activeRecipe($$"org.openrewrite.staticanalysis.SimplifyTernaryRecipes$SimplifyTernaryFalseTrueRecipe")
273+
activeRecipe($$"org.openrewrite.staticanalysis.SimplifyTernaryRecipes$SimplifyTernaryTrueFalseRecipe")
274+
activeRecipe("org.openrewrite.staticanalysis.UseListSort")
275+
activeRecipe("org.openrewrite.staticanalysis.SimplifyBooleanExpression")
276+
activeRecipe("org.openrewrite.staticanalysis.SimplifyBooleanReturn")
277+
activeRecipe("org.openrewrite.staticanalysis.StaticMethodNotFinal")
278+
activeRecipe("org.openrewrite.staticanalysis.NoToStringOnStringType")
279+
activeRecipe("org.openrewrite.staticanalysis.UnnecessaryCloseInTryWithResources")
280+
activeRecipe("org.openrewrite.staticanalysis.UnnecessaryExplicitTypeArguments")
281+
activeRecipe("org.openrewrite.staticanalysis.UnnecessaryReturnAsLastStatement")
282+
activeRecipe("org.openrewrite.staticanalysis.UnnecessaryThrows")
283+
activeRecipe("org.openrewrite.staticanalysis.UnwrapRepeatableAnnotations")
284+
// activeRecipe("org.openrewrite.staticanalysis.UnwrapElseAfterReturn") // kinda annoying when I want to pick the style on a per if-else statement basis
285+
activeRecipe("org.openrewrite.staticanalysis.UsePortableNewlines")
286+
// activeRecipe("org.openrewrite.staticanalysis.UseCollectionInterfaces") // stops people from using something like an ArrayList in a return type // TODO enable
287+
// activeRecipe("org.openrewrite.staticanalysis.IsEmptyCallOnCollections") // eventually enable this, but first update some tests
288+
activeRecipe("org.openrewrite.staticanalysis.NoEmptyCollectionWithRawType")
289+
activeRecipe("org.openrewrite.staticanalysis.ReplaceCollectionToArrayArgWithEmptyArray")
290+
activeRecipe("org.openrewrite.staticanalysis.UseMapContainsKey")
291+
activeRecipe("org.openrewrite.staticanalysis.UseStandardCharset")
292+
activeRecipe("org.openrewrite.staticanalysis.EqualsToContentEquals")
293+
activeRecipe("org.openrewrite.staticanalysis.StringLiteralEquality")
294+
activeRecipe("org.openrewrite.staticanalysis.UseStringReplace")
295+
activeRecipe("org.openrewrite.staticanalysis.UseSystemLineSeparator")
296+
activeRecipe("org.openrewrite.staticanalysis.NoEqualityInForCondition")
297+
// consider https://docs.openrewrite.org/recipes/staticanalysis/explicitlambdaargumenttypes later
298+
activeRecipe("org.openrewrite.staticanalysis.IndexOfChecksShouldUseAStartPosition")
299+
activeRecipe("org.openrewrite.staticanalysis.PrimitiveWrapperClassConstructorToValueOf")
300+
activeRecipe("org.openrewrite.staticanalysis.RemoveHashCodeCallsFromArrayInstances")
301+
activeRecipe("org.openrewrite.staticanalysis.IndexOfReplaceableByContains")
302+
activeRecipe("org.openrewrite.staticanalysis.BigDecimalDoubleConstructorRecipe")
240303

241-
// TODO add more
242304
}

client/src/main/java/me/retrodaredevil/solarthing/actions/chatbot/SlackChatBotAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ private void handle(EventsApiEnvelope eventsApiEnvelope) {
178178
}
179179
}
180180
private static Instant epochSecondsToInstant(BigDecimal timestampBigDecimal) {
181-
long nanos = timestampBigDecimal.multiply(new BigDecimal(1_000_000)).remainder(new BigDecimal(1000)).longValue() * 1000;
181+
long nanos = timestampBigDecimal.multiply(BigDecimal.valueOf(1_000_000)).remainder(BigDecimal.valueOf(1000)).longValue() * 1000;
182182
// convert epoch millis to milliseconds, then add additional nanoseconds
183-
return Instant.ofEpochMilli(timestampBigDecimal.multiply(new BigDecimal(1000)).longValue())
183+
return Instant.ofEpochMilli(timestampBigDecimal.multiply(BigDecimal.valueOf(1000)).longValue())
184184
.plusNanos(nanos);
185185
}
186186

client/src/main/java/me/retrodaredevil/solarthing/program/subprogram/pvoutput/PVOutputHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,17 @@ private static boolean isGoodReading(TemperatureCelsiusProvider temperatureCelsi
117117
int removeAmount = uniqueReadings.size() / 7 + 1; // remove at least 1 set of outliers. For every 7 unique readings, remove another set
118118
for (int i = 0; i < removeAmount; i++) {
119119
// remove outliers
120-
uniqueReadings.remove(uniqueReadings.first());
120+
uniqueReadings.remove(uniqueReadings.getFirst());
121121
if (!uniqueReadings.isEmpty()) { // need to make this check because it's possible that the size is 1 before removing the first element
122-
uniqueReadings.remove(uniqueReadings.last());
122+
uniqueReadings.remove(uniqueReadings.getLast());
123123
}
124124
}
125125
if (uniqueReadings.isEmpty()) {
126126
// better safe than sorry
127127
return false;
128128
}
129-
float firstReading = uniqueReadings.first();
130-
float lastReading = uniqueReadings.last();
129+
float firstReading = uniqueReadings.getFirst();
130+
float lastReading = uniqueReadings.getLast();
131131
return temperatureCelsius > firstReading - 4.0f && temperatureCelsius < lastReading + 4.0f;
132132
}
133133
private static AddStatusParametersBuilder createStatusBuilder(ZoneId zoneId, long dateMillis) {

common/src/main/java/me/retrodaredevil/solarthing/actions/mate/ACModeActionNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public ACModeActionNode(ACMode acMode, boolean not) {
3737
this.not = not;
3838
}
3939
private static ACMode parseMode(String modeName) {
40-
modeName = modeName.replaceAll(" ", "").toLowerCase(Locale.ENGLISH);
40+
modeName = modeName.replace(" ", "").toLowerCase(Locale.ENGLISH);
4141
return switch (modeName) {
4242
case "noac" -> ACMode.NO_AC;
4343
case "acdrop" -> ACMode.AC_DROP;

common/src/main/java/me/retrodaredevil/solarthing/actions/mate/FXOperationalModeActionNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public static FXOperationalModeActionNode create(@JsonProperty(value = "mode", r
4141
}
4242
private static OperationalMode parseMode(String modeString) {
4343
requireNonNull(modeString);
44-
modeString = modeString.replaceAll(" ", "");
44+
modeString = modeString.replace(" ", "");
4545
for (OperationalMode mode : OperationalMode.values()) {
46-
if (mode.getModeName().replaceAll(" ", "").equalsIgnoreCase(modeString)) {
46+
if (mode.getModeName().replace(" ", "").equalsIgnoreCase(modeString)) {
4747
return mode;
4848
}
4949
}

core/src/main/java/me/retrodaredevil/solarthing/misc/weather/W1TemperatureListUpdater.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void receive(List<Packet> packets) {
4444
long startTimeNanos = System.nanoTime();
4545
final String name;
4646
try {
47-
name = readContents(nameFile).replaceAll("\n", ""); // remove new line at end
47+
name = readContents(nameFile).replace("\n", ""); // remove new line at end
4848
} catch (FileNotFoundException e){
4949
LOGGER.error("name file does not exist. file: " + nameFile);
5050
return;

core/src/main/java/me/retrodaredevil/solarthing/util/TimeUtil.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static String informalDurationToFormal(String informalDuration) {
4343
.replaceAll("MINUTES|MINUTE", "M")
4444
.replaceAll("HOURS|HOUR", "H")
4545
.replaceAll("DAYS|DAY", "D")
46-
.replaceAll("AND", "")
46+
.replace("AND", "")
4747
;
4848
if (!formalDuration.startsWith("P")) { // Make the format of the string we send lenient
4949
if (formalDuration.contains("T")) {
@@ -52,7 +52,7 @@ public static String informalDurationToFormal(String informalDuration) {
5252
formalDuration = "PT" + formalDuration;
5353
}
5454
}
55-
formalDuration = formalDuration.replaceAll(" ", "");
55+
formalDuration = formalDuration.replace(" ", "");
5656
return formalDuration;
5757
}
5858
public static @Nullable Duration lenientParseDurationOrNull(String informalDuration) {
@@ -74,9 +74,9 @@ public static String instantToSlackDateSeconds(Instant instant, String fallback)
7474
public static String slackEscape(String messageToEscape) {
7575
// https://api.slack.com/reference/surfaces/formatting#escaping
7676
return messageToEscape
77-
.replaceAll("&", "&amp;")
78-
.replaceAll("<", "&lt;")
79-
.replaceAll(">", "&gt;")
77+
.replace("&", "&amp;")
78+
.replace("<", "&lt;")
79+
.replace(">", "&gt;")
8080
;
8181
}
8282
}

server/src/main/java/me/retrodaredevil/solarthing/rest/graphql/service/SolarThingGraphQLBatteryRecordService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public SolarThingBatteryEstimate(List<IdentificationCacheDataPacket<BatteryRecor
105105
if (data.isEmpty()) {
106106
return Collections.emptyList();
107107
}
108-
var first = data.get(0);
109-
var last = data.get(data.size() - 1);
108+
var first = data.getFirst();
109+
var last = data.getLast();
110110

111111
int lastFirstIndex = data.size();
112112
long lastStartDateMillis = last.getPeriodEndDateMillis();

server/src/main/java/me/retrodaredevil/solarthing/rest/graphql/service/SolarThingGraphQLDailyService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ private <T extends Identifiable & DailyData> List<DataNode<Float>> getPoints(Cla
126126
return new ArrayList<>(r);
127127
}
128128
private <T extends DailyData> void addAllPoints(Collection<? super DataNode<Float>> nodesOut, List<TimestampedPacket<T>> timestampedPackets, List<AccumulationPair<T>> accumulationPairs, String sourceId, int fragmentId, Function<T, Float> totalGetter) {
129-
T firstPacket = timestampedPackets.get(0).getPacket();
129+
T firstPacket = timestampedPackets.getFirst().getPacket();
130130
List<AccumulationCalc.SumNode<FloatAccumulationValue>> sumNodes = AccumulationCalc.getTotals(accumulationPairs, FloatAccumulationValue.convert(totalGetter), timestampedPackets, FloatAccumulationValueFactory.getInstance());
131131
for (AccumulationCalc.SumNode<FloatAccumulationValue> sumNode : sumNodes) {
132132
nodesOut.add(new DataNode<>(sumNode.getSum().getValue(), firstPacket, sumNode.getDateMillis(), sourceId, fragmentId));
133133
}
134134
}
135135
private <T extends DailyData> void addDayPoints(Collection<? super DataNode<Float>> nodesOut, List<TimestampedPacket<T>> timestampedPackets, List<AccumulationPair<T>> accumulationPairs, String sourceId, int fragmentId, long dayStartTimeMillis, Function<T, Float> totalGetter) {
136-
T firstPacket = timestampedPackets.get(0).getPacket();
136+
T firstPacket = timestampedPackets.getFirst().getPacket();
137137
float total = AccumulationCalc.getTotal(accumulationPairs, FloatAccumulationValue.convert(totalGetter), FloatAccumulationValueFactory.getInstance()).getValue();
138138
nodesOut.add(new DataNode<>(total, firstPacket, dayStartTimeMillis, sourceId, fragmentId));
139139
}

0 commit comments

Comments
 (0)