}
@Deactivate
+ @Override
public void deactivate() {
super.deactivate();
}
+ @Override
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, unbind = "removeChangeTracker")
public void addChangeTracker(ScriptDependencyTracker.Listener listener) {
super.addChangeTracker(listener);
}
+ @Override
public void removeChangeTracker(ScriptDependencyTracker.Listener listener) {
super.removeChangeTracker(listener);
}
private static final String PARAM_INSTANCE_HELP = " [--instance <instance id>]";
private class CommandCompleter implements ConsoleCommandCompleter {
+ @Override
public boolean complete(String[] args, int cursorArgumentIndex, int cursorPosition, List<String> candidates) {
if (cursorArgumentIndex == 0) {
- boolean result = SUBCMD_COMPLETER.complete(args, cursorArgumentIndex, cursorPosition, candidates);
- return result;
+ return SUBCMD_COMPLETER.complete(args, cursorArgumentIndex, cursorPosition, candidates);
}
return false;
}
return id;
}
+ @Override
public String toString() {
return "Item:" + proxyItem.getItem() + " HomeKit type: '" + homekitAccessoryType.getTag()
+ "' characteristic: '" + homekitCharacteristicType.getTag() + "'";
// Need to copy over everything except the current value, which we instead
// reach in and get the default value
cJson.forEach((k, v) -> {
- if (k.equals("value")) {
+ if ("value".equals(k)) {
Object defaultValue = ((BaseCharacteristic) c).getDefault();
if (defaultValue instanceof Boolean) {
cBuilder.add("value", (boolean) defaultValue);
} else if (state instanceof OpenClosedType) {
return state.equals(trueOpenClosedValue);
} else if (state instanceof StringType) {
- return state.toString().equalsIgnoreCase("Open") || state.toString().equalsIgnoreCase("Opened");
+ return "Open".equalsIgnoreCase(state.toString()) || "Opened".equalsIgnoreCase(state.toString());
} else if (localTrueThresheold != null) {
if (state instanceof DecimalType stateAsDecimalType) {
final boolean result = stateAsDecimalType.toBigDecimal().compareTo(localTrueThresheold) > 0;
this.totalMatchingItems = 1;
this.browseIdentifier = req.getBrowseIdentifier();
- this.items = Arrays.stream(listItems).skip(this.offset).limit(this.limit).map(item -> {
- return new NeeoDirectoryResultItem(item.getTitle(), item.getThumbNailUri(), null, item.getItemValue(),
- true);
- }).toArray(NeeoDirectoryResultItem[]::new);
+ this.items = Arrays.stream(listItems).skip(this.offset).limit(this.limit)
+ .map(item -> new NeeoDirectoryResultItem(item.getTitle(), item.getThumbNailUri(), null,
+ item.getItemValue(), true))
+ .toArray(NeeoDirectoryResultItem[]::new);
final NeeoDirectoryRequest current = new NeeoDirectoryRequest(this.offset, this.limit, this.browseIdentifier);
}
for (Class<? extends Command> cmd : item.getAcceptedCommandTypes()) {
- if (!cmd.getSimpleName().equalsIgnoreCase("refreshtype")) {
+ if (!"refreshtype".equalsIgnoreCase(cmd.getSimpleName())) {
commandTypes.add(cmd.getSimpleName().toLowerCase());
}
}
*/
@Override
public boolean canHandleRoute(String[] paths) {
- return paths.length >= 1 && (paths[0].equalsIgnoreCase("brainstatus") || paths[0].equalsIgnoreCase("addbrain")
- || paths[0].equalsIgnoreCase("removebrain") || paths[0].equalsIgnoreCase("getlog")
- || paths[0].equalsIgnoreCase("blinkled"));
+ return paths.length >= 1 && ("brainstatus".equalsIgnoreCase(paths[0]) || "addbrain".equalsIgnoreCase(paths[0])
+ || "removebrain".equalsIgnoreCase(paths[0]) || "getlog".equalsIgnoreCase(paths[0])
+ || "blinkled".equalsIgnoreCase(paths[0]));
}
/**
Objects.requireNonNull(resp, "resp cannot be null");
try {
- if (paths[0].equalsIgnoreCase("brainstatus")) {
+ if ("brainstatus".equalsIgnoreCase(paths[0])) {
final List<BrainStatus> status = new ArrayList<>();
for (NeeoBrainServlet servlet : service.getServlets()) {
status.add(servlet.getBrainStatus());
}
NeeoUtil.write(resp, gson.toJson(status));
- } else if (paths[0].equalsIgnoreCase("blinkled")) {
+ } else if ("blinkled".equalsIgnoreCase(paths[0])) {
final String brainId = req.getParameter("brainid");
if (brainId == null) {
NeeoUtil.write(resp, gson.toJson(new ReturnStatus("BrainID is null")));
}
}
}
- } else if (paths[0].equalsIgnoreCase("getlog")) {
+ } else if ("getlog".equalsIgnoreCase(paths[0])) {
final String brainId = req.getParameter("brainid");
if (brainId == null) {
NeeoUtil.write(resp, gson.toJson(new ReturnStatus("BrainID is null")));
}
try {
- if (paths[0].equalsIgnoreCase("removebrain")) {
+ if ("removebrain".equalsIgnoreCase(paths[0])) {
final BrainInfo info = gson.fromJson(req.getReader(), BrainInfo.class);
final String brainId = info.getBrainId();
if (brainId == null) {
NeeoUtil.write(resp,
gson.toJson(new ReturnStatus("BrainID (" + brainId + ") could not be removed")));
}
- } else if (paths[0].equalsIgnoreCase("addbrain")) {
+ } else if ("addbrain".equalsIgnoreCase(paths[0])) {
final BrainInfo info = gson.fromJson(req.getReader(), BrainInfo.class);
final String brainIp = info.getBrainIp();
if (brainIp == null) {
*/
@Override
public boolean canHandleRoute(String[] paths) {
- return paths.length >= 1 && paths[0].equalsIgnoreCase("db");
+ return paths.length >= 1 && "db".equalsIgnoreCase(paths[0]);
}
/**
final String path = paths[1].toLowerCase();
- if (path.equalsIgnoreCase("search")) {
+ if ("search".equalsIgnoreCase(path)) {
String queryString = req.getQueryString();
if (queryString != null) {
doSearch(queryString, resp);
}
- } else if (path.equalsIgnoreCase("adapterdefinition") && paths.length >= 3) {
+ } else if ("adapterdefinition".equalsIgnoreCase(path) && paths.length >= 3) {
doAdapterDefinition(paths[2], resp);
} else {
doQuery(path, resp);
return false;
}
- if (paths[0].equalsIgnoreCase("device")) {
+ if ("device".equalsIgnoreCase(paths[0])) {
return true;
}
throw new IllegalArgumentException("paths cannot be empty");
}
- final boolean hasDeviceStart = paths[0].equalsIgnoreCase("device");
+ final boolean hasDeviceStart = "device".equalsIgnoreCase(paths[0]);
if (hasDeviceStart) {
final PathInfo pathInfo = new PathInfo(paths);
// 4. Old subscribe path: /{thingUID}/subscribe or unsubscribe/{deviceid}/{devicekey}
// 4. Old unsubscribe path: /{thingUID}/subscribe or unsubscribe/{deviceid}
- final boolean hasDeviceStart = paths[0].equalsIgnoreCase("device");
- if (hasDeviceStart && (paths.length >= 3 && !paths[2].equalsIgnoreCase("subscribe")
- && !paths[2].equalsIgnoreCase("unsubscribe"))) {
+ final boolean hasDeviceStart = "device".equalsIgnoreCase(paths[0]);
+ if (hasDeviceStart && (paths.length >= 3 && !"subscribe".equalsIgnoreCase(paths[2])
+ && !"unsubscribe".equalsIgnoreCase(paths[2]))) {
try {
final PathInfo pathInfo = new PathInfo(paths);
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
import java.util.Objects;
+import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/** The logger */
private final Logger logger = LoggerFactory.getLogger(ThingDashboardService.class);
+ private static final Set<String> STARTERS = Set.of("thingstatus", "getchannel", "getvirtualdevice", "restoredevice",
+ "refreshdevice", "deletedevice", "exportrules", "updatedevice");
+
/** The gson used for json manipulation */
private final Gson gson;
*/
@Override
public boolean canHandleRoute(String[] paths) {
- return paths.length >= 1 && (paths[0].equalsIgnoreCase("thingstatus") //
- || paths[0].equalsIgnoreCase("getchannel") //
- || paths[0].equalsIgnoreCase("getvirtualdevice") //
- || paths[0].equalsIgnoreCase("restoredevice") //
- || paths[0].equalsIgnoreCase("refreshdevice") //
- || paths[0].equalsIgnoreCase("deletedevice") //
- || paths[0].equalsIgnoreCase("exportrules") //
- || paths[0].equalsIgnoreCase("updatedevice"));
+ return paths.length >= 1 && STARTERS.contains(paths[0].toLowerCase(Locale.ROOT));
}
/**
Objects.requireNonNull(resp, "resp cannot be null");
try {
- if (paths[0].equalsIgnoreCase("thingstatus")) {
+ if ("thingstatus".equalsIgnoreCase(paths[0])) {
final List<NeeoDevice> devices = context.getDefinitions().getAllDevices();
NeeoUtil.write(resp, gson.toJson(devices));
- } else if (paths[0].equalsIgnoreCase("getchannel")) {
+ } else if ("getchannel".equalsIgnoreCase(paths[0])) {
final String itemName = NeeoUtil.decodeURIComponent(req.getParameter("itemname"));
final List<NeeoDeviceChannel> channels = context.getDefinitions().getNeeoDeviceChannel(itemName);
if (channels == null) {
} else {
NeeoUtil.write(resp, gson.toJson(new ReturnStatus(channels)));
}
- } else if (paths[0].equalsIgnoreCase("getvirtualdevice")) {
+ } else if ("getvirtualdevice".equalsIgnoreCase(paths[0])) {
final NeeoThingUID uid = context.generate(NeeoConstants.VIRTUAL_THING_TYPE);
final NeeoDevice device = new NeeoDevice(uid, 0, NeeoDeviceType.EXCLUDE, "NEEO Integration",
"New Virtual Thing", new ArrayList<>(), null, null, null, null);
}
try {
- if (paths[0].equalsIgnoreCase("updatedevice")) {
+ if ("updatedevice".equalsIgnoreCase(paths[0])) {
final NeeoDevice device = gson.fromJson(req.getReader(), NeeoDevice.class);
context.getDefinitions().put(device);
}
NeeoUtil.write(resp, gson.toJson(ReturnStatus.SUCCESS));
- } else if (paths[0].equalsIgnoreCase("restoredevice")) {
+ } else if ("restoredevice".equalsIgnoreCase(paths[0])) {
final NeeoThingUID uid = new NeeoThingUID(
new String(req.getInputStream().readAllBytes(), StandardCharsets.UTF_8));
context.getDefinitions().remove(uid);
} else {
NeeoUtil.write(resp, gson.toJson(new ReturnStatus(device)));
}
- } else if (paths[0].equalsIgnoreCase("refreshdevice")) {
+ } else if ("refreshdevice".equalsIgnoreCase(paths[0])) {
final NeeoThingUID uid = new NeeoThingUID(
new String(req.getInputStream().readAllBytes(), StandardCharsets.UTF_8));
final NeeoDevice device = context.getDefinitions().getDevice(uid);
} else {
NeeoUtil.write(resp, gson.toJson(new ReturnStatus(device)));
}
- } else if (paths[0].equalsIgnoreCase("deletedevice")) {
+ } else if ("deletedevice".equalsIgnoreCase(paths[0])) {
final NeeoThingUID uid = new NeeoThingUID(
new String(req.getInputStream().readAllBytes(), StandardCharsets.UTF_8));
final boolean deleted = context.getDefinitions().remove(uid);
NeeoUtil.write(resp, gson.toJson(new ReturnStatus(
deleted ? null : "Device " + uid + " was not found (possibly already deleted?)")));
- } else if (paths[0].equalsIgnoreCase("exportrules")) {
+ } else if ("exportrules".equalsIgnoreCase(paths[0])) {
final NeeoThingUID uid = new NeeoThingUID(
new String(req.getInputStream().readAllBytes(), StandardCharsets.UTF_8));
final NeeoDevice device = context.getDefinitions().getDevice(uid);
try {
headerValue = requestHeadersJson.getString(headerName);
logger.debug("Jetty set header {} = {}", headerName, headerValue);
- if (!headerName.equalsIgnoreCase("Content-Length")) {
+ if (!"Content-Length".equalsIgnoreCase(headerName)) {
request.header(headerName, headerValue);
}
} catch (JSONException e) {
}
private boolean supportsUpdates() {
- return cloudBaseUrl.indexOf(CFG_BASE_URL) >= 0;
+ return cloudBaseUrl.contains(CFG_BASE_URL);
}
}
ITEM_CLASS_MAP_NEW.put(PlayerItem.class, DynamoDBBigDecimalItem.class); // Different from LEGACY
}
- public static final Class<? extends DynamoDBItem<?>> getDynamoItemClass(Class<? extends Item> itemClass,
- boolean legacy) throws NullPointerException {
+ public static Class<? extends DynamoDBItem<?>> getDynamoItemClass(Class<? extends Item> itemClass, boolean legacy)
+ throws NullPointerException {
Class<? extends DynamoDBItem<?>> dtoclass = (legacy ? ITEM_CLASS_MAP_LEGACY : ITEM_CLASS_MAP_NEW)
.get(itemClass);
if (dtoclass == null) {
String tableName = localTableNameResolver.fromClass(dtoClass);
final TableSchema<T> schema = getDynamoDBTableSchema(dtoClass, expectedTableSchemaRevision);
@SuppressWarnings("unchecked") // OK since this is the only place tableCache is populated
- DynamoDbAsyncTable<T> table = (DynamoDbAsyncTable<T>) tableCache.computeIfAbsent(dtoClass, clz -> {
- return localClient.table(tableName, schema);
- });
+ DynamoDbAsyncTable<T> table = (DynamoDbAsyncTable<T>) tableCache.computeIfAbsent(dtoClass,
+ clz -> localClient.table(tableName, schema));
if (table == null) {
// Invariant. To make null checker happy
throw new IllegalStateException();
**************/
public @Nullable Integer doPingDB() throws JdbcSQLException {
try {
- final @Nullable Integer result = Yank.queryScalar(sqlPingDB, Integer.class, null);
- return result;
+ return Yank.queryScalar(sqlPingDB, Integer.class, null);
} catch (YankSQLException e) {
throw new JdbcSQLException(e);
}
public @Nullable String doGetDB() throws JdbcSQLException {
try {
- final @Nullable String result = Yank.queryScalar(sqlGetDB, String.class, null);
- return result;
+ return Yank.queryScalar(sqlGetDB, String.class, null);
} catch (YankSQLException e) {
throw new JdbcSQLException(e);
}
} else if (item instanceof ImageItem) {
return RawType.valueOf(objectAsString(v));
} else if (item instanceof ContactItem || item instanceof PlayerItem || item instanceof SwitchItem) {
- State state = TypeParser.parseState(item.getAcceptedDataTypes(), ((String) v).toString().trim());
+ State state = TypeParser.parseState(item.getAcceptedDataTypes(), ((String) v).trim());
if (state == null) {
throw new UnsupportedOperationException("Unable to parse state for item " + item.toString());
}
return state;
} else {
- State state = TypeParser.parseState(item.getAcceptedDataTypes(), ((String) v).toString());
+ State state = TypeParser.parseState(item.getAcceptedDataTypes(), ((String) v));
if (state == null) {
throw new UnsupportedOperationException("Unable to parse state for item " + item.toString());
}
if (v instanceof byte[]) {
return new String((byte[]) v);
}
- return ((String) v).toString();
+ return ((String) v);
}
public String getItemType(Item i) {
* @param separators Array will be merged to str
* @return
*/
- public static final String replaceArrayMerge(String str, String separate, Object[] separators) {
+ public static String replaceArrayMerge(String str, String separate, Object[] separators) {
String s = str;
for (int i = 0; i < separators.length; i++) {
s = s.replaceFirst(separate, (String) separators[i]);
/**
* @see #replaceArrayMerge(String str, String separate, Object[] separators)
*/
- public static final String replaceArrayMerge(String str, String[] separate, String[] separators) {
+ public static String replaceArrayMerge(String str, String[] separate, String[] separators) {
String s = str;
for (int i = 0; i < separators.length; i++) {
s = s.replaceFirst(separate[i], separators[i]);
// replace first ; with ?
url = url.replaceFirst(";", "?");
// replace other ; with &
- url = url.replaceAll(";", "&");
+ url = url.replace(";", "&");
}
if (url.split(":").length < 3 || url.indexOf("/") == -1) {
}
public void addArchives(String archivesString) {
- String splitArchives[] = archivesString.split(":");
+ String[] splitArchives = archivesString.split(":");
for (String archiveString : splitArchives) {
String[] opts = archiveString.split(",");
if (opts.length != 4) { // check if correct number of parameters
String regex = substMatcher.group(1);
String substitution = substMatcher.group(2);
String options = substMatcher.group(3);
- if (options.equals("g")) {
+ if ("g".equals(options)) {
result = source.trim().replaceAll(regex, substitution);
} else {
result = source.trim().replaceFirst(regex, substitution);
final String value = properties.getProperty(entry);
final Matcher matcher = LIMITS_PATTERN.matcher(entry);
if (matcher.matches() && (matcher.groupCount() == 4)) {
- final boolean lowerInclusive = matcher.group(1).equals("[");
- final boolean upperInclusive = matcher.group(4).equals("]");
+ final boolean lowerInclusive = "[".equals(matcher.group(1));
+ final boolean upperInclusive = "]".equals(matcher.group(4));
final String lowLimit = matcher.group(2);
final String highLimit = matcher.group(3);
String itemLabel = targetItem.getLabel();
String groupLabel = null;
Item finalTargetItem = targetItem;
- if (finalTargetItem.getType().equals("Group") && memberTargets != null) {
+ if ("Group".equals(finalTargetItem.getType()) && memberTargets != null) {
if (memberTargets.mergeState && memberTargets.itemName.isEmpty() && !memberTargets.itemType.isEmpty()) {
// handle states that can be merged
switch (memberTargets.itemType) {
.filter(Objects::nonNull).toArray(String[]::new);
itemOptionPlaceholder.posStaticValues = cmdDescription.getCommandOptions().stream()
.collect(Collectors.toMap(
- option -> option.getLabel() != null ? option.getLabel().replaceAll(" ", "__")
- : option.getCommand().replaceAll(" ", "__"),
- option -> option.getCommand().replaceAll(" ", "__")));
+ option -> option.getLabel() != null ? option.getLabel().replace(" ", "__")
+ : option.getCommand().replace(" ", "__"),
+ option -> option.getCommand().replace(" ", "__")));
return itemOptionPlaceholder;
} else if (stateDescription != null) {
itemOptionPlaceholder.nerStaticValues = stateDescription.getOptions().stream()
.filter(Objects::nonNull).toArray(String[]::new);
if (isRead) {
itemOptionPlaceholder.posStaticValues = stateDescription.getOptions().stream()
- .collect(Collectors.toMap(option -> option.getValue().replaceAll(" ", "__"),
- option -> option.getLabel() != null ? option.getLabel().replaceAll(" ", "__")
- : option.getValue().replaceAll(" ", "__")));
+ .collect(Collectors.toMap(option -> option.getValue().replace(" ", "__"),
+ option -> option.getLabel() != null ? option.getLabel().replace(" ", "__")
+ : option.getValue().replace(" ", "__")));
} else {
itemOptionPlaceholder.posStaticValues = stateDescription.getOptions().stream()
.collect(Collectors.toMap(
- option -> option.getLabel() != null ? option.getLabel().replaceAll(" ", "__")
- : option.getValue().replaceAll(" ", "__"),
- option -> option.getValue().replaceAll(" ", "__")));
+ option -> option.getLabel() != null ? option.getLabel().replace(" ", "__")
+ : option.getValue().replace(" ", "__"),
+ option -> option.getValue().replace(" ", "__")));
}
return itemOptionPlaceholder;
}
if (tag == null) {
return "";
}
- return tag.replaceAll("__", " ");
+ return tag.replace("__", " ");
}
private Map<String[], Item> getItemsByLabelTokensMap() {
throw new TTSException("The passed voice is unsupported");
}
- boolean isAudioFormatSupported = this.audioFormats.stream().anyMatch(audioFormat -> {
- return audioFormat.isCompatible(requestedFormat);
- });
+ boolean isAudioFormatSupported = this.audioFormats.stream()
+ .anyMatch(audioFormat -> audioFormat.isCompatible(requestedFormat));
if (!isAudioFormatSupported) {
throw new TTSException("The passed AudioFormat is unsupported");
throw new TTSException("Could not read from PollyTTS service");
}
logger.debug("Audio Stream for '{}' in format {}", text, requestedFormat);
- AudioStream audioStream = new PollyTTSAudioStream(pollyAudioStream, requestedFormat);
- return audioStream;
+ return new PollyTTSAudioStream(pollyAudioStream, requestedFormat);
} catch (AmazonPollyException ex) {
throw new TTSException("Could not read from PollyTTS service: " + ex.getMessage(), ex);
}
File localFile = new File(EXTRACTION_FOLDER,
relativePath.substring(relativePath.lastIndexOf(File.separator) + 1));
if (!localFile.exists()) {
- if (File.separator.equals("\\")) {
+ if ("\\".equals(File.separator)) {
// bundle requires unix path separator
logger.debug("use unix path separator");
relativePath = relativePath.replace("\\", "/");
"You can provide a specific model for fr language in {}, english language model will be used",
PORCUPINE_FOLDER);
}
- } else if (locale.getLanguage().equals("es")) {
+ } else if ("es".equals(locale.getLanguage())) {
Path esPath = Path.of(PORCUPINE_FOLDER, "porcupine_params_es.pv");
if (Files.exists(esPath)) {
modelPath = esPath.toString();
usage();
return RC_USAGE;
}
- if (!args[0].equalsIgnoreCase("--api-key")) {
+ if (!"--api-key".equalsIgnoreCase(args[0])) {
usage();
return RC_API_KEY_MISSING;
}
try {
String osName = System.getProperty("os.name", "generic").toLowerCase();
String osArch = System.getProperty("os.arch", "").toLowerCase();
- if (osName.contains("linux") && (osArch.equals("arm") || osArch.equals("armv7l"))) {
+ if (osName.contains("linux") && ("arm".equals(osArch) || "armv7l".equals(osArch))) {
// workaround for loading required shared libraries
loadSharedLibrariesArmv7l();
}