@Test public void testNormalizeSIGNED_8_BIT_INTEGER() { ZclAttributeNormalizer normalizer = new ZclAttributeNormalizer(); assertEquals(Integer.valueOf(123), normalizer.normalizeZclData(ZclDataType.SIGNED_8_BIT_INTEGER, Double.valueOf(123))); }
protected Object normalizeZclData(ZclDataType dataType, Object data) { try { switch (dataType) { case BOOLEAN: if (data instanceof Integer) { logger.debug("Normalizing data Integer {} to BOOLEAN", data); return Boolean.valueOf(!((Integer) data).equals(0)); } break; case UNSIGNED_8_BIT_INTEGER: if (data instanceof String) { logger.debug("Normalizing data String {} to UNSIGNED_8_BIT_INTEGER", data); return Integer.parseInt((String) data); } if (data instanceof Double) { logger.debug("Normalizing data Double {} to UNSIGNED_8_BIT_INTEGER", data); return ((Double) data).intValue(); } break; case UNSIGNED_16_BIT_INTEGER: if (data instanceof Double) { logger.debug("Normalizing data Double {} to UNSIGNED_16_BIT_INTEGER", data); return ((Double) data).intValue(); } break; case SIGNED_8_BIT_INTEGER: if (data instanceof Double) { logger.debug("Normalizing data Double {} to SIGNED_8_BIT_INTEGER", data); return ((Double) data).intValue(); } break; case SIGNED_16_BIT_INTEGER: if (data instanceof Double) { logger.debug("Normalizing data Double {} to SIGNED_16_BIT_INTEGER", data); return ((Double) data).intValue(); } break; default: break; } return data; } catch (NumberFormatException e) { logger.warn("Exception normalizing data: Returning default value of {}", dataType); return getDefaultValue(dataType); } }
ZclAttributeNormalizer { protected Object normalizeZclData(ZclDataType dataType, Object data) { try { switch (dataType) { case BOOLEAN: if (data instanceof Integer) { logger.debug("Normalizing data Integer {} to BOOLEAN", data); return Boolean.valueOf(!((Integer) data).equals(0)); } break; case UNSIGNED_8_BIT_INTEGER: if (data instanceof String) { logger.debug("Normalizing data String {} to UNSIGNED_8_BIT_INTEGER", data); return Integer.parseInt((String) data); } if (data instanceof Double) { logger.debug("Normalizing data Double {} to UNSIGNED_8_BIT_INTEGER", data); return ((Double) data).intValue(); } break; case UNSIGNED_16_BIT_INTEGER: if (data instanceof Double) { logger.debug("Normalizing data Double {} to UNSIGNED_16_BIT_INTEGER", data); return ((Double) data).intValue(); } break; case SIGNED_8_BIT_INTEGER: if (data instanceof Double) { logger.debug("Normalizing data Double {} to SIGNED_8_BIT_INTEGER", data); return ((Double) data).intValue(); } break; case SIGNED_16_BIT_INTEGER: if (data instanceof Double) { logger.debug("Normalizing data Double {} to SIGNED_16_BIT_INTEGER", data); return ((Double) data).intValue(); } break; default: break; } return data; } catch (NumberFormatException e) { logger.warn("Exception normalizing data: Returning default value of {}", dataType); return getDefaultValue(dataType); } } }
ZclAttributeNormalizer { protected Object normalizeZclData(ZclDataType dataType, Object data) { try { switch (dataType) { case BOOLEAN: if (data instanceof Integer) { logger.debug("Normalizing data Integer {} to BOOLEAN", data); return Boolean.valueOf(!((Integer) data).equals(0)); } break; case UNSIGNED_8_BIT_INTEGER: if (data instanceof String) { logger.debug("Normalizing data String {} to UNSIGNED_8_BIT_INTEGER", data); return Integer.parseInt((String) data); } if (data instanceof Double) { logger.debug("Normalizing data Double {} to UNSIGNED_8_BIT_INTEGER", data); return ((Double) data).intValue(); } break; case UNSIGNED_16_BIT_INTEGER: if (data instanceof Double) { logger.debug("Normalizing data Double {} to UNSIGNED_16_BIT_INTEGER", data); return ((Double) data).intValue(); } break; case SIGNED_8_BIT_INTEGER: if (data instanceof Double) { logger.debug("Normalizing data Double {} to SIGNED_8_BIT_INTEGER", data); return ((Double) data).intValue(); } break; case SIGNED_16_BIT_INTEGER: if (data instanceof Double) { logger.debug("Normalizing data Double {} to SIGNED_16_BIT_INTEGER", data); return ((Double) data).intValue(); } break; default: break; } return data; } catch (NumberFormatException e) { logger.warn("Exception normalizing data: Returning default value of {}", dataType); return getDefaultValue(dataType); } }  }
ZclAttributeNormalizer { protected Object normalizeZclData(ZclDataType dataType, Object data) { try { switch (dataType) { case BOOLEAN: if (data instanceof Integer) { logger.debug("Normalizing data Integer {} to BOOLEAN", data); return Boolean.valueOf(!((Integer) data).equals(0)); } break; case UNSIGNED_8_BIT_INTEGER: if (data instanceof String) { logger.debug("Normalizing data String {} to UNSIGNED_8_BIT_INTEGER", data); return Integer.parseInt((String) data); } if (data instanceof Double) { logger.debug("Normalizing data Double {} to UNSIGNED_8_BIT_INTEGER", data); return ((Double) data).intValue(); } break; case UNSIGNED_16_BIT_INTEGER: if (data instanceof Double) { logger.debug("Normalizing data Double {} to UNSIGNED_16_BIT_INTEGER", data); return ((Double) data).intValue(); } break; case SIGNED_8_BIT_INTEGER: if (data instanceof Double) { logger.debug("Normalizing data Double {} to SIGNED_8_BIT_INTEGER", data); return ((Double) data).intValue(); } break; case SIGNED_16_BIT_INTEGER: if (data instanceof Double) { logger.debug("Normalizing data Double {} to SIGNED_16_BIT_INTEGER", data); return ((Double) data).intValue(); } break; default: break; } return data; } catch (NumberFormatException e) { logger.warn("Exception normalizing data: Returning default value of {}", dataType); return getDefaultValue(dataType); } }   }
ZclAttributeNormalizer { protected Object normalizeZclData(ZclDataType dataType, Object data) { try { switch (dataType) { case BOOLEAN: if (data instanceof Integer) { logger.debug("Normalizing data Integer {} to BOOLEAN", data); return Boolean.valueOf(!((Integer) data).equals(0)); } break; case UNSIGNED_8_BIT_INTEGER: if (data instanceof String) { logger.debug("Normalizing data String {} to UNSIGNED_8_BIT_INTEGER", data); return Integer.parseInt((String) data); } if (data instanceof Double) { logger.debug("Normalizing data Double {} to UNSIGNED_8_BIT_INTEGER", data); return ((Double) data).intValue(); } break; case UNSIGNED_16_BIT_INTEGER: if (data instanceof Double) { logger.debug("Normalizing data Double {} to UNSIGNED_16_BIT_INTEGER", data); return ((Double) data).intValue(); } break; case SIGNED_8_BIT_INTEGER: if (data instanceof Double) { logger.debug("Normalizing data Double {} to SIGNED_8_BIT_INTEGER", data); return ((Double) data).intValue(); } break; case SIGNED_16_BIT_INTEGER: if (data instanceof Double) { logger.debug("Normalizing data Double {} to SIGNED_16_BIT_INTEGER", data); return ((Double) data).intValue(); } break; default: break; } return data; } catch (NumberFormatException e) { logger.warn("Exception normalizing data: Returning default value of {}", dataType); return getDefaultValue(dataType); } }    }