Ordinal implements DataType, EepDataListener { public Integer ordinalValue() { if(category != null) { return category.getSensorValue(); } else if(rawValue != null) { return rawValue; } else { return null; } } Ordinal(EepDataField dataField, CategoricalScale scale);  Ordinal(EepDataField dataField, int rawValue); Integer ordinalValue(); @Override void didUpdateData(EepData data); @Override void updateData(EepData data); @Override void updateSensor(Sensor sensor);  }
@Test public void testBasicConstruction() throws Exception { EepDataField dataField = new EepDataField("EDF1", 0, 8); ScaleCategory category1 = new ScaleCategory("Category 1", 0x00, 0x05, "CAT1", 1); ScaleCategory category2 = new ScaleCategory("Category 2", 0x06, 0x0A, "CAT2", 2); CategoricalScale scale = new CategoricalScale(category1, category2); Ordinal ordinal = new Ordinal(dataField, scale); Assert.assertNull(ordinal.ordinalValue()); ordinal = new Ordinal(dataField, 10); Assert.assertEquals(10, (int)ordinal.ordinalValue()); }
@Test public void testUpdateValue() throws Exception { EepDataField dataField = new EepDataField("EDF1", 0, 8); ScaleCategory category1 = new ScaleCategory("Category 1", 0x00, 0x05, "CAT1", 1); ScaleCategory category2 = new ScaleCategory("Category 2", 0x06, 0x0A, "CAT2", 2); CategoricalScale scale = new CategoricalScale(category1, category2); Ordinal ordinal = new Ordinal(dataField, scale); EepData data = new EepData(EepType.EEP_TYPE_F60201, 1, ordinal); data.update(new byte[] {0x00}); Assert.assertEquals(1, (int)ordinal.ordinalValue()); data.update(new byte[] {0x05}); Assert.assertEquals(1, (int)ordinal.ordinalValue()); data.update(new byte[] {0x06}); Assert.assertEquals(2, (int)ordinal.ordinalValue()); category1 = new ScaleCategory("Category 1", 0x03, 0x03, "CAT1", 1); category2 = new ScaleCategory("Category 2", 0x04, 0x04, "CAT2", 2); scale = new CategoricalScale(category1, category2); ordinal = new Ordinal(dataField, scale); data = new EepData(EepType.EEP_TYPE_F60201, 1, ordinal); data.update(new byte[] {0x03}); Assert.assertEquals(1, (int)ordinal.ordinalValue()); data.update(new byte[] {0x04}); Assert.assertEquals(2, (int)ordinal.ordinalValue()); }
@Test public void testUpdateWithOutOfRangeValue() throws Exception { EepDataField dataField = new EepDataField("EDF1", 0, 8); ScaleCategory category1 = new ScaleCategory("Category 1", 0x00, 0x05, "CAT1", 1); ScaleCategory category2 = new ScaleCategory("Category 2", 0x06, 0x0A, "CAT2", 2); CategoricalScale scale = new CategoricalScale(category1, category2); Ordinal ordinal = new Ordinal(dataField, scale); EepData data = new EepData(EepType.EEP_TYPE_F60201, 1, ordinal); Assert.assertNull(ordinal.ordinalValue()); data.update(new byte[]{(byte)0xFF}); Assert.assertNull(ordinal.ordinalValue()); data.update(new byte[]{(byte)0x06}); Assert.assertEquals(2, (int)ordinal.ordinalValue()); data.update(new byte[]{(byte)0xFF}); Assert.assertEquals(2, (int) ordinal.ordinalValue()); data.update(new byte[]{(byte)0x05}); Assert.assertEquals(1, (int)ordinal.ordinalValue()); }