List of usage examples for org.apache.commons.lang ObjectUtils toString
public static String toString(Object obj)
Gets the toString
of an Object
returning an empty string ("") if null
input.
ObjectUtils.toString(null) = "" ObjectUtils.toString("") = "" ObjectUtils.toString("bat") = "bat" ObjectUtils.toString(Boolean.TRUE) = "true"
From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.parser.CommonRpcParser.java
/** * Converts the object to a boolean.// w w w . j a va 2 s. c o m */ protected Boolean toBoolean(Object object) { if (object == null || object instanceof Boolean) { return (Boolean) object; } return BooleanUtils.toBoolean(ObjectUtils.toString(object)); }
From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.parser.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);// w ww . ja v a2 s.com dpScript.setInfo(scriptName); channel.addDatapoint(dpScript); } return null; }
From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.server.RpcResponseHandler.java
/** * Returns a valid result of the method called by the Homematic gateway. *//*from ww w. ja va 2 s .c om*/ public T handleMethodCall(String methodName, Object[] responseData) throws IOException { if (RPC_METHODNAME_EVENT.equals(methodName)) { return handleEvent(responseData); } else if (RPC_METHODNAME_LIST_DEVICES.equals(methodName) || RPC_METHODNAME_UPDATE_DEVICE.equals(methodName)) { return getEmptyArrayResult(); } else if (RPC_METHODNAME_DELETE_DEVICES.equals(methodName)) { return handleDeleteDevice(responseData); } else if (RPC_METHODNAME_NEW_DEVICES.equals(methodName)) { return handleNewDevice(responseData); } else if (RPC_METHODNAME_SYSTEM_LISTMETHODS.equals(methodName)) { RpcRequest<T> msg = createRpcRequest(); msg.addArg(getListMethods()); return msg.createMessage(); } else if (RPC_METHODNAME_SYSTEM_MULTICALL.equals(methodName)) { for (Object o : (Object[]) responseData[0]) { Map<?, ?> call = (Map<?, ?>) o; if (call != null) { String method = ObjectUtils.toString(call.get("methodName")); Object[] data = (Object[]) call.get("params"); handleMethodCall(method, data); } } return getEmptyEventListResult(); } else if (RPC_METHODNAME_SET_CONFIG_READY.equals(methodName)) { return getEmptyEventListResult(); } else { logger.warn("Unknown method called by Homematic gateway: {}", methodName); return getEmptyEventListResult(); } }
From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DisplayTextVirtualDatapoint.java
@Override public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value) throws IOException, HomematicClientException { dp.setValue(value);//from w w w.j a v a 2 s. c o m 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); } }
From source file:org.eclipse.smarthome.binding.homematic.internal.type.HomematicTypeGeneratorImpl.java
private void generateConfigDescription(HmDevice device, URI configDescriptionURI) { List<ConfigDescriptionParameter> parms = new ArrayList<ConfigDescriptionParameter>(); List<ConfigDescriptionParameterGroup> groups = new ArrayList<ConfigDescriptionParameterGroup>(); for (HmChannel channel : device.getChannels()) { String groupName = "HMG_" + channel.getNumber(); String groupLabel = MetadataUtils.getDescription("CHANNEL_NAME") + " " + channel.getNumber(); groups.add(new ConfigDescriptionParameterGroup(groupName, null, false, groupLabel, null)); for (HmDatapoint dp : channel.getDatapoints()) { if (dp.getParamsetType() == HmParamsetType.MASTER) { ConfigDescriptionParameterBuilder builder = ConfigDescriptionParameterBuilder.create( MetadataUtils.getParameterName(dp), MetadataUtils.getConfigDescriptionParameterType(dp)); builder.withLabel(MetadataUtils.getLabel(dp)); builder.withDefault(ObjectUtils.toString(dp.getDefaultValue())); builder.withDescription(MetadataUtils.getDatapointDescription(dp)); if (dp.isEnumType()) { builder.withLimitToOptions(dp.isEnumType()); List<ParameterOption> options = MetadataUtils.generateOptions(dp, new OptionsBuilder<ParameterOption>() { @Override public ParameterOption createOption(String value, String description) { return new ParameterOption(value, description); }//from w w w. ja va 2s .c om }); builder.withOptions(options); } if (dp.isNumberType()) { builder.withMinimum(MetadataUtils.createBigDecimal(dp.getMinValue())); builder.withMaximum(MetadataUtils.createBigDecimal(dp.getMaxValue())); builder.withStepSize( MetadataUtils.createBigDecimal(dp.isFloatType() ? new Float(0.1) : 1L)); builder.withUnitLabel(MetadataUtils.getUnit(dp)); } builder.withGroupName(groupName); parms.add(builder.build()); } } } configDescriptionProvider.addConfigDescription(new ConfigDescription(configDescriptionURI, parms, groups)); }
From source file:org.eclipse.wb.core.gef.policy.PolicyUtils.java
/** * Translates given {@link Translatable} from model coordinates into feedback layer coordinates. *///ww w.j av a 2 s. c o m public static void translateModelToFeedback(GraphicalEditPolicy policy, Translatable t) { if (policy instanceof LayoutEditPolicy) { translateAbsoluteToModel((LayoutEditPolicy) policy, t); } else if (policy instanceof SelectionEditPolicy) { translateAbsoluteToModel((SelectionEditPolicy) policy, t); } else { throw new IllegalArgumentException(ObjectUtils.toString(policy)); } }
From source file:org.eclipse.wb.internal.core.utils.binding.editors.StringComboEditor.java
public void setValue(Object value) { m_field.setText(ObjectUtils.toString(value)); }
From source file:org.eclipse.wb.internal.core.utils.binding.editors.StringListEditor.java
public void setValue(Object value) { String stringValue = ObjectUtils.toString(value); String[] values = StringUtils.split(stringValue, m_separator); List elements = new ArrayList(); CollectionUtils.addAll(elements, values); m_field.setElements(elements);/* w ww . j av a 2 s .c o m*/ }
From source file:org.eclipse.wb.internal.core.utils.binding.providers.StringPreferenceProvider.java
public void setValue(Object value) { m_store.setValue(m_key, ObjectUtils.toString(value)); }
From source file:org.eclipse.wb.internal.core.utils.binding.ValueUtils.java
/** * Extract <code>boolean</code> from given object. *///from w ww . java 2s . co m public static boolean objectToBoolean(Object value) { // extract from Boolean if (value instanceof Boolean) { Boolean booleanObject = (Boolean) value; return booleanObject.booleanValue(); } // extract from Object String stringObject = ObjectUtils.toString(value); return BooleanUtils.toBoolean(stringObject); }