org.apache.commons.lang.ObjectUtils#toString ( )源码实例Demo

下面列出了org.apache.commons.lang.ObjectUtils#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: DesignPatterns   文件: StatusCheckAspect.java
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();
    }
 
源代码2 项目: openhab1-addons   文件: CcuClient.java
@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);
    }
}
 
源代码3 项目: openhab1-addons   文件: PlugwiseBinding.java
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;
    }
 
源代码4 项目: openhab1-addons   文件: WeatherTokenResolver.java
/**
 * 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);
    }
}
 
源代码5 项目: tddl5   文件: HintRouter.java
private static String buildComparativeCondition(String key, Object value) {
    String type = "s";
    if (value instanceof Number) {
        type = "l";
    }
    return key + "=" + ObjectUtils.toString(value) + ":" + type;
}
 
源代码6 项目: tddl   文件: IndexChooser.java
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);
    }
}
 
源代码7 项目: tddl   文件: MergeConcurrentOptimizer.java
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);
    }
}
 
源代码8 项目: smarthome   文件: GetAllScriptsParser.java
@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;
}
 
源代码9 项目: openhab1-addons   文件: CcuClient.java
/**
 * {@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());
    }
}
 
源代码10 项目: openhab1-addons   文件: HomegearClient.java
/**
 * 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;
}
 
源代码11 项目: openhab1-addons   文件: UPBBinding.java
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);

}
 
源代码12 项目: openhab1-addons   文件: PlugwiseBinding.java
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);
                }
            }

        }

    }
 
源代码13 项目: openhab1-addons   文件: WeatherTokenResolver.java
/**
 * 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);
}
 
源代码14 项目: redisq   文件: StringPayloadSerializer.java
public String serialize(Object payload) throws SerializationException {
    return ObjectUtils.toString(payload);
}
 
源代码15 项目: tddl5   文件: ExtensionLoader.java
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));
        }
    }
}
 
源代码16 项目: smarthome   文件: DisplayTextVirtualDatapoint.java
@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);
    }
}
 
源代码17 项目: openhab1-addons   文件: TrimToNullStringAdapter.java
/**
 * {@inheritDoc}
 */
@Override
public String marshal(String value) throws Exception {
    return ObjectUtils.toString(value);
}
 
源代码18 项目: openhab1-addons   文件: BooleanTypeAdapter.java
/**
 * {@inheritDoc}
 */
@Override
public String marshal(Boolean value) throws Exception {
    return ObjectUtils.toString(value);
}
 
/**
 * Uses ObjectUtils.toString(Object) as default.
 * @param value
 * @return
 */
protected String formatValue(final T value)
{
  return ObjectUtils.toString(value);
}
 
源代码20 项目: projectforge-webapp   文件: JsonBuilder.java
/**
 * @param obj
 * @return
 * @see ObjectUtils#toString(Object)
 */
protected String formatValue(final Object obj)
{
  return ObjectUtils.toString(obj);
}