mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
Replace StringBuffer usages with StringBuilder (#3668)
See: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/StringBuilder.html > This class provides an API compatible with StringBuffer, but with no guarantee of synchronization. > This class is designed for use as a drop-in replacement for StringBuffer in places where the string buffer was being used by a single thread (as is generally the case). > Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations. Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
+8
-13
@@ -266,7 +266,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
||||
this.ruleRegistry = ruleRegistry;
|
||||
this.readyService = readyService;
|
||||
|
||||
listener = new RegistryChangeListener<Rule>() {
|
||||
listener = new RegistryChangeListener<>() {
|
||||
@Override
|
||||
public void added(Rule rule) {
|
||||
RuleEngineImpl.this.addRule(rule);
|
||||
@@ -337,8 +337,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
||||
synchronized (this) {
|
||||
Set<String> rulesPerModule = mapModuleTypeToRules.get(moduleTypeName);
|
||||
if (rulesPerModule != null) {
|
||||
rules = new HashSet<>();
|
||||
rules.addAll(rulesPerModule);
|
||||
rules = new HashSet<>(rulesPerModule);
|
||||
}
|
||||
}
|
||||
if (rules != null) {
|
||||
@@ -366,8 +365,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
||||
synchronized (this) {
|
||||
Set<String> rulesPerModule = mapModuleTypeToRules.get(moduleTypeName);
|
||||
if (rulesPerModule != null) {
|
||||
rules = new HashSet<>();
|
||||
rules.addAll(rulesPerModule);
|
||||
rules = new HashSet<>(rulesPerModule);
|
||||
}
|
||||
}
|
||||
if (rules != null) {
|
||||
@@ -402,8 +400,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
||||
moduleHandlerFactories.put(moduleTypeName, moduleHandlerFactory);
|
||||
Set<String> rulesPerModule = mapModuleTypeToRules.get(moduleTypeName);
|
||||
if (rulesPerModule != null) {
|
||||
rules = new HashSet<>();
|
||||
rules.addAll(rulesPerModule);
|
||||
rules = new HashSet<>(rulesPerModule);
|
||||
}
|
||||
}
|
||||
if (rules != null) {
|
||||
@@ -505,13 +502,11 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
||||
final boolean activated = activateRule(rule);
|
||||
if (activated) {
|
||||
Future<?> f = scheduleTasks.remove(rUID);
|
||||
if (f != null) {
|
||||
if (!f.isDone()) {
|
||||
if ((f != null) && !f.isDone()) {
|
||||
f.cancel(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC)
|
||||
protected void setEventPublisher(EventPublisher eventPublisher) {
|
||||
@@ -942,7 +937,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
||||
for (Entry<String, List<String>> e : mapMissingHandlers.entrySet()) {
|
||||
String rUID = e.getKey();
|
||||
List<String> missingTypes = e.getValue();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Missing handlers: ");
|
||||
for (String typeUID : missingTypes) {
|
||||
sb.append(typeUID).append(", ");
|
||||
@@ -1097,7 +1092,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
||||
throw new IllegalStateException("context cannot be null at that point - please report a bug.");
|
||||
}
|
||||
if (connections != null) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Connection c : connections) {
|
||||
String outputModuleId = c.getOutputModuleId();
|
||||
if (outputModuleId != null) {
|
||||
@@ -1438,7 +1433,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
||||
private void executeRulesWithStartLevel() {
|
||||
getScheduledExecutor().submit(() -> {
|
||||
ruleRegistry.getAll().stream() //
|
||||
.filter(r -> mustTrigger(r)) //
|
||||
.filter(this::mustTrigger) //
|
||||
.forEach(r -> runNow(r.getUID(), true,
|
||||
Map.of(SystemTriggerHandler.OUT_STARTLEVEL, StartLevelService.STARTLEVEL_RULES)));
|
||||
started = true;
|
||||
|
||||
+3
-3
@@ -500,7 +500,7 @@ public class RuleRegistryImpl extends AbstractRegistry<Rule, String, RuleProvide
|
||||
if (isOptionalConfig(configDescriptions)) {
|
||||
return;
|
||||
} else {
|
||||
StringBuffer statusDescription = new StringBuffer();
|
||||
StringBuilder statusDescription = new StringBuilder();
|
||||
String msg = " '%s';";
|
||||
for (ConfigDescriptionParameter configParameter : configDescriptions) {
|
||||
if (configParameter.isRequired()) {
|
||||
@@ -517,7 +517,7 @@ public class RuleRegistryImpl extends AbstractRegistry<Rule, String, RuleProvide
|
||||
processValue(configurations.remove(configParameterName), configParameter);
|
||||
}
|
||||
if (!configurations.isEmpty()) {
|
||||
StringBuffer statusDescription = new StringBuffer();
|
||||
StringBuilder statusDescription = new StringBuilder();
|
||||
String msg = " '%s';";
|
||||
for (String name : configurations.keySet()) {
|
||||
statusDescription.append(String.format(msg, name));
|
||||
@@ -610,7 +610,7 @@ public class RuleRegistryImpl extends AbstractRegistry<Rule, String, RuleProvide
|
||||
*/
|
||||
private void resolveModuleConfigReferences(List<? extends Module> modules, Map<String, ?> ruleConfiguration) {
|
||||
if (modules != null) {
|
||||
StringBuffer statusDescription = new StringBuffer();
|
||||
StringBuilder statusDescription = new StringBuilder();
|
||||
for (Module module : modules) {
|
||||
try {
|
||||
ReferenceResolver.updateConfiguration(module.getConfiguration(), ruleConfiguration, logger);
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ public class ConsoleInterpreter {
|
||||
public static String getHelp(final String base, final String separator,
|
||||
Collection<ConsoleCommandExtension> extensions) {
|
||||
final List<String> usages = ConsoleInterpreter.getUsages(extensions);
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
final StringBuilder buffer = new StringBuilder();
|
||||
|
||||
buffer.append("---openHAB commands---\n\t");
|
||||
for (int i = 0; i < usages.size(); i++) {
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class MagicServiceConfig {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer b = new StringBuffer();
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (Field field : this.getClass().getDeclaredFields()) {
|
||||
Object value;
|
||||
try {
|
||||
|
||||
+1
-1
@@ -132,7 +132,7 @@ public final class FirmwareUpdateConsoleCommandExtension extends AbstractConsole
|
||||
FirmwareStatusInfo firmwareStatusInfo = firmwareUpdateService.getFirmwareStatusInfo(thingUID);
|
||||
|
||||
if (firmwareStatusInfo != null) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(String.format("Firmware status for thing with UID %s is %s.", thingUID,
|
||||
firmwareStatusInfo.getFirmwareStatus()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user