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:
+9
-14
@@ -266,7 +266,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
|||||||
this.ruleRegistry = ruleRegistry;
|
this.ruleRegistry = ruleRegistry;
|
||||||
this.readyService = readyService;
|
this.readyService = readyService;
|
||||||
|
|
||||||
listener = new RegistryChangeListener<Rule>() {
|
listener = new RegistryChangeListener<>() {
|
||||||
@Override
|
@Override
|
||||||
public void added(Rule rule) {
|
public void added(Rule rule) {
|
||||||
RuleEngineImpl.this.addRule(rule);
|
RuleEngineImpl.this.addRule(rule);
|
||||||
@@ -337,8 +337,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
|||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
Set<String> rulesPerModule = mapModuleTypeToRules.get(moduleTypeName);
|
Set<String> rulesPerModule = mapModuleTypeToRules.get(moduleTypeName);
|
||||||
if (rulesPerModule != null) {
|
if (rulesPerModule != null) {
|
||||||
rules = new HashSet<>();
|
rules = new HashSet<>(rulesPerModule);
|
||||||
rules.addAll(rulesPerModule);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rules != null) {
|
if (rules != null) {
|
||||||
@@ -366,8 +365,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
|||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
Set<String> rulesPerModule = mapModuleTypeToRules.get(moduleTypeName);
|
Set<String> rulesPerModule = mapModuleTypeToRules.get(moduleTypeName);
|
||||||
if (rulesPerModule != null) {
|
if (rulesPerModule != null) {
|
||||||
rules = new HashSet<>();
|
rules = new HashSet<>(rulesPerModule);
|
||||||
rules.addAll(rulesPerModule);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rules != null) {
|
if (rules != null) {
|
||||||
@@ -402,8 +400,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
|||||||
moduleHandlerFactories.put(moduleTypeName, moduleHandlerFactory);
|
moduleHandlerFactories.put(moduleTypeName, moduleHandlerFactory);
|
||||||
Set<String> rulesPerModule = mapModuleTypeToRules.get(moduleTypeName);
|
Set<String> rulesPerModule = mapModuleTypeToRules.get(moduleTypeName);
|
||||||
if (rulesPerModule != null) {
|
if (rulesPerModule != null) {
|
||||||
rules = new HashSet<>();
|
rules = new HashSet<>(rulesPerModule);
|
||||||
rules.addAll(rulesPerModule);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rules != null) {
|
if (rules != null) {
|
||||||
@@ -505,10 +502,8 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
|||||||
final boolean activated = activateRule(rule);
|
final boolean activated = activateRule(rule);
|
||||||
if (activated) {
|
if (activated) {
|
||||||
Future<?> f = scheduleTasks.remove(rUID);
|
Future<?> f = scheduleTasks.remove(rUID);
|
||||||
if (f != null) {
|
if ((f != null) && !f.isDone()) {
|
||||||
if (!f.isDone()) {
|
f.cancel(true);
|
||||||
f.cancel(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -942,7 +937,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
|||||||
for (Entry<String, List<String>> e : mapMissingHandlers.entrySet()) {
|
for (Entry<String, List<String>> e : mapMissingHandlers.entrySet()) {
|
||||||
String rUID = e.getKey();
|
String rUID = e.getKey();
|
||||||
List<String> missingTypes = e.getValue();
|
List<String> missingTypes = e.getValue();
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("Missing handlers: ");
|
sb.append("Missing handlers: ");
|
||||||
for (String typeUID : missingTypes) {
|
for (String typeUID : missingTypes) {
|
||||||
sb.append(typeUID).append(", ");
|
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.");
|
throw new IllegalStateException("context cannot be null at that point - please report a bug.");
|
||||||
}
|
}
|
||||||
if (connections != null) {
|
if (connections != null) {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (Connection c : connections) {
|
for (Connection c : connections) {
|
||||||
String outputModuleId = c.getOutputModuleId();
|
String outputModuleId = c.getOutputModuleId();
|
||||||
if (outputModuleId != null) {
|
if (outputModuleId != null) {
|
||||||
@@ -1438,7 +1433,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
|||||||
private void executeRulesWithStartLevel() {
|
private void executeRulesWithStartLevel() {
|
||||||
getScheduledExecutor().submit(() -> {
|
getScheduledExecutor().submit(() -> {
|
||||||
ruleRegistry.getAll().stream() //
|
ruleRegistry.getAll().stream() //
|
||||||
.filter(r -> mustTrigger(r)) //
|
.filter(this::mustTrigger) //
|
||||||
.forEach(r -> runNow(r.getUID(), true,
|
.forEach(r -> runNow(r.getUID(), true,
|
||||||
Map.of(SystemTriggerHandler.OUT_STARTLEVEL, StartLevelService.STARTLEVEL_RULES)));
|
Map.of(SystemTriggerHandler.OUT_STARTLEVEL, StartLevelService.STARTLEVEL_RULES)));
|
||||||
started = true;
|
started = true;
|
||||||
|
|||||||
+3
-3
@@ -500,7 +500,7 @@ public class RuleRegistryImpl extends AbstractRegistry<Rule, String, RuleProvide
|
|||||||
if (isOptionalConfig(configDescriptions)) {
|
if (isOptionalConfig(configDescriptions)) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
StringBuffer statusDescription = new StringBuffer();
|
StringBuilder statusDescription = new StringBuilder();
|
||||||
String msg = " '%s';";
|
String msg = " '%s';";
|
||||||
for (ConfigDescriptionParameter configParameter : configDescriptions) {
|
for (ConfigDescriptionParameter configParameter : configDescriptions) {
|
||||||
if (configParameter.isRequired()) {
|
if (configParameter.isRequired()) {
|
||||||
@@ -517,7 +517,7 @@ public class RuleRegistryImpl extends AbstractRegistry<Rule, String, RuleProvide
|
|||||||
processValue(configurations.remove(configParameterName), configParameter);
|
processValue(configurations.remove(configParameterName), configParameter);
|
||||||
}
|
}
|
||||||
if (!configurations.isEmpty()) {
|
if (!configurations.isEmpty()) {
|
||||||
StringBuffer statusDescription = new StringBuffer();
|
StringBuilder statusDescription = new StringBuilder();
|
||||||
String msg = " '%s';";
|
String msg = " '%s';";
|
||||||
for (String name : configurations.keySet()) {
|
for (String name : configurations.keySet()) {
|
||||||
statusDescription.append(String.format(msg, name));
|
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) {
|
private void resolveModuleConfigReferences(List<? extends Module> modules, Map<String, ?> ruleConfiguration) {
|
||||||
if (modules != null) {
|
if (modules != null) {
|
||||||
StringBuffer statusDescription = new StringBuffer();
|
StringBuilder statusDescription = new StringBuilder();
|
||||||
for (Module module : modules) {
|
for (Module module : modules) {
|
||||||
try {
|
try {
|
||||||
ReferenceResolver.updateConfiguration(module.getConfiguration(), ruleConfiguration, logger);
|
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,
|
public static String getHelp(final String base, final String separator,
|
||||||
Collection<ConsoleCommandExtension> extensions) {
|
Collection<ConsoleCommandExtension> extensions) {
|
||||||
final List<String> usages = ConsoleInterpreter.getUsages(extensions);
|
final List<String> usages = ConsoleInterpreter.getUsages(extensions);
|
||||||
final StringBuffer buffer = new StringBuffer();
|
final StringBuilder buffer = new StringBuilder();
|
||||||
|
|
||||||
buffer.append("---openHAB commands---\n\t");
|
buffer.append("---openHAB commands---\n\t");
|
||||||
for (int i = 0; i < usages.size(); i++) {
|
for (int i = 0; i < usages.size(); i++) {
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@ public class MagicServiceConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer b = new StringBuffer();
|
StringBuilder b = new StringBuilder();
|
||||||
for (Field field : this.getClass().getDeclaredFields()) {
|
for (Field field : this.getClass().getDeclaredFields()) {
|
||||||
Object value;
|
Object value;
|
||||||
try {
|
try {
|
||||||
|
|||||||
+1
-1
@@ -132,7 +132,7 @@ public final class FirmwareUpdateConsoleCommandExtension extends AbstractConsole
|
|||||||
FirmwareStatusInfo firmwareStatusInfo = firmwareUpdateService.getFirmwareStatusInfo(thingUID);
|
FirmwareStatusInfo firmwareStatusInfo = firmwareUpdateService.getFirmwareStatusInfo(thingUID);
|
||||||
|
|
||||||
if (firmwareStatusInfo != null) {
|
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,
|
sb.append(String.format("Firmware status for thing with UID %s is %s.", thingUID,
|
||||||
firmwareStatusInfo.getFirmwareStatus()));
|
firmwareStatusInfo.getFirmwareStatus()));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user