Skip to content

Commit

Permalink
[SONAR] Cleanup
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
hansva committed Sep 30, 2024
1 parent 275aa86 commit 83ee689
Show file tree
Hide file tree
Showing 127 changed files with 498 additions and 557 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/apache/hop/core/DbCacheEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public int hashCode() {

@Override
public boolean equals(Object o) {
if (o instanceof DbCacheEntry) {
DbCacheEntry obj = (DbCacheEntry) o;
if (o instanceof DbCacheEntry dbCacheEntry) {
DbCacheEntry obj = dbCacheEntry;

return dbname.equalsIgnoreCase(obj.dbname) && sql.equalsIgnoreCase(obj.sql);
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/org/apache/hop/core/config/HopConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ public static boolean readOptionBoolean(String optionKey, boolean defaultValue)
if (Utils.isEmpty(value.toString())) {
return defaultValue;
}
if (value instanceof Boolean) {
return (Boolean) value;
if (value instanceof Boolean bool) {
return bool;
}
if (value instanceof Integer) {
return ((Integer) value) != 0;
if (value instanceof Integer integer) {
return integer != 0;
}
String str = value.toString();
return Const.toBoolean(str);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/apache/hop/core/database/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -1300,8 +1300,8 @@ public void emptyAndCommit(
public static HopDatabaseBatchException createHopDatabaseBatchException(
String message, SQLException ex) {
HopDatabaseBatchException kdbe = new HopDatabaseBatchException(message, ex);
if (ex instanceof BatchUpdateException) {
kdbe.setUpdateCounts(((BatchUpdateException) ex).getUpdateCounts());
if (ex instanceof BatchUpdateException batchUpdateException) {
kdbe.setUpdateCounts(batchUpdateException.getUpdateCounts());
} else {
// Null update count forces rollback of batch
kdbe.setUpdateCounts(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
return obj instanceof DatabaseMeta && getName().equals(((DatabaseMeta) obj).getName());
return obj instanceof DatabaseMeta databaseMeta && getName().equals(databaseMeta.getName());
}

public String getURL(IVariables variables) throws HopDatabaseException {
Expand Down Expand Up @@ -930,8 +930,8 @@ public static final Map<String, IDatabase> getIDatabaseMap() {
clearDatabaseInterfacesMap();
// doCreate() above doesn't declare any exceptions so anything that comes out SHOULD be a
// runtime exception
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
if (e instanceof RuntimeException runtimeException) {
throw runtimeException;
} else {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ public void eventAdded(HopLoggingEvent event) {

try {
Object messageObject = event.getMessage();
if (messageObject instanceof LogMessage) {
if (messageObject instanceof LogMessage logMessage) {
boolean logToFile = false;

if (logChannelId == null) {
logToFile = true;
} else {
LogMessage message = (LogMessage) messageObject;
LogMessage message = logMessage;
// This should be fast enough cause cached.
List<String> logChannelChildren =
LoggingRegistry.getInstance().getLogChannelChildren(logChannelId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public String format(HopLoggingEvent event) {
}

Object object = event.getMessage();
if (object instanceof LogMessage) {
LogMessage message = (LogMessage) object;
if (object instanceof LogMessage logMessage) {
LogMessage message = logMessage;

String[] parts =
message.getMessage() == null ? new String[] {} : message.getMessage().split(Const.CR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public class LoggingObject implements ILoggingObject {
private boolean forcingSeparateLogging;

public LoggingObject(Object object) {
if (object instanceof ILoggingObject) {
grabLoggingObjectInformation((ILoggingObject) object);
if (object instanceof ILoggingObject iLoggingObject) {
grabLoggingObjectInformation(iLoggingObject);
} else {
grabObjectInformation(object);
}
Expand Down Expand Up @@ -169,9 +169,9 @@ private void getParentLoggingObject(Object parentObject) {
return;
}

if (parentObject instanceof ILoggingObject) {
if (parentObject instanceof ILoggingObject iLoggingObject) {

parent = (ILoggingObject) parentObject;
parent = iLoggingObject;

// See if the parent is already in the logging registry.
// This prevents the logging registry from hanging onto Pipeline and Job objects that would
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public Slf4jLoggingEventListener() {
public void eventAdded(HopLoggingEvent event) {
Object messageObject = event.getMessage();
checkNotNull(messageObject, "Expected log message to be defined.");
if (messageObject instanceof LogMessage) {
LogMessage message = (LogMessage) messageObject;
if (messageObject instanceof LogMessage logMessage) {
LogMessage message = logMessage;
ILoggingObject loggingObject = logObjProvider.apply(message.getLogChannelId());

if (loggingObject == null) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/apache/hop/core/plugins/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public String toString() {

@Override
public boolean equals(Object obj) {
return (obj != null) && (obj instanceof Plugin) && compareTo((Plugin) obj) == 0;
return (obj != null) && (obj instanceof Plugin plugin) && compareTo(plugin) == 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ public <T> T loadClass(IPlugin plugin, Class<T> pluginClass) throws HopPluginExc
PKG, "PluginRegistry.RuntimeError.NoValidTransformOrPlugin.PLUGINREGISTRY001"));
}

if (plugin instanceof IClassLoadingPlugin) {
T aClass = ((IClassLoadingPlugin) plugin).loadClass(pluginClass);
if (plugin instanceof IClassLoadingPlugin iClassLoadingPlugin) {
T aClass = iClassLoadingPlugin.loadClass(pluginClass);
if (aClass == null) {
throw new HopPluginClassMapException(
BaseMessages.getString(
Expand Down Expand Up @@ -804,9 +804,9 @@ public <T> T getClass(IPlugin plugin, String className) throws HopPluginExceptio
try {
if (plugin.isNativePlugin()) {
return (T) Class.forName(className);
} else if ((plugin instanceof IClassLoadingPlugin)
&& ((IClassLoadingPlugin) plugin).getClassLoader() != null) {
return (T) ((IClassLoadingPlugin) plugin).getClassLoader().loadClass(className);
} else if ((plugin instanceof IClassLoadingPlugin iClassLoadingPlugin)
&& iClassLoadingPlugin.getClassLoader() != null) {
return (T) iClassLoadingPlugin.getClassLoader().loadClass(className);
} else {
URLClassLoader ucl;
lock.writeLock().lock();
Expand Down Expand Up @@ -931,8 +931,9 @@ public ClassLoader getClassLoader(IPlugin plugin) throws HopPluginException {
} else {
ucl = classLoaders.get(plugin);
if (ucl == null) {
if (plugin.getLibraries().isEmpty() && plugin instanceof IClassLoadingPlugin) {
return ((IClassLoadingPlugin) plugin).getClassLoader();
if (plugin.getLibraries().isEmpty()
&& plugin instanceof IClassLoadingPlugin iClassLoadingPlugin) {
return iClassLoadingPlugin.getClassLoader();
}
ucl = createClassLoader(plugin);
classLoaders.put(plugin, ucl); // save for later use...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public ValueMetaBase(Node node) throws HopException {
* loadMetaData() method.
*/
@Deprecated(since = "2.0")
public ValueMetaBase(DataInputStream inputStream) throws HopFileException, HopEofException {
public ValueMetaBase(DataInputStream inputStream) throws HopFileException {
this();
try {
type = inputStream.readInt();
Expand Down Expand Up @@ -3421,7 +3421,7 @@ public void writeMeta(DataOutputStream outputStream) throws HopFileException {
* @throws HopEofException If we reached the end of the stream
*/
@Override
public void readMetaData(DataInputStream inputStream) throws HopFileException, HopEofException {
public void readMetaData(DataInputStream inputStream) throws HopFileException {

// Loading the type is not handled here, this should be read from the stream previously!
//
Expand Down Expand Up @@ -5598,22 +5598,20 @@ public void setPreparedStatementValue(
}
}
} else {
if (data instanceof Timestamp) {
if (data instanceof Timestamp timestamp) {
// Preserve ns precision!
//
if (databaseMeta.getIDatabase().isDuckDbVariant()) {
// As of DuckDB JDBC 0.10.0
// setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
// is not yet implemented
preparedStatement.setTimestamp(index, (Timestamp) data);
preparedStatement.setTimestamp(index, timestamp);
} else {
if (this.getDateFormatTimeZone() == null) {
preparedStatement.setTimestamp(index, (Timestamp) data);
preparedStatement.setTimestamp(index, timestamp);
} else {
preparedStatement.setTimestamp(
index,
(Timestamp) data,
Calendar.getInstance(this.getDateFormatTimeZone()));
index, timestamp, Calendar.getInstance(this.getDateFormatTimeZone()));
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ public StringBuffer format(Date timestamp, StringBuffer toAppendTo, FieldPositio
StringBuffer dateBuffer;
String nan;

if (timestamp instanceof Timestamp) {
Timestamp tmp = (Timestamp) timestamp;
if (timestamp instanceof Timestamp timestamp1) {
Timestamp tmp = timestamp1;
Date date = new Date(tmp.getTime());
dateBuffer = super.format(date, toAppendTo, pos);
nan = formatNanoseconds(tmp.getNanos());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ public static SSLContext getSslContextWithTrustStoreFile(
// Get hold of the default trust manager
X509TrustManager defaultTm = null;
for (TrustManager tm : tmf.getTrustManagers()) {
if (tm instanceof X509TrustManager) {
defaultTm = (X509TrustManager) tm;
if (tm instanceof X509TrustManager x509TrustManager) {
defaultTm = x509TrustManager;
break;
}
}
Expand All @@ -223,8 +223,8 @@ public static SSLContext getSslContextWithTrustStoreFile(
// Get hold of the default trust manager
X509TrustManager trustManager = null;
for (TrustManager tm : tmf.getTrustManagers()) {
if (tm instanceof X509TrustManager) {
trustManager = (X509TrustManager) tm;
if (tm instanceof X509TrustManager x509TrustManager) {
trustManager = x509TrustManager;
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public Object createObject(String id, Object parentObject) throws HopException {
// By default, inherit variables from a parent object.
//
if (parentObject != null) {
if (parentObject instanceof IVariables) {
if (object instanceof IVariables) {
((IVariables) object).initializeFrom((IVariables) parentObject);
if (parentObject instanceof IVariables iVariablesParentObject) {
if (object instanceof IVariables iVariablesObject) {
iVariablesObject.initializeFrom(iVariablesParentObject);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ public T load(String name) throws HopException {
* @param t
*/
private void inheritVariables(T t) {
if (t instanceof IVariables) {
((IVariables) t).initializeFrom(variables);
if (t instanceof IVariables iVariables) {
iVariables.initializeFrom(variables);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public T load(String name) throws HopException {
}
T t = objectMap.get(name);

if (t instanceof IVariables) {
((IVariables) t).initializeFrom(variables);
if (t instanceof IVariables iVariables) {
iVariables.initializeFrom(variables);
}

// Remember where this came from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,19 @@ private static String serializeObjectToXml(
if (value == null) {
xml += XmlHandler.addTagValue(tag, (String) null);
} else {
if (value instanceof String) {
if (value instanceof String string) {
// Hang on, is this a password?
//
if (password) {
xml +=
XmlHandler.addTagValue(tag, Encr.encryptPasswordIfNotUsingVariables((String) value));
xml += XmlHandler.addTagValue(tag, Encr.encryptPasswordIfNotUsingVariables(string));
} else {
xml += XmlHandler.addTagValue(tag, (String) value);
xml += XmlHandler.addTagValue(tag, string);
}
} else if (value instanceof Boolean) {
xml += XmlHandler.addTagValue(tag, (Boolean) value);
} else if (value instanceof Integer) {
} else if (value instanceof Boolean bool) {
xml += XmlHandler.addTagValue(tag, bool);
} else if (value instanceof Integer integer) {
if (intCodeConverterClass.equals(IIntCodeConverter.None.class)) {
xml += XmlHandler.addTagValue(tag, (Integer) value);
xml += XmlHandler.addTagValue(tag, integer);
} else {
try {
IIntCodeConverter converter = intCodeConverterClass.getConstructor().newInstance();
Expand All @@ -164,17 +163,17 @@ private static String serializeObjectToXml(
e);
}
}
} else if (value instanceof Long) {
xml += XmlHandler.addTagValue(tag, (Long) value);
} else if (value instanceof Date) {
xml += XmlHandler.addTagValue(tag, (Date) value);
} else if (value instanceof Long longValue) {
xml += XmlHandler.addTagValue(tag, longValue);
} else if (value instanceof Date date) {
xml += XmlHandler.addTagValue(tag, date);
} else if (value.getClass().isEnum()) {
if (storeWithCode) {
xml += XmlHandler.addTagValue(tag, ((IEnumHasCode) value).getCode());
} else {
xml += XmlHandler.addTagValue(tag, ((Enum) value).name());
}
} else if (value instanceof java.util.List) {
} else if (value instanceof java.util.List list) {

// Serialize a list of values
// Use the key on the annotation to open a new block
Expand All @@ -186,7 +185,7 @@ private static String serializeObjectToXml(

// Add the elements...
//
List listItems = (List) value;
List listItems = list;
for (Object listItem : listItems) {
xml +=
serializeObjectToXml(
Expand Down
7 changes: 3 additions & 4 deletions engine/src/main/java/org/apache/hop/config/HopConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.hop.core.encryption.Encr;
import org.apache.hop.core.encryption.HopTwoWayPasswordEncoder;
import org.apache.hop.core.encryption.ITwoWayPasswordEncoder;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.logging.LogChannel;
import org.apache.hop.core.logging.LogLevel;
import org.apache.hop.core.plugins.IPlugin;
Expand Down Expand Up @@ -89,8 +88,8 @@ public void run() {
Map<String, Object> mixins = cmd.getMixins();
for (String key : mixins.keySet()) {
Object mixin = mixins.get(key);
if (mixin instanceof IConfigOptions) {
IConfigOptions configOptions = (IConfigOptions) mixin;
if (mixin instanceof IConfigOptions iConfigOptions) {
IConfigOptions configOptions = iConfigOptions;

actionTaken = configOptions.handleOption(log, this, variables) || actionTaken;
}
Expand All @@ -109,7 +108,7 @@ private LogLevel determineLogLevel() {
return LogLevel.lookupCode(variables.resolve(level));
}

private void buildMetadataProvider() throws HopException {
private void buildMetadataProvider() {
List<IHopMetadataProvider> providers = new ArrayList<>();
String folder = variables.getVariable(Const.HOP_METADATA_FOLDER);
if (StringUtils.isEmpty(folder)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public Collection<Object> values() {
@Override
public String getProperty(String key) {
Object oval = storageMap.get(key);
String sval = (oval instanceof String) ? (String) oval : null;
String sval = (oval instanceof String string) ? string : null;
return ((sval == null) && (defaults != null)) ? defaults.getProperty(key) : sval;
}

Expand Down Expand Up @@ -337,7 +337,7 @@ public synchronized void storeToXML(OutputStream os, String comment, String enco
*/
public static ConcurrentMapProperties convertProperties(Properties props) {
if (props != null) {
if (!(props instanceof ConcurrentMapProperties)) {
if (!(props instanceof ConcurrentMapProperties concurrentMapProperties)) {
ConcurrentMapProperties result = new ConcurrentMapProperties(null);
synchronized (props) {
for (String prop : props.stringPropertyNames()) {
Expand All @@ -347,7 +347,7 @@ public static ConcurrentMapProperties convertProperties(Properties props) {
return result;
} else {
// Already a ConcurrentMapProperties
return (ConcurrentMapProperties) props;
return concurrentMapProperties;
}
}
return null;
Expand Down
Loading

0 comments on commit 83ee689

Please sign in to comment.