List of usage examples for org.apache.commons.lang StringUtils endsWithIgnoreCase
public static boolean endsWithIgnoreCase(String str, String suffix)
Case insensitive check if a String ends with a specified suffix.
From source file:org.openhab.io.neeo.internal.serialization.NeeoBrainDeviceSerializer.java
@Override public JsonElement serialize(NeeoDevice device, @Nullable Type deviceType, @Nullable JsonSerializationContext jsonContext) { Objects.requireNonNull(device, "device cannot be null"); Objects.requireNonNull(deviceType, "deviceType cannot be null"); Objects.requireNonNull(jsonContext, "jsonContext cannot be null"); final JsonObject jsonObject = new JsonObject(); final String adapterName = device.getUid().getNeeoUID(); // jsonObject.addProperty("apiversion", "1.0"); // haven't decided if needed jsonObject.addProperty("adapterName", adapterName); jsonObject.addProperty("driverVersion", device.getDriverVersion()); jsonObject.addProperty("type", device.getType().toString()); jsonObject.addProperty("manufacturer", device.getManufacturer()); jsonObject.addProperty("name", device.getName()); jsonObject.addProperty("tokens", ""); final NeeoDeviceTiming timing = device.getDeviceTiming(); if (timing != null) { final JsonObject timingObj = new JsonObject(); timingObj.addProperty("standbyCommandDelay", timing.getStandbyCommandDelay()); timingObj.addProperty("sourceSwitchDelay", timing.getSourceSwitchDelay()); timingObj.addProperty("shutdownDelay", timing.getShutdownDelay()); jsonObject.add("timing", timingObj); }//from www .j ava 2 s.co m /** * Setup only really good for SDK discovery (which we don't do) * 'setup': { 'discovery': true,'registration': false,'introheader': 'header text','introtext': 'some hints'} */ jsonObject.add("setup", new JsonObject()); jsonObject.add("deviceCapabilities", jsonContext.serialize(device.getDeviceCapabilities())); final JsonObject deviceObj = new JsonObject(); final String deviceName = device.getName(); deviceObj.addProperty("name", deviceName); deviceObj.add("tokens", new JsonArray()); jsonObject.add("device", deviceObj); final String specificName = device.getSpecificName(); if (specificName != null && StringUtils.isNotEmpty(specificName)) { deviceObj.addProperty("specificname", specificName); jsonObject.addProperty("specificname", specificName); } else if (StringUtils.isNotEmpty(deviceName)) { deviceObj.addProperty("specificname", deviceName); jsonObject.addProperty("specificname", deviceName); } final String iconName = device.getIconName(); if (iconName != null && StringUtils.isNotEmpty(iconName)) { deviceObj.addProperty("icon", iconName); jsonObject.addProperty("icon", iconName); } final List<JsonObject> capabilities = new ArrayList<>(); for (NeeoDeviceChannel channel : device.getExposedChannels()) { final NeeoCapabilityType capabilityType = channel.getType(); final String compPath = NeeoConstants.CAPABILITY_PATH_PREFIX + "/" + adapterName + "/" + channel.getItemName() + "/" + channel.getSubType() + "/" + channel.getChannelNbr(); final String uniqueItemName = channel.getUniqueItemName(); final String sensorItemName = uniqueItemName + (StringUtils.endsWithIgnoreCase(uniqueItemName, NeeoConstants.NEEO_SENSOR_SUFFIX) ? "" : NeeoConstants.NEEO_SENSOR_SUFFIX); if (capabilityType == NeeoCapabilityType.BUTTON) { final String name = StringUtils.isEmpty(channel.getLabel()) ? uniqueItemName : channel.getLabel(); if (channel.getKind() == NeeoDeviceChannelKind.TRIGGER) { final String path = compPath + "/button/trigger"; capabilities.add(createBase(name, channel.getLabel(), capabilityType.toString(), path)); } else { final String value = channel.getValue(); final String path = compPath + "/button/" + (value == null || StringUtils.isEmpty(value) ? "on" : NeeoUtil.encodeURIComponent(value.trim())); capabilities.add(createBase(name, channel.getLabel(), capabilityType.toString(), path)); } } else if (capabilityType == NeeoCapabilityType.SENSOR_POWER) { final JsonObject sensorTypeObj = new JsonObject(); sensorTypeObj.addProperty("type", NeeoCapabilityType.SENSOR_POWER.toString()); // power should NOT use the sensor suffix capabilities.add(createBase(uniqueItemName, channel.getLabel(), NeeoCapabilityType.SENSOR.toString(), compPath + "/switch/power", sensorTypeObj)); } else if (capabilityType == NeeoCapabilityType.SENSOR) { final JsonObject sensor = new JsonObject(); sensor.addProperty("type", NeeoCapabilityType.SENSOR_RANGE.toString()); final NeeoDeviceChannelRange channelRange = channel.getRange(); final int[] range = new int[] { channelRange.getMinValue(), channelRange.getMaxValue() }; sensor.add("range", jsonContext.serialize(range)); sensor.addProperty("unit", channelRange.getUnit()); capabilities.add(createBase(sensorItemName, channel.getLabel(), capabilityType.toString(), compPath + "/sensor/sensor", sensor)); } else if (capabilityType == NeeoCapabilityType.SLIDER) { final JsonObject sliderSensor = new JsonObject(); sliderSensor.addProperty("type", NeeoCapabilityType.SENSOR_RANGE.toString()); sliderSensor.addProperty("sensor", sensorItemName); final NeeoDeviceChannelRange channelRange = channel.getRange(); final int[] range = new int[] { channelRange.getMinValue(), channelRange.getMaxValue() }; sliderSensor.add("range", jsonContext.serialize(range)); sliderSensor.addProperty("unit", channelRange.getUnit()); capabilities.add(createBase(uniqueItemName, channel.getLabel(), capabilityType.toString(), compPath + "/slider/actor", "slider", sliderSensor)); final JsonObject sensorTypeObj = new JsonObject(); sensorTypeObj.addProperty("type", NeeoCapabilityType.SENSOR_RANGE.toString()); sensorTypeObj.add("range", jsonContext.serialize(range)); sensorTypeObj.addProperty("unit", channelRange.getUnit()); capabilities.add(createBase(sensorItemName, channel.getLabel(), NeeoCapabilityType.SENSOR.toString(), compPath + "/slider/sensor", sensorTypeObj)); } else if (capabilityType == NeeoCapabilityType.SWITCH) { final String label = channel.getLabel(); final NeeoButtonGroup buttons = NeeoButtonGroup.parse(label); if (buttons == null) { capabilities.add(createBase(uniqueItemName, channel.getLabel(), capabilityType.toString(), compPath + "/switch/actor", new JsonPrimitive(sensorItemName))); final JsonObject sensorTypeObj = new JsonObject(); sensorTypeObj.addProperty("type", NeeoCapabilityType.SENSOR_BINARY.toString()); capabilities.add(createBase(sensorItemName, channel.getLabel(), NeeoCapabilityType.SENSOR.toString(), compPath + "/switch/sensor", sensorTypeObj)); } else { for (final ButtonInfo bi : buttons.getButtonInfos()) { capabilities.add(createBase(bi.getLabel(), bi.getLabel(), NeeoCapabilityType.BUTTON.toString(), compPath + "/button/" + bi.getSuffix())); } } } else if (capabilityType == NeeoCapabilityType.IMAGEURL) { final String value = channel.getValue(); final String size = (value == null || StringUtils.isEmpty(value) ? "large" : value.trim()) .toLowerCase(); final JsonObject jo = createBase(uniqueItemName, channel.getLabel(), capabilityType.toString(), compPath + "/image/actor", "sensor", new JsonPrimitive(sensorItemName)); jo.addProperty("size", size); capabilities.add(jo); final JsonObject sensorTypeObj = new JsonObject(); sensorTypeObj.addProperty("type", NeeoCapabilityType.IMAGEURL.toString()); capabilities.add(createBase(sensorItemName, channel.getLabel(), NeeoCapabilityType.SENSOR.toString(), compPath + "/image/sensor", sensorTypeObj)); } else if (capabilityType == NeeoCapabilityType.TEXTLABEL) { final JsonObject capObj = createBase(uniqueItemName, channel.getLabel(), capabilityType.toString(), compPath + "/textlabel/actor", new JsonPrimitive(sensorItemName)); capObj.addProperty("isLabelVisible", channel instanceof NeeoDeviceChannelText ? ((NeeoDeviceChannelText) channel).isLabelVisible() : true); capabilities.add(capObj); final JsonObject sensorTypeObj = new JsonObject(); sensorTypeObj.addProperty("type", NeeoCapabilityType.SENSOR_CUSTOM.toString()); capabilities.add(createBase(sensorItemName, channel.getLabel(), NeeoCapabilityType.SENSOR.toString(), compPath + "/textlabel/sensor", sensorTypeObj)); } else if (capabilityType == NeeoCapabilityType.DIRECTORY) { final JsonObject capObj = createBase(uniqueItemName, channel.getLabel(), capabilityType.toString(), compPath + "/directory/actor"); capabilities.add(capObj); } else { logger.debug("Unknown capability type: {} for channel {}", capabilityType, channel); continue; } } jsonObject.add("capabilities", jsonContext.serialize(capabilities)); return jsonObject; }
From source file:org.opentestsystem.airose.docquality.processors.PassiveSentencesQualityProcessor.java
private boolean checkPassive(AbstractDocument doc, Parse p) { Queue<Parse> queue = new LinkedList<Parse>(); queue.add(p);// w w w . j a v a2s . com while (queue.size() > 0) { p = queue.remove(); String parseType = p.getType(); if ((parseType.length() >= 2) && StringUtils.equalsIgnoreCase(parseType.substring(0, 2), "VB")) { String word = p.getText().substring(p.getSpan().getStart(), p.getSpan().getStart() + p.getSpan().length()); List<String> roots = wordnet.getBaseWords(word, EnumPOS.VERB); if ((roots.size() > 0) && (StringUtils.endsWithIgnoreCase(roots.get(0), "be"))) { return true; } else return false; } else { for (Parse child : p.getChildren()) queue.add(child); } } return false; }
From source file:org.pdfsam.guiclient.business.actions.AutoLoadEnvironmentAction.java
@Override public void actionPerformed(ActionEvent e) { if (recentEnvironment != null && StringUtils.endsWithIgnoreCase(recentEnvironment.getName(), ".xml")) { if (recentEnvironment.exists()) { environment.loadJobs(recentEnvironment); }/*from www . jav a 2 s. co m*/ } }
From source file:org.pentaho.di.job.entries.publish.DatasourcePublishService.java
protected String checkDswId(String modelName) { if (!modelName.endsWith(METADATA_EXTENSION)) { if (StringUtils.endsWithIgnoreCase(modelName, METADATA_EXTENSION)) { modelName = StringUtils.removeEndIgnoreCase(modelName, METADATA_EXTENSION); }/*from w ww.ja v a 2 s. c o m*/ modelName += METADATA_EXTENSION; } return modelName; }
From source file:org.sonar.api.resources.JavaFile.java
/** * Creates a JavaFile from a file in the source directories * * @return the JavaFile created if exists, null otherwise *//*w w w. j ava 2 s .co m*/ public static JavaFile fromIOFile(File file, List<File> sourceDirs, boolean unitTest) { if (file == null || !StringUtils.endsWithIgnoreCase(file.getName(), ".java")) { return null; } PathResolver.RelativePath relativePath = new PathResolver().relativePath(sourceDirs, file); if (relativePath != null) { return fromRelativePath(relativePath.path(), unitTest); } return null; }
From source file:org.sonar.core.plugins.PluginClassloaders.java
private boolean isResource(File file) { return !StringUtils.endsWithIgnoreCase(file.getName(), ".jar") && !file.isDirectory(); }
From source file:org.sonar.dotnet.tools.commons.visualstudio.VisualStudioProject.java
/** * Recursively lists the files of a directory * /*from w w w .j a va2 s . c om*/ * @param dir * the directory to list * @param extension * @return */ private List<File> listRecursiveFiles(File dir, String extension) { List<File> result = new ArrayList<File>(); File[] content = dir.listFiles(); if (content != null) { for (File file : content) { if (file.isDirectory()) { List<File> matching = listRecursiveFiles(file, extension); result.addAll(matching); } else { // Look for matching file names if (StringUtils.endsWithIgnoreCase(file.getName(), extension)) { result.add(file); } } } } return result; }
From source file:org.sonar.dotnet.tools.gallio.GallioCommandBuilder.java
protected String trimFileReportName() { String reportName = gallioReportFile.getName(); if (StringUtils.endsWithIgnoreCase(reportName, ".xml")) { // We remove the terminal .xml that will be added by the Gallio runner reportName = reportName.substring(0, reportName.length() - 4); }/*from w ww .java 2 s .c om*/ return reportName; }
From source file:org.sonar.plugins.emma.EmmaMavenPluginHandler.java
public void configure(Project project, MavenPlugin plugin) { plugin.setParameter("format", "xml"); if (project.getExclusionPatterns() != null) { for (String pattern : project.getExclusionPatterns()) { if (StringUtils.endsWithIgnoreCase(pattern, ".java")) { pattern = StringUtils.substringBeforeLast(pattern, "."); }/*from ww w .java 2s .c o m*/ pattern = pattern.startsWith("/") ? pattern.substring(1) : pattern; pattern = pattern.replace("**", "*").replace('/', '.'); plugin.addParameter("filters/filter", "-" + pattern); } } }
From source file:org.sonar.server.plugins.BatchResourcesServlet.java
/** * @return part of request URL after servlet path *//* w ww. j a va 2s .c o m*/ String filename(HttpServletRequest request) { String filename = null; if (StringUtils.endsWithIgnoreCase(request.getRequestURI(), "jar")) { filename = StringUtils.substringAfterLast(request.getRequestURI(), "/"); } return filename; }