Skip to content

Commit

Permalink
Code quality improvements surfaced by IntelliJ.
Browse files Browse the repository at this point in the history
  • Loading branch information
msqr committed Feb 3, 2025
1 parent fd42603 commit c786597
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -99,7 +100,7 @@ public class AsyncDatumCollector implements CacheEntryCreatedListener<Serializab
/** The {@code queueSize} property default value. */
public static final int DEFAULT_QUEUE_SIZE = 200;

/** The {@code shtudownWaitSecs} default value. */
/** The {@code shutdownWaitSecs} default value. */
public static final int DEFAULT_SHUTDOWN_WAIT_SECS = 30;

/** The {@code datumCacheRemovalAlertThreshold} default value. */
Expand Down Expand Up @@ -221,7 +222,7 @@ public AsyncDatumCollector(Cache<Serializable, Serializable> datumCache, DatumWr
this.stats = requireNonNullArgument(stats, "stats");
this.concurrency = DEFAULT_CONCURRENCY;
this.shutdownWaitSecs = DEFAULT_SHUTDOWN_WAIT_SECS;
this.listenerConfiguration = new MutableCacheEntryListenerConfiguration<Serializable, Serializable>(
this.listenerConfiguration = new MutableCacheEntryListenerConfiguration<>(
new SingletonFactory<CacheEntryListener<Serializable, Serializable>>(this), null, false,
false);
setQueueSize(DEFAULT_QUEUE_SIZE);
Expand Down Expand Up @@ -317,8 +318,7 @@ public Result performPingTest() throws Exception {
for ( BasicCount s : BasicCount.values() ) {
statMap.put(s.toString(), stats.get(s));
}
if ( datumCache instanceof BufferingDelegatingCache ) {
BufferingDelegatingCache<Serializable, Serializable> buf = (BufferingDelegatingCache<Serializable, Serializable>) datumCache;
if ( datumCache instanceof BufferingDelegatingCache<Serializable, Serializable> buf ) {
statMap.put("BufferSize", buf.getInternalSize());
statMap.put("BufferCapacity", buf.getInternalCapacity());
statMap.put("BufferWatermark", buf.getInternalSizeWatermark());
Expand Down Expand Up @@ -504,7 +504,7 @@ public void onRemoved(
long c = stats.get(BasicCount.BufferRemovals);
if ( stats.getLogFrequency() > 0 && ((c % stats.getLogFrequency()) == 0) ) {
Set<Serializable> allKeys = StreamSupport.stream(datumCache.spliterator(), false)
.filter(e -> e != null).map(e -> e.getKey()).collect(Collectors.toSet());
.filter(Objects::nonNull).map(Entry::getKey).collect(Collectors.toSet());
log.trace("Datum cache keys: {}", allKeys);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ private Map<String, List<Datum>> sortedDatumStreams() {
map.computeIfAbsent(d.getSourceId(), k -> new ArrayList<>(8)).add(d);
}
for ( List<Datum> list : map.values() ) {
Collections.sort(list, (l, r) -> {
return r.getTimestamp().compareTo(l.getTimestamp());
});
list.sort((l, r) -> r.getTimestamp().compareTo(l.getTimestamp()));
}
timeSortedDatumBySource = map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
package net.solarnetwork.central.datum.support;

import java.math.BigDecimal;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.springframework.util.PathMatcher;
Expand Down Expand Up @@ -64,8 +63,8 @@ private DatumUtils() {
* a default value to use if {@code o} is <em>null</em> or if any
* error occurs serializing the object to JSON
* @return the JSON string
* @since 1.1
* @see JsonUtils#getJSONString(Object, String)
* @since 1.1
*/
public static String getJSONString(final Object o, final String defaultValue) {
return JsonUtils.getJSONString(o, defaultValue);
Expand All @@ -85,8 +84,8 @@ public static String getJSONString(final Object o, final String defaultValue) {
* @param clazz
* the type of Object to map the JSON into
* @return the object
* @since 1.1
* @see JsonUtils#getJSONString(Object, String)
* @since 1.1
*/
public static <T> T getObjectFromJSON(final String json, Class<T> clazz) {
return JsonUtils.getObjectFromJSON(json, clazz);
Expand Down Expand Up @@ -115,12 +114,7 @@ public static Set<NodeSourcePK> filterNodeSources(Set<NodeSourcePK> sources, Pat
|| !pathMatcher.isPattern(pattern) ) {
return sources;
}
for ( Iterator<NodeSourcePK> itr = sources.iterator(); itr.hasNext(); ) {
NodeSourcePK pk = itr.next();
if ( !pathMatcher.match(pattern, pk.getSourceId()) ) {
itr.remove();
}
}
sources.removeIf(pk -> !pathMatcher.match(pattern, pk.getSourceId()));
return sources;
}

Expand All @@ -147,12 +141,7 @@ public static Set<String> filterSources(Set<String> sources, PathMatcher pathMat
|| !pathMatcher.isPattern(pattern) ) {
return sources;
}
for ( Iterator<String> itr = sources.iterator(); itr.hasNext(); ) {
String source = itr.next();
if ( !pathMatcher.match(pattern, source) ) {
itr.remove();
}
}
sources.removeIf(source -> !pathMatcher.match(pattern, source));
return sources;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/* ==================================================================
* GeneralLocationDatumMapPropertySerializer.java - Oct 17, 2014 2:31:27 PM
*
*
* Copyright 2007-2014 SolarNetwork.net Dev Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
* ==================================================================
*/
Expand All @@ -35,7 +35,7 @@
* {@link ReportingDatum} API is also supported (those properties will be added
* to the output if a {@link GeneralLocationDatum} subclass implements that
* interface).
*
*
* @author matt
* @version 2.0
*/
Expand All @@ -44,10 +44,9 @@ public class GeneralLocationDatumMapPropertySerializer implements PropertySerial
@Override
public Object serialize(Object data, String propertyName, Object propertyValue) {
GeneralLocationDatum datum = (GeneralLocationDatum) propertyValue;
Map<String, Object> props = new LinkedHashMap<String, Object>(8);
Map<String, Object> props = new LinkedHashMap<>(8);
props.put("created", datum.getCreated());
if ( datum instanceof ReportingDatum ) {
ReportingDatum rd = (ReportingDatum) datum;
if ( datum instanceof ReportingDatum rd ) {
props.put("localDate", rd.getLocalDate());
props.put("localTime", rd.getLocalTime());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/* ==================================================================
* GeneralNodeDatumMapPropertySerializer.java - Sep 5, 2014 7:12:44 AM
*
*
* Copyright 2007-2014 SolarNetwork.net Dev Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
* ==================================================================
*/
Expand All @@ -33,17 +33,17 @@

/**
* Serialize a {@link GeneralNodeDatum} to a {@code Map}.
*
*
* <p>
* The {@link ReportingDatum} API is also supported (those properties will be
* added to the output if a {@link GeneralNodeDatum} subclass implements that
* interface). Similarly the {@link ReadingDatum} API is supported and all start
* and final properties will be added to the resulting map, adding the
* interface). Similarly, the {@link ReadingDatum} API is supported and all
* start and final properties will be added to the resulting map, adding the
* {@link ReadingDatum#START_PROPERTY_SUFFIX} and
* {@link ReadingDatum#FINAL_PROPERTY_SUFFIX} property name suffix as
* appropriate.
* </p>
*
*
* @author matt
* @version 2.0
*/
Expand All @@ -52,15 +52,13 @@ public class GeneralNodeDatumMapPropertySerializer implements PropertySerializer
@Override
public Object serialize(Object data, String propertyName, Object propertyValue) {
GeneralNodeDatum datum = (GeneralNodeDatum) propertyValue;
Map<String, Object> props = new LinkedHashMap<String, Object>(8);
Map<String, Object> props = new LinkedHashMap<>(8);
props.put("created", datum.getCreated());
if ( datum instanceof ReportingDatum ) {
ReportingDatum rd = (ReportingDatum) datum;
if ( datum instanceof ReportingDatum rd ) {
props.put("localDate", rd.getLocalDate());
props.put("localTime", rd.getLocalTime());
}
if ( datum instanceof ReadingDatum ) {
ReadingDatum rd = (ReadingDatum) datum;
if ( datum instanceof ReadingDatum rd ) {
Map<String, ?> dataStart = rd.getSampleDataStart();
if ( dataStart != null ) {
for ( Map.Entry<String, ?> me : dataStart.entrySet() ) {
Expand Down

0 comments on commit c786597

Please sign in to comment.