Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SONAR] cleanup #4352

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions core/src/main/java/org/apache/hop/core/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -2355,12 +2355,10 @@ public static String getClassicStackTrace(Throwable e) {
}

public static String getSimpleStackTrace(Throwable aThrowable) {
String result =
ExceptionUtils.getMessage(aThrowable)
+ Const.CR
+ "Root cause: "
+ ExceptionUtils.getRootCauseMessage(aThrowable);
return result;
return ExceptionUtils.getMessage(aThrowable)
+ Const.CR
+ "Root cause: "
+ ExceptionUtils.getRootCauseMessage(aThrowable);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/apache/hop/core/Counters.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public void clear() {

public Counter getCounter(String name) {
synchronized (lock) {
Counter found = counterMap.get(name);
return found;
return counterMap.get(name);
}
}

Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/apache/hop/core/QueueRowSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public QueueRowSet() {

@Override
public Object[] getRow() {
Object[] retRow = buffer.pollFirst();
return retRow;
return buffer.pollFirst();
}

@Override
Expand Down
19 changes: 8 additions & 11 deletions core/src/main/java/org/apache/hop/core/ResultFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,14 @@ public RowMetaAndData getRow() {
@JsonIgnore
public String getXml() {

String xml =
XmlHandler.openTag(XML_TAG)
+ XmlHandler.addTagValue("type", getTypeCode())
+ XmlHandler.addTagValue("file", file.getName().toString())
+ XmlHandler.addTagValue(CONST_PARENT_ORIGIN, originParent)
+ XmlHandler.addTagValue(CONST_ORIGIN, origin)
+ XmlHandler.addTagValue(CONST_COMMENT, comment)
+ XmlHandler.addTagValue(CONST_TIMESTAMP, timestamp)
+ XmlHandler.closeTag(XML_TAG);

return xml;
return XmlHandler.openTag(XML_TAG)
+ XmlHandler.addTagValue("type", getTypeCode())
+ XmlHandler.addTagValue("file", file.getName().toString())
+ XmlHandler.addTagValue(CONST_PARENT_ORIGIN, originParent)
+ XmlHandler.addTagValue(CONST_ORIGIN, origin)
+ XmlHandler.addTagValue(CONST_COMMENT, comment)
+ XmlHandler.addTagValue(CONST_TIMESTAMP, timestamp)
+ XmlHandler.closeTag(XML_TAG);
}

public ResultFile(Node node) throws HopFileException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ public Map<String, Object> readFromFile(String filename) throws HopException {
TypeReference<HashMap<String, Object>> typeRef =
new TypeReference<HashMap<String, Object>>() {};
try (InputStream inputStream = HopVfs.getInputStream(file)) {
HashMap<String, Object> configMap = objectMapper.readValue(inputStream, typeRef);
return configMap;
return objectMapper.readValue(inputStream, typeRef);
}
} catch (Exception e) {
throw new HopException("Error reading Hop configuration file " + filename, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public class DatabaseMetaObjectFactory implements IHopMetadataObjectFactory {
public Object createObject(String id, Object parentObject) throws HopException {
PluginRegistry registry = PluginRegistry.getInstance();
IPlugin plugin = registry.findPluginWithId(DatabasePluginType.class, id);
IDatabase iDatabase = (IDatabase) registry.loadClass(plugin);
return iDatabase;
return registry.loadClass(plugin);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ protected String calculateGetterMethod(GuiWidgetElement guiElement, String field
if (StringUtils.isNotEmpty(guiElement.getterMethod())) {
return guiElement.getterMethod();
}
String getter = "get" + StringUtil.initCap(fieldName);
return getter;
return "get" + StringUtil.initCap(fieldName);
}

protected String calculateSetterMethod(GuiWidgetElement guiElement, String fieldName) {
if (StringUtils.isNotEmpty(guiElement.setterMethod())) {
return guiElement.setterMethod();
}
String getter = "set" + StringUtil.initCap(fieldName);
return getter;
return "set" + StringUtil.initCap(fieldName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,7 @@ public Map<String, List<GuiTabItem>> getGuiTabsMap() {
}

public List<GuiTabItem> findGuiTabItems(String parent) {
List<GuiTabItem> guiTabItems = guiTabsMap.get(parent);
return guiTabItems;
return guiTabsMap.get(parent);
}

public void addKeyboardShortcut(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ protected String extractDesc(LoggingPlugin annotation) {

@Override
protected String extractID(LoggingPlugin annotation) {
String id = annotation.id();
return id;
return annotation.id();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,7 @@ public static Object round(IValueMeta metaA, Object dataA, int roundingMode)
*/
public static Object round(IValueMeta metaA, Object dataA, IValueMeta metaB, Object dataB)
throws HopValueException {
final Object r = round(metaA, dataA, metaB, dataB, ROUND_2_MODE);
return r;
return round(metaA, dataA, metaB, dataB, ROUND_2_MODE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ public static String convertGenericRecordToString(GenericRecord genericRecord)
String schemaJson = schema.toString();
String dataJson = genericRecord.toString();

String json = "{ \"schema\" : " + schemaJson + ", \"data\" : " + dataJson + " }";
return json;
return "{ \"schema\" : " + schemaJson + ", \"data\" : " + dataJson + " }";
} catch (Exception e) {
throw new HopValueException(
"Unable to convert an Avro record to a JSON String using the provided schema", e);
Expand Down Expand Up @@ -451,9 +450,8 @@ public Object readData(DataInputStream inputStream)

BinaryDecoder binaryDecoder = DecoderFactory.get().directBinaryDecoder(inputStream, null);
GenericDatumReader<GenericRecord> datumReader = new GenericDatumReader<>(schema);
GenericRecord genericRecord = datumReader.read(null, binaryDecoder);

return genericRecord;
return datumReader.read(null, binaryDecoder);
} catch (EOFException e) {
throw new HopEofException(e);
} catch (SocketTimeoutException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public boolean isDate() {

@Override
public Date getDate(Object object) throws HopValueException {
Timestamp timestamp = getTimestamp(object);
return timestamp;
return getTimestamp(object);
}

@Override
Expand Down Expand Up @@ -321,14 +320,13 @@ public Object convertDataFromString(
// See if we need to convert a null value into a String
// For example, we might want to convert null into "Empty".
//
if (!Utils.isEmpty(ifNull)) {
if (!Utils.isEmpty(ifNull)
&& (Utils.isEmpty(pol)
|| pol.equalsIgnoreCase(Const.rightPad(new StringBuilder(nullValue), pol.length())))) {
// Note that you can't pull the pad method up here as a nullComp variable
// because you could get an NPE since you haven't checked isEmpty(pol)
// yet!
if (Utils.isEmpty(pol)
|| pol.equalsIgnoreCase(Const.rightPad(new StringBuilder(nullValue), pol.length()))) {
pol = ifNull;
}
pol = ifNull;
}

// See if the polled value is empty
Expand Down Expand Up @@ -401,8 +399,8 @@ public Timestamp convertDateToTimestamp(Date date) {
return null;
}
Timestamp result = null;
if (date instanceof Timestamp) {
result = (Timestamp) date;
if (date instanceof Timestamp timestamp) {
result = timestamp;
} else {
result = new Timestamp(date.getTime());
}
Expand Down
16 changes: 7 additions & 9 deletions core/src/main/java/org/apache/hop/core/util/ExecutorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ public class ExecutorUtil {
private ExecutorUtil() {}

private static ExecutorService init() {
ExecutorService executorService =
Executors.newCachedThreadPool(
r -> {
Thread thread = Executors.defaultThreadFactory().newThread(r);
thread.setDaemon(true);
thread.setName(SIMPLE_NAME + " thread " + threadNum.getAndIncrement());
return thread;
});
return executorService;
return Executors.newCachedThreadPool(
r -> {
Thread thread = Executors.defaultThreadFactory().newThread(r);
thread.setDaemon(true);
thread.setName(SIMPLE_NAME + " thread " + threadNum.getAndIncrement());
return thread;
});
}

public static ExecutorService getExecutor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ public static final List<String> getValuesList(
Object singleton = getInstanceMethod.invoke(null, new Object[] {});

Method method = singletonClass.getMethod(methodName);
List<String> values = (List<String>) method.invoke(singleton, new Object[] {});

return values;
return (List<String>) method.invoke(singleton, new Object[] {});
} catch (Exception e) {
throw new HopException(
"Unable to get list of values from class "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ static String calculateString(
ResourceBundle bundle =
getBundle(locale, packageName + "." + bundleName, resourceClass, fallbackOnRoot);
String unformattedString = bundle.getString(key);
String string = MessageFormat.format(unformattedString, parameters);
return string;
return MessageFormat.format(unformattedString, parameters);
} catch (IllegalArgumentException e) {
final StringBuilder msg = new StringBuilder();
msg.append("Format problem with key=[")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ public static final MultiMetadataProvider getStandardHopMetadataProvider(IVariab

public static <T extends IHopMetadata> HopMetadata getHopMetadataAnnotation(
Class<T> managedClass) {
HopMetadata hopMetadata = managedClass.getAnnotation(HopMetadata.class);
return hopMetadata;
return managedClass.getAnnotation(HopMetadata.class);
}

public static String[] getHopMetadataKeys(IHopMetadataProvider provider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void correctLogIdReturned_WhenLogObjectRegisteredAlready() {

String logChanelId = loggingRegistry.registerLoggingSource(child);

assertEquals(logChanelId, LOG_CHANEL_ID_CHILD);
assertEquals(LOG_CHANEL_ID_CHILD, logChanelId);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void testFragmentMerge() {
plugin.merge(fragment);

assertTrue(classMap.containsKey(IPluginTypeListener.class));
assertEquals(libraries.size(), 2);
assertEquals(2, libraries.size());
assertTrue(libraries.contains(Integer.class.getName()));
assertEquals("", plugin.getDescription());
assertEquals(fragment.getImageFile(), plugin.getImageFile());
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/org/apache/hop/core/row/RowMetaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,9 @@ public void testMergeRowMetaWithOriginTransform() throws Exception {
}
}
assertNotNull(found);
assertEquals(found.getOrigin(), "newOriginTransform");
assertEquals("newOriginTransform", found.getOrigin());
assertNotNull(other);
assertEquals(other.getOrigin(), "originTransform");
assertEquals("originTransform", other.getOrigin());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,23 @@ public void testCompare() throws Exception {
Timestamp later = Timestamp.valueOf("2013-12-12 12:12:12.121212");
assertTrue(vm.isSortedAscending());
assertFalse(vm.isSortedDescending());
assertEquals(vm.compare(null, null), 0);
assertEquals(vm.compare(null, earlier), -1);
assertEquals(vm.compare(earlier, null), 1);
assertEquals(vm.compare(earlier, earlier), 0);
assertEquals(vm.compare(earlier, later), -1);
assertEquals(vm.compare(later, earlier), 1);
assertEquals(0, vm.compare(null, null));
assertEquals(-1, vm.compare(null, earlier));
assertEquals(1, vm.compare(earlier, null));
assertEquals(0, vm.compare(earlier, earlier));
assertEquals(-1, vm.compare(earlier, later));
assertEquals(1, vm.compare(later, earlier));

// Check Descending comparison
vm.setSortedDescending(true);
assertFalse(vm.isSortedAscending());
assertTrue(vm.isSortedDescending());
assertEquals(vm.compare(null, null), 0);
assertEquals(vm.compare(null, earlier), 1);
assertEquals(vm.compare(earlier, null), -1);
assertEquals(vm.compare(earlier, earlier), 0);
assertEquals(vm.compare(earlier, later), 1);
assertEquals(vm.compare(later, earlier), -1);
assertEquals(0, vm.compare(null, null));
assertEquals(1, vm.compare(null, earlier));
assertEquals(-1, vm.compare(earlier, null));
assertEquals(0, vm.compare(earlier, earlier));
assertEquals(1, vm.compare(earlier, later));
assertEquals(-1, vm.compare(later, earlier));
}

@Test
Expand All @@ -100,7 +100,7 @@ public void testConvertStringToTimestamp() throws Exception {
}

@Test
public void testConvertTimestampToString() throws Exception {
public void testConvertTimestampToString() {
ValueMetaTimestamp valueMetaTimestamp = new ValueMetaTimestamp();
assertEquals(
"2012/04/05 04:03:02.123456000",
Expand All @@ -116,7 +116,7 @@ public void testConvertTimestampToString() throws Exception {
}

@Test
public void testConvertDateToTimestamp() throws Exception {
public void testConvertDateToTimestamp() {
ValueMetaTimestamp valueMetaTimestamp = new ValueMetaTimestamp();
// Converting date to timestamp
Date date = new Date();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private Callable<Boolean> newCallable() {
for (int i = 0; i < 300; i++) {
String key = "key" + i;
variables.setVariable(key, "value");
assertEquals(variables.resolve("${" + key + "}"), "value");
assertEquals("value", variables.resolve("${" + key + "}"));
}
return true;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ public static IPlugin getTransformPluginForClass(Class<? extends ITransformMeta>

public static Node getTransformXmlNode(TransformMeta transformMeta) throws HopException {
String xml = transformMeta.getXml();
Node transformNode =
XmlHandler.getSubNode(XmlHandler.loadXmlString(xml), TransformMeta.XML_TAG);
return transformNode;
return XmlHandler.getSubNode(XmlHandler.loadXmlString(xml), TransformMeta.XML_TAG);
}

public static void loadTransformMetadata(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ protected void drawNote(NotePadMeta notePadMeta) {
}

protected Point real2screen(int x, int y) {
Point screen = new Point((int) (x + offset.x), (int) (y + offset.y));

return screen;
return new Point((int) (x + offset.x), (int) (y + offset.y));
}

protected Point magnifyPoint(Point p) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ public int getPartition(IVariables variables, IRowMeta rowMeta, Object[] row)
value = valueMeta.hashCode(valueData);
}

int targetLocation = (int) (Math.abs(value) % nrPartitions);

return targetLocation;
return (int) (Math.abs(value) % nrPartitions);
}

@Override
Expand Down
Loading
Loading