DiscreteAttribute extends AbstractIndexableAttribute implements RangeAttribute { @Override public int registerXAttribute(XAttribute att) { if (att instanceof XAttributeDiscrete && this.getKey().equals(att.getKey())) { long value = ((XAttributeDiscrete) att).getValue(); if (!indexMap.containsKey(value)) { values.add(value); indexMap.put(value, values.size()-1); return (values.size()-1); } else { return -1; } } else { return -1; } } DiscreteAttribute(String key, AttributeLevel level); @Override int registerXAttribute(XAttribute att); @Override ImmutableList<Object> getValues(); @Override int getValueIndex(Object value); @Override Object getValue(int index); @Override int getValueSize(); @Override Object getMin(); @Override Object getMax();  }
@Test public void testRegisterXAttributeWithInvalidType() { DiscreteAttribute att = new DiscreteAttribute("concept:name", AttributeLevel.EVENT); int result = att.registerXAttribute(xAttFactory.createAttributeContinuous("concept:name", 100, null)); Assert.assertEquals(-1, result); }
@Test public void testRegisterXAttributeWithInvalidKey() { DiscreteAttribute att = new DiscreteAttribute("concept:name", AttributeLevel.EVENT); int result = att.registerXAttribute(xAttFactory.createAttributeDiscrete("invalid_key", 100, null)); Assert.assertEquals(-1, result); }
@Test public void testRegisterValidXAttribute() { DiscreteAttribute att = new DiscreteAttribute("concept:name", AttributeLevel.EVENT); XAttributeDiscrete xatt = xAttFactory.createAttributeDiscrete("concept:name", 100, null); int result = att.registerXAttribute(xatt); Assert.assertEquals(0, result); }