Skip to content

Fix maven-bundle-plugin and many Sonarlint fixes #18

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

Merged
merged 3 commits into from
Dec 25, 2020
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.0</version>
<version>3.0.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ public class EBusConfigurationReaderException extends Exception {

private static final long serialVersionUID = 1L;

public EBusConfigurationReaderException(String message, Throwable cause, Object... args) {
public EBusConfigurationReaderException(final String message, final Throwable cause, final Object... args) {
super(String.format(message, args), cause);
}

public EBusConfigurationReaderException(String message, Object... args) {
public EBusConfigurationReaderException(final String message, final Object... args) {
super(MessageFormat.format(message, args));
}

public EBusConfigurationReaderException(String message) {
public EBusConfigurationReaderException(final String message) {
super(message);
}

public EBusConfigurationReaderException(String message, Throwable cause) {
public EBusConfigurationReaderException(final String message, final Throwable cause) {
super(message, cause);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public interface IEBusConfigurationProvider {
* @param configurationId
* @return Returns a configuration label for an id or null if not existent.
*/
public @Nullable String getConfigurationLabel(String configurationId);
public @Nullable String getConfigurationLabel(final String configurationId);

/**
* Returns the input stream for a configuration id or null if not existent.
*
* @param configurationId
* @return Returns the input stream for a configuration id or null if not existent.
*/
public @Nullable InputStream getConfigurationStream(String configurationId);
public @Nullable InputStream getConfigurationStream(final String configurationId);

}
6 changes: 3 additions & 3 deletions src/main/java/de/csdev/ebus/cfg/IEBusConfigurationReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ public interface IEBusConfigurationReader {
* @throws EBusConfigurationReaderException
* @throws IOException
*/
public @Nullable IEBusCommandCollection loadConfigurationCollection(URL url)
public @Nullable IEBusCommandCollection loadConfigurationCollection(final URL url)
throws EBusConfigurationReaderException, IOException;

/**
* @param url
* @return
*/
public List<IEBusCommandCollection> loadConfigurationCollectionBundle(URL url);
public List<IEBusCommandCollection> loadConfigurationCollectionBundle(final URL url);

/**
* Sets the eBUS type registry to use
*
* @param ebusTypes
*/
public void setEBusTypes(EBusTypeRegistry ebusTypes);
public void setEBusTypes(final EBusTypeRegistry ebusTypes);

/**
* Clears all internal states
Expand Down
36 changes: 14 additions & 22 deletions src/main/java/de/csdev/ebus/cfg/std/EBusConfigurationReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public class EBusConfigurationReader implements IEBusConfigurationReader {

private @NonNull EBusTypeRegistry registry;

private @NonNull Map<@NonNull String, @Nullable Collection<@NonNull EBusCommandValue>> templateValueRegistry = new HashMap<@NonNull String, @Nullable Collection<@NonNull EBusCommandValue>>();
private @NonNull Map<@NonNull String, @Nullable Collection<@NonNull EBusCommandValue>> templateBlockRegistry = new HashMap<@NonNull String, @Nullable Collection<@NonNull EBusCommandValue>>();
private @NonNull Map<@NonNull String, @Nullable Collection<@NonNull EBusCommandValue>> templateValueRegistry = new HashMap<>();
private @NonNull Map<@NonNull String, @Nullable Collection<@NonNull EBusCommandValue>> templateBlockRegistry = new HashMap<>();

public EBusConfigurationReader() {
try {
Expand Down Expand Up @@ -108,8 +108,7 @@ public EBusConfigurationReader() {
Type merchantListType = new TypeToken<List<EBusValueDTO>>() {
}.getType();

Gson gson = new Gson();
gson = new GsonBuilder().registerTypeAdapter(merchantListType, new EBusValueJsonDeserializer()).create();
Gson gson = new GsonBuilder().registerTypeAdapter(merchantListType, new EBusValueJsonDeserializer()).create();

MessageDigest md = null;

Expand Down Expand Up @@ -171,7 +170,7 @@ protected void parseTemplateConfiguration(@NonNull EBusCollectionDTO collection)
List<EBusValueDTO> templateValues = templates.getTemplate();
if (templateValues != null) {

Collection<EBusCommandValue> blockList = new ArrayList<EBusCommandValue>();
Collection<EBusCommandValue> blockList = new ArrayList<>();

for (EBusValueDTO value : templateValues) {
if (value != null) {
Expand Down Expand Up @@ -211,11 +210,11 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection

Objects.requireNonNull(commandCollection, "commandCollection");

LinkedHashMap<String, EBusCommandValue> templateMap = new LinkedHashMap<String, EBusCommandValue>();
ArrayList<EBusCommandValue> templateList = new ArrayList<EBusCommandValue>();
LinkedHashMap<String, EBusCommandValue> templateMap = new LinkedHashMap<>();
ArrayList<EBusCommandValue> templateList = new ArrayList<>();

// collect available channels
List<String> methods = new ArrayList<String>();
List<String> methods = new ArrayList<>();
if (commandElement.getGet() != null) {
methods.add("get");
}
Expand Down Expand Up @@ -357,7 +356,7 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection

Objects.requireNonNull(valueDto, "valueDto");

Collection<@NonNull EBusCommandValue> result = new ArrayList<@NonNull EBusCommandValue>();
Collection<@NonNull EBusCommandValue> result = new ArrayList<>();
String typeStr = valueDto.getType();
String collectionId = null;

Expand Down Expand Up @@ -402,7 +401,6 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection

} else if (templateMap != null) {
// return the complete template block from within command block
// templateCollection = templateMap.values();
templateCollection = new ArrayList<>(templateList);

} else {
Expand Down Expand Up @@ -443,7 +441,7 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection

} else if (templateMap != null && templateMap.containsKey(id)) {
// return the complete template block from within command block
templateCollection = new ArrayList<@NonNull EBusCommandValue>();
templateCollection = new ArrayList<>();
templateCollection.add(templateMap.get(id));

} else {
Expand Down Expand Up @@ -474,7 +472,7 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection
// convert static content to bytes

byte[] byteArray = EBusUtils.toByteArray(valueDto.getDefault());
Map<String, Object> properties = new HashMap<String, Object>();
Map<String, Object> properties = new HashMap<>();
properties.put("length", byteArray.length);
final IEBusType<?> typeByte = registry.getType(EBusTypeBytes.TYPE_BYTES, properties);

Expand Down Expand Up @@ -571,7 +569,7 @@ public void setEBusTypes(@NonNull EBusTypeRegistry ebusTypes) {

Objects.requireNonNull(url, "url");

List<@NonNull IEBusCommandCollection> result = new ArrayList<@NonNull IEBusCommandCollection>();
List<@NonNull IEBusCommandCollection> result = new ArrayList<>();

Gson gson = new Gson();
Type type = new TypeToken<Map<String, ?>>() {
Expand All @@ -593,12 +591,10 @@ public void setEBusTypes(@NonNull EBusTypeRegistry ebusTypes) {
try {
logger.debug("Load configuration from url {} ...", fileUrl);
IEBusCommandCollection collection = loadConfigurationCollection(fileUrl);
if (collection != null) {
result.add(collection);
}
result.add(collection);

} catch (EBusConfigurationReaderException e) {
logger.error(e.getMessage() + " (Url: " + fileUrl + ")");
logger.error("{} (url: {})", e.getMessage(), fileUrl);
} catch (IOException e) {
logger.error("error!", e);
}
Expand All @@ -607,11 +603,7 @@ public void setEBusTypes(@NonNull EBusTypeRegistry ebusTypes) {
}
}

} catch (JsonSyntaxException e) {
logger.error("error!", e);
} catch (JsonIOException e) {
logger.error("error!", e);
} catch (IOException e) {
} catch (JsonSyntaxException | JsonIOException | IOException e) {
logger.error("error!", e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public List<EBusValueDTO> deserialize(JsonElement jElement, Type typeOfT, JsonDe
throws JsonParseException {

JsonArray asJsonArray = jElement.getAsJsonArray();
ArrayList<EBusValueDTO> result = new ArrayList<EBusValueDTO>();
ArrayList<EBusValueDTO> result = new ArrayList<>();

ArrayList<String> fields = new ArrayList<String>();
ArrayList<String> fields = new ArrayList<>();
for (Field field : EBusValueDTO.class.getDeclaredFields()) {

SerializedName annotation = field.getAnnotation(SerializedName.class);
Expand Down
52 changes: 20 additions & 32 deletions src/main/java/de/csdev/ebus/client/EBusClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
*/
public class EBusClient {

private static final String LABEL_LISTENER = "listener";

private @NonNull EBusCommandRegistry commandRegistry;

private @Nullable IEBusController controller;
Expand All @@ -57,7 +59,7 @@ public class EBusClient {
*
* @param commandRegistry
*/
public EBusClient(@NonNull EBusCommandRegistry commandRegistry) {
public EBusClient(final @NonNull EBusCommandRegistry commandRegistry) {

Objects.requireNonNull(commandRegistry);

Expand All @@ -76,8 +78,8 @@ public EBusClient(@NonNull EBusCommandRegistry commandRegistry) {
* @param listener
* @see de.csdev.ebus.service.device.EBusDeviceTable#addEBusDeviceTableListener(IEBusDeviceTableListener)
*/
public void addEBusDeviceTableListener(@NonNull IEBusDeviceTableListener listener) {
Objects.requireNonNull(listener, "listener");
public void addEBusDeviceTableListener(final @NonNull IEBusDeviceTableListener listener) {
Objects.requireNonNull(listener, LABEL_LISTENER);
if (deviceTable != null) {
deviceTable.addEBusDeviceTableListener(listener);
}
Expand All @@ -89,8 +91,8 @@ public void addEBusDeviceTableListener(@NonNull IEBusDeviceTableListener listene
* @param listener
* @see de.csdev.ebus.core.EBusControllerBase#addEBusEventListener(IEBusConnectorEventListener)
*/
public void addEBusEventListener(@NonNull IEBusConnectorEventListener listener) {
Objects.requireNonNull(listener, "listener");
public void addEBusEventListener(final @NonNull IEBusConnectorEventListener listener) {
Objects.requireNonNull(listener, LABEL_LISTENER);
if (controller != null) {
controller.addEBusEventListener(listener);
}
Expand All @@ -102,8 +104,8 @@ public void addEBusEventListener(@NonNull IEBusConnectorEventListener listener)
* @param listener
* @see de.csdev.ebus.client.EBusClient#addEBusParserListener(IEBusParserListener)
*/
public void addEBusParserListener(@NonNull IEBusParserListener listener) {
Objects.requireNonNull(listener, "listener");
public void addEBusParserListener(final @NonNull IEBusParserListener listener) {
Objects.requireNonNull(listener, LABEL_LISTENER);
if (resolverService != null) {
resolverService.addEBusParserListener(listener);
}
Expand All @@ -117,11 +119,10 @@ public void addEBusParserListener(@NonNull IEBusParserListener listener) {
* @throws EBusControllerException
* @see de.csdev.ebus.core.EBusLowLevelController#addToSendQueue(byte[])
*/
public @NonNull Integer addToSendQueue(byte @NonNull [] buffer) throws EBusControllerException {
public @NonNull Integer addToSendQueue(final byte @NonNull [] buffer) throws EBusControllerException {

Objects.requireNonNull(buffer, "buffer");

IEBusController controller = this.controller;
if (controller == null) {
throw new EBusControllerException("Controller not set!");
}
Expand All @@ -138,14 +139,13 @@ public void addEBusParserListener(@NonNull IEBusParserListener listener) {
* @throws EBusControllerException
* @see de.csdev.ebus.core.EBusLowLevelController#addToSendQueue(byte[], int)
*/
public @NonNull Integer addToSendQueue(byte @NonNull [] buffer, int maxAttemps) throws EBusControllerException {
public @NonNull Integer addToSendQueue(final byte @NonNull [] buffer, final int maxAttemps) throws EBusControllerException {

IEBusController controller = this.controller;
if (controller == null) {
if (this.controller == null) {
throw new EBusControllerException("Controller not set!");
}

return controller.addToSendQueue(buffer, maxAttemps);
return this.controller.addToSendQueue(buffer, maxAttemps);
}

/**
Expand All @@ -157,8 +157,8 @@ public void addEBusParserListener(@NonNull IEBusParserListener listener) {
* @throws EBusTypeException
* @throws EBusCommandException
*/
public @NonNull ByteBuffer buildTelegram(@NonNull IEBusCommandMethod commandMethod,
@NonNull Byte destinationAddress, @Nullable Map<String, Object> values)
public @NonNull ByteBuffer buildTelegram(final @NonNull IEBusCommandMethod commandMethod,
final @NonNull Byte destinationAddress, final @Nullable Map<String, Object> values)
throws EBusTypeException, EBusCommandException {

Objects.requireNonNull(commandMethod, "commandMethod");
Expand All @@ -174,7 +174,7 @@ public void addEBusParserListener(@NonNull IEBusParserListener listener) {
* @param controller
* @param masterAddress
*/
public void connect(@NonNull IEBusController controller, byte masterAddress) {
public void connect(final @NonNull IEBusController controller, final byte masterAddress) {

Objects.requireNonNull(controller, "Parameter controller can't be null!");

Expand All @@ -200,38 +200,26 @@ public void connect(@NonNull IEBusController controller, byte masterAddress) {
public void dispose() {
if (controller != null) {
controller.interrupt();
// controller = null;
}

// if (commandRegistry != null) {
// commandRegistry = null;
// }

if (deviceTableService != null) {
deviceTableService.dispose();
// deviceTableService = null;
}

if (deviceTable != null) {
deviceTable.dispose();
// deviceTable = null;
}

if (resolverService != null) {
resolverService.dispose();
// resolverService = null;
}

// if (metricsService != null) {
// metricsService = null;
// }
}

/**
* @param id
* @return
*/
public @Nullable IEBusCommandCollection getCommandCollection(@NonNull String id) {
public @Nullable IEBusCommandCollection getCommandCollection(final @NonNull String id) {
Objects.requireNonNull(id);
return getConfigurationProvider().getCommandCollection(id);
}
Expand Down Expand Up @@ -304,7 +292,7 @@ public void dispose() {
* @return
* @see de.csdev.ebus.service.device.EBusDeviceTable#removeEBusDeviceTableListener(IEBusDeviceTableListener)
*/
public boolean removeEBusDeviceTableListener(@NonNull IEBusDeviceTableListener listener) {
public boolean removeEBusDeviceTableListener(final @NonNull IEBusDeviceTableListener listener) {
Objects.requireNonNull(listener);
return getDeviceTable().removeEBusDeviceTableListener(listener);
}
Expand All @@ -316,7 +304,7 @@ public boolean removeEBusDeviceTableListener(@NonNull IEBusDeviceTableListener l
* @return
* @see de.csdev.ebus.core.EBusControllerBase#removeEBusEventListener(IEBusConnectorEventListener)
*/
public boolean removeEBusEventListener(@NonNull IEBusConnectorEventListener listener) {
public boolean removeEBusEventListener(final @NonNull IEBusConnectorEventListener listener) {
Objects.requireNonNull(listener);

if (controller != null) {
Expand All @@ -332,7 +320,7 @@ public boolean removeEBusEventListener(@NonNull IEBusConnectorEventListener list
* @return
* @see de.csdev.ebus.client.EBusClient#removeEBusParserListener(IEBusParserListener)
*/
public boolean removeEBusParserListener(@NonNull IEBusParserListener listener) {
public boolean removeEBusParserListener(final @NonNull IEBusParserListener listener) {
Objects.requireNonNull(listener);
return getResolverService().removeEBusParserListener(listener);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/csdev/ebus/command/EBusCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void setParentCollection(IEBusCommandCollection parentCollection) {

public void setProperties(Map<String, Object> properties) {
Objects.requireNonNull(properties, "properties");
this.properties = new HashMap<String, Object>();
this.properties = new HashMap<>();
this.properties.putAll(properties);
}

Expand Down
Loading