Java Code Examples for org.apache.commons.lang.ObjectUtils#toString()
The following examples show how to use
org.apache.commons.lang.ObjectUtils#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatusCheckAspect.java From DesignPatterns with Apache License 2.0 | 6 votes |
private CheckResult check(Method method, Object[] paramValues) { boolean isMExist = method.isAnnotationPresent(StatusCheck.class); if(isMExist){ Parameter[] parameters = method.getParameters(); if(parameters.length >= 2) { if(paramValues != null) { String updateStatusCode = ObjectUtils.toString(paramValues[0]); String fromStatusCode = ObjectUtils.toString(paramValues[1]); System.out.println("AOP实际校验逻辑。。。。" + updateStatusCode + "----" + fromStatusCode); if("1".equals(updateStatusCode)) { CheckResult checkResult = new CheckResult(); checkResult.setCheckResult(1); checkResult.setCheckMessage("校验失败"); return checkResult; } } } } return new CheckResult(); }
Example 2
Source File: WeatherTokenResolver.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
/** * Replaces the token with properties of the weather LocationConfig object. */ private String replaceConfig(Token token) { LocationConfig locationConfig = WeatherContext.getInstance().getConfig().getLocationConfig(locationId); if (locationConfig == null) { throw new RuntimeException("Weather locationId '" + locationId + "' does not exist"); } if ("latitude".equals(token.name)) { return locationConfig.getLatitude().toString(); } else if ("longitude".equals(token.name)) { return locationConfig.getLongitude().toString(); } else if ("name".equals(token.name)) { return locationConfig.getName(); } else if ("language".equals(token.name)) { return locationConfig.getLanguage(); } else if ("updateInterval".equals(token.name)) { return ObjectUtils.toString(locationConfig.getUpdateInterval()); } else if ("locationId".equals(token.name)) { return locationConfig.getLocationId(); } else if ("providerName".equals(token.name)) { return ObjectUtils.toString(locationConfig.getProviderName()); } else { throw new RuntimeException("Invalid weather token: " + token.full); } }
Example 3
Source File: PlugwiseBinding.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
private Stick setupStick(Dictionary<String, ?> config) { String port = ObjectUtils.toString(config.get("stick.port"), null); if (port == null) { return null; } Stick stick = new Stick(port, this); logger.debug("Plugwise added Stick connected to serial port {}", port); String interval = ObjectUtils.toString(config.get("stick.interval"), null); if (interval != null) { stick.setInterval(Integer.valueOf(interval)); logger.debug("Setting the interval to send ZigBee PDUs to {} ms", interval); } String retries = ObjectUtils.toString(config.get("stick.retries"), null); if (retries != null) { stick.setRetries(Integer.valueOf(retries)); logger.debug("Setting the maximum number of attempts to send a message to ", retries); } return stick; }
Example 4
Source File: CcuClient.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
@Override public void setDatapointValue(HmDatapoint dp, String datapointName, Object value) throws HomematicClientException { HmInterface hmInterface = dp.getChannel().getDevice().getHmInterface(); if (hmInterface == HmInterface.VIRTUALDEVICES) { String groupName = HmInterface.VIRTUALDEVICES + "." + dp.getChannel().getAddress() + "." + datapointName; if (dp.isIntegerValue() && value instanceof Double) { value = ((Number) value).intValue(); } String strValue = ObjectUtils.toString(value); if (dp.isStringValue()) { strValue = "\"" + strValue + "\""; } HmResult result = sendScriptByName("setVirtualGroup", HmResult.class, new String[] { "group_name", "group_state" }, new String[] { groupName, strValue }); if (!result.isValid()) { throw new HomematicClientException("Unable to set CCU group " + groupName); } } else { super.setDatapointValue(dp, datapointName, value); } }
Example 5
Source File: HintRouter.java From tddl5 with Apache License 2.0 | 5 votes |
private static String buildComparativeCondition(String key, Object value) { String type = "s"; if (value instanceof Number) { type = "l"; } return key + "=" + ObjectUtils.toString(value) + ":" + type; }
Example 6
Source File: IndexChooser.java From tddl with Apache License 2.0 | 5 votes |
private static boolean chooseIndex(Map<String, Object> extraCmd) { String ifChooseIndex = ObjectUtils.toString(GeneralUtil.getExtraCmdString(extraCmd, ExtraCmd.CHOOSE_INDEX)); // 默认返回true if (StringUtils.isEmpty(ifChooseIndex)) { return true; } else { return BooleanUtils.toBoolean(ifChooseIndex); } }
Example 7
Source File: MergeConcurrentOptimizer.java From tddl with Apache License 2.0 | 5 votes |
private static boolean isMergeConcurrent(Map<String, Object> extraCmd, IMerge query) { String value = ObjectUtils.toString(GeneralUtil.getExtraCmdString(extraCmd, ExtraCmd.MERGE_CONCURRENT)); if (StringUtils.isEmpty(value)) { if (query.getSql() != null) { // 如果存在sql,那说明是hint直接路由 return true; } if ((query.getLimitFrom() != null || query.getLimitTo() != null)) { if (query.getOrderBys() == null || query.getOrderBys().isEmpty()) { // 存在limit,但不存在order by时不允许走并行 return false; } } else if ((query.getOrderBys() == null || query.getOrderBys().isEmpty()) && (query.getGroupBys() == null || query.getGroupBys().isEmpty()) && query.getHavingFilter() == null) { if (isNoFilter(query)) { // 没有其他的order by / group by / having / // where等条件时,就是个简单的select * // from xxx,暂时也不做并行 return false; } } return true; } else { return BooleanUtils.toBoolean(value); } }
Example 8
Source File: GetAllScriptsParser.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public Void parse(Object[] message) throws IOException { message = (Object[]) message[0]; for (int i = 0; i < message.length; i++) { String scriptName = ObjectUtils.toString(message[i]); HmDatapoint dpScript = new HmDatapoint(scriptName, scriptName, HmValueType.BOOL, Boolean.FALSE, false, HmParamsetType.VALUES); dpScript.setInfo(scriptName); channel.addDatapoint(dpScript); } return null; }
Example 9
Source File: WeatherTokenResolver.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Replaces the token with a property of the weather object. */ private String replaceWeather(Token token, Weather instance) throws Exception { if (!PropertyUtils.hasProperty(instance, token.name)) { throw new RuntimeException("Invalid weather token: " + token.full); } Object propertyValue = PropertyUtils.getPropertyValue(instance, token.name); if (token.unit != null && propertyValue instanceof Double) { propertyValue = UnitUtils.convertUnit((Double) propertyValue, token.unit, token.name); } if (token.formatter != null) { return String.format(token.formatter, propertyValue); } return ObjectUtils.toString(propertyValue); }
Example 10
Source File: PlugwiseBinding.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
private void setupNonStickDevices(Dictionary<String, ?> config) { Set<String> deviceNames = getDeviceNamesFromConfig(config); for (String deviceName : deviceNames) { if ("stick".equals(deviceName)) { continue; } if (stick.getDeviceByName(deviceName) != null) { continue; } String MAC = ObjectUtils.toString(config.get(deviceName + ".mac"), null); if (MAC == null || MAC.equals("")) { logger.warn("Plugwise cannot add device with name {} without a MAC address", deviceName); } else if (stick.getDeviceByMAC(MAC) != null) { logger.warn( "Plugwise cannot add device with name: {} and MAC address: {}, " + "the same MAC address is already used by device with name: {}", deviceName, MAC, stick.getDeviceByMAC(MAC).name); } else { String deviceType = ObjectUtils.toString(config.get(deviceName + ".type"), null); PlugwiseDevice device = createPlugwiseDevice(deviceType, MAC, deviceName); if (device != null) { stick.addDevice(device); } } } }
Example 11
Source File: CcuClient.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void setVariable(HmValueItem hmValueItem, Object value) throws HomematicClientException { String strValue = ObjectUtils.toString(value); if (hmValueItem.isStringValue()) { strValue = "\"" + strValue + "\""; } logger.debug("Sending {} with value '{}' to CCU", hmValueItem.getName(), strValue); HmResult result = sendScriptByName("setVariable", HmResult.class, new String[] { "variable_name", "variable_state" }, new String[] { hmValueItem.getName(), strValue }); if (!result.isValid()) { throw new HomematicClientException("Unable to set CCU variable " + hmValueItem.getName()); } }
Example 12
Source File: HomegearClient.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Parses the datapoint informations into the binding model. */ private HmDatapoint parseDatapoint(HmChannel channel, String name, Map<String, ?> dpData) throws IllegalAccessException { HmDatapoint dp = new HmDatapoint(); dp.setName(name); FieldUtils.writeField(dp, "channel", channel, true); FieldUtils.writeField(dp, "writeable", dpData.get("WRITEABLE"), true); Object valueList = dpData.get("VALUE_LIST"); if (valueList != null && valueList instanceof Object[]) { Object[] vl = (Object[]) valueList; String[] stringArray = new String[vl.length]; for (int i = 0; i < vl.length; i++) { stringArray[i] = vl[i].toString(); } FieldUtils.writeField(dp, "valueList", stringArray, true); } Object value = dpData.get("VALUE"); String type = (String) dpData.get("TYPE"); boolean isString = StringUtils.equals("STRING", type); if (isString && value != null && !(value instanceof String)) { value = ObjectUtils.toString(value); } setValueType(dp, type, value); if (dp.isNumberValueType()) { FieldUtils.writeField(dp, "minValue", dpData.get("MIN"), true); FieldUtils.writeField(dp, "maxValue", dpData.get("MAX"), true); } dp.setValue(value); return dp; }
Example 13
Source File: UPBBinding.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
private void parseConfiguration(final Map<String, Object> configuration) { port = ObjectUtils.toString(configuration.get("port"), null); network = Integer.valueOf(ObjectUtils.toString(configuration.get("network"), "0")).byteValue(); logger.debug("Parsed UPB configuration:"); logger.debug("Serial port: {}", port); logger.debug("UPB Network: {}", network & 0xff); }
Example 14
Source File: StringPayloadSerializer.java From redisq with MIT License | 4 votes |
public String serialize(Object payload) throws SerializationException { return ObjectUtils.toString(payload); }
Example 15
Source File: BooleanTypeAdapter.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public String marshal(Boolean value) throws Exception { return ObjectUtils.toString(value); }
Example 16
Source File: TrimToNullStringAdapter.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public String marshal(String value) throws Exception { return ObjectUtils.toString(value); }
Example 17
Source File: DisplayTextVirtualDatapoint.java From smarthome with Eclipse Public License 2.0 | 4 votes |
@Override public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value) throws IOException, HomematicClientException { dp.setValue(value); if (DATAPOINT_NAME_DISPLAY_SUBMIT.equals(dp.getName()) && MiscUtils.isTrueValue(dp.getValue())) { HmChannel channel = dp.getChannel(); boolean isEp = isEpDisplay(channel.getDevice()); List<String> message = new ArrayList<String>(); message.add(START); if (isEp) { message.add(LF); } for (int i = 1; i <= getLineCount(channel.getDevice()); i++) { String line = ObjectUtils.toString( channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_LINE + i).getValue()); if (StringUtils.isEmpty(line)) { line = " "; } message.add(LINE); message.add(encodeText(line)); if (!isEp) { String color = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_COLOR + i) .getOptionValue(); message.add(COLOR); String colorCode = Color.getCode(color); message.add(StringUtils.isBlank(colorCode) ? Color.WHITE.getCode() : colorCode); } String icon = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_ICON + i) .getOptionValue(); String iconCode = Icon.getCode(icon); if (StringUtils.isNotBlank(iconCode)) { message.add(ICON); message.add(iconCode); } message.add(LF); } if (isEp) { String beeper = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_BEEPER) .getOptionValue(); message.add(BEEPER_START); message.add(Beeper.getCode(beeper)); message.add(BEEPER_END); // set number of beeps message.add( encodeBeepCount(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_BEEPCOUNT))); message.add(BEEPCOUNT_END); // set interval between two beeps message.add(encodeBeepInterval( channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_BEEPINTERVAL))); message.add(BEEPINTERVAL_END); // LED value must always set (same as beeps) String led = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_LED).getOptionValue(); message.add(Led.getCode(led)); } message.add(STOP); gateway.sendDatapoint(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_SUBMIT), new HmDatapointConfig(), StringUtils.join(message, ","), null); } }
Example 18
Source File: ExtensionLoader.java From tddl5 with Apache License 2.0 | 4 votes |
private static <S> S loadFile(Class<S> service, String activateName, ClassLoader loader) { try { boolean foundFromCache = true; List<Class> extensions = providers.get(service); if (extensions == null) { synchronized (service) { extensions = providers.get(service); if (extensions == null) { extensions = findAllExtensionClass(service, activateName, loader); foundFromCache = false; providers.put(service, extensions); } } } // 为避免被覆盖,每个activateName的查找,允许再加一层子目录 if (StringUtils.isNotEmpty(activateName)) { loadFile(service, TDDL_DIRECTORY + activateName.toLowerCase() + "/", loader, extensions); List<Class> activateExtensions = new ArrayList<Class>(); for (int i = 0; i < extensions.size(); i++) { Class clz = extensions.get(i); Activate activate = (Activate) clz.getAnnotation(Activate.class); if (activate != null && activateName.equals(activate.name())) { activateExtensions.add(clz); } } extensions = activateExtensions; } if (extensions.isEmpty()) { throw new ExtensionNotFoundException("not found service provider for : " + service.getName() + "[" + activateName + "] and classloader : " + ObjectUtils.toString(loader)); } Class<?> extension = extensions.get(extensions.size() - 1);// 最大的一个 S result = service.cast(extension.newInstance()); if (!foundFromCache && logger.isInfoEnabled()) { logger.info("load " + service.getSimpleName() + "[" + activateName + "] extension by class[" + extension.getName() + "]"); } return result; } catch (Throwable e) { if (e instanceof ExtensionNotFoundException) { throw (ExtensionNotFoundException) e; } else { throw new ExtensionNotFoundException("not found service provider for : " + service.getName() + " caused by " + ExceptionUtils.getFullStackTrace(e)); } } }
Example 19
Source File: JsonBuilder.java From projectforge-webapp with GNU General Public License v3.0 | 2 votes |
/** * @param obj * @return * @see ObjectUtils#toString(Object) */ protected String formatValue(final Object obj) { return ObjectUtils.toString(obj); }
Example 20
Source File: PFAutoCompleteTextField.java From projectforge-webapp with GNU General Public License v3.0 | 2 votes |
/** * Uses ObjectUtils.toString(Object) as default. * @param value * @return */ protected String formatValue(final T value) { return ObjectUtils.toString(value); }