@Test public void testConstructor_Types_Precision_Scale_Default() throws OperationException { System.out.println("NumberField(Types, int, int, Number)"); for (Types type : Types.values()) { try { new NumberField(type, 1, 0, new Integer(0)); if (!isNumberType(type)) { fail("Incorrectly accepted " + type.getType() + " as a valid number type"); } } catch (OperationException ex) { if (isNumberType(type) && !typeTakesPrecisionAndScale(type)) { assertEquals(ErrorCode.DATATYPE_ERROR, ex.getErrorCode()); } else if (isNumberType(type)) { fail("Incorrectly reported " + type.getType() + " as an invalid number type"); } } if (!typeTakesPrecisionAndScale(type)) { continue; } for (int i = 1; i <= 127; i++) { try { new NumberField(type, i, 0, new Integer(0)); } catch (OperationException ex) { fail("Failed to accept " + i + " as a valid precision value for type " + type.getType()); } } for (int i = -84; i <= 127; i++) { try { new NumberField(type, 127, i, new Integer(0)); } catch (OperationException ex) { fail("Failed to accept " + i + " as a valid scale value for type " + type.getType()); } } new NumberField(type, 10, 2, new Integer(-1)); new NumberField(type, 10, 2, new Integer(0)); new NumberField(type, 10, 2, new Integer(1)); new NumberField(type, 10, 2, new Float(-1.1)); new NumberField(type, 10, 2, new Float(0.0)); new NumberField(type, 10, 2, new Float(1.1)); new NumberField(type, 10, 2, new Double(-1.1)); new NumberField(type, 10, 2, new Double(0.0)); new NumberField(type, 10, 2, new Double(1.1)); new NumberField(type, 10, 2, new Short((short) -1)); new NumberField(type, 10, 2, new Short((short) 0)); new NumberField(type, 10, 2, new Short((short) 1)); new NumberField(type, 10, 2, new Long(1)); new NumberField(type, 10, 2, new Long(0)); new NumberField(type, 10, 2, new Long(1)); try { new NumberField(type, 1, 0, new Integer(-10)); fail(type.getType() + " accepted numeric value violating precision / scale constraint"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_CONSTRAINT_VIOLATION, ex.getErrorCode()); } try { new NumberField(type, 1, 0, new Integer(10)); fail(type.getType() + " accepted numeric value violating precision / scale constraint"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_CONSTRAINT_VIOLATION, ex.getErrorCode()); } try { new NumberField(type, 1, 1, new Float(-10.1)); fail(type.getType() + " accepted numeric value violating precision / scale constraint"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_CONSTRAINT_VIOLATION, ex.getErrorCode()); } try { new NumberField(type, 1, 1, new Float(10.1)); fail(type.getType() + " accepted numeric value violating precision / scale constraint"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_CONSTRAINT_VIOLATION, ex.getErrorCode()); } try { new NumberField(type, 1, 1, new Double(-10.1)); fail(type.getType() + " accepted numeric value violating precision / scale constraint"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_CONSTRAINT_VIOLATION, ex.getErrorCode()); } try { new NumberField(type, 1, 1, new Double(10.1)); fail(type.getType() + " accepted numeric value violating precision / scale constraint"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_CONSTRAINT_VIOLATION, ex.getErrorCode()); } try { new NumberField(type, 1, 0, new Short((short) -10)); fail(type.getType() + " accepted numeric value violating precision / scale constraint"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_CONSTRAINT_VIOLATION, ex.getErrorCode()); } try { new NumberField(type, 1, 0, new Short((short) 10)); fail(type.getType() + " accepted numeric value violating precision / scale constraint"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_CONSTRAINT_VIOLATION, ex.getErrorCode()); } try { new NumberField(type, 1, 0, new Long(10)); fail(type.getType() + " accepted numeric value violating precision / scale constraint"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_CONSTRAINT_VIOLATION, ex.getErrorCode()); } try { new NumberField(type, 1, 0, new Long(10)); fail(type.getType() + " accepted numeric value violating precision / scale constraint"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_CONSTRAINT_VIOLATION, ex.getErrorCode()); } try { new NumberField(type, 0, 0, new Integer(0)); fail(type.getType() + " type accepted value with precision of 0, where as precision has to be greater than or equal to one"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_ERROR, ex.getErrorCode()); } try { new NumberField(type, -1, 0, new Integer(0)); fail(type.getType() + " type accepted value with precision of -1, where as precision has to be greater than or equal to one"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_ERROR, ex.getErrorCode()); } try { new NumberField(type, 2, 2, new Integer(0)); } catch (OperationException ex) { fail(type.getType() + " type did not accept terminal condition of precision equal to scale"); } try { new NumberField(type, 2, 3, new Integer(0)); fail(type.getType() + " type accepted precision greater than scale, whereas precision must be less than or equal to scale"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_ERROR, ex.getErrorCode()); } try { new NumberField(type, 128, 0, new Integer(0)); fail(type.getType() + " type accepted value with precision of 128, where as maximum permitted precision is 127"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_ERROR, ex.getErrorCode()); } try { new NumberField(type, 127, -85, new Integer(0)); fail("Accepted -85 as a valid scale value, when minimum permissible scale value is -84"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_ERROR, ex.getErrorCode()); } try { new NumberField(type, 127, 128, new Integer(0)); fail("Accepted 128 as a valid scale value, when maximum permissible scale value is 127"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_ERROR, ex.getErrorCode()); } } }
@Override public Types getType() { return type; }
NumberField implements FieldType<Number> { @Override public Types getType() { return type; } }
NumberField implements FieldType<Number> { @Override public Types getType() { return type; } NumberField(final Types type);  NumberField(final Types type, final Number defaultValue);  NumberField(final Types type, final int precision);  NumberField(final int scale, final Types type);  NumberField(final Types type, final int precision, final Number defaultValue);  NumberField(final int scale, final Types type, final Number defaultValue);  NumberField(final Types type, final int precision, final int scale);  NumberField(final Types type, final int precision, final int scale, final Number defaultValue); }
NumberField implements FieldType<Number> { @Override public Types getType() { return type; } NumberField(final Types type);  NumberField(final Types type, final Number defaultValue);  NumberField(final Types type, final int precision);  NumberField(final int scale, final Types type);  NumberField(final Types type, final int precision, final Number defaultValue);  NumberField(final int scale, final Types type, final Number defaultValue);  NumberField(final Types type, final int precision, final int scale);  NumberField(final Types type, final int precision, final int scale, final Number defaultValue); @Override Types getType(); int getPrecision(); Integer getScale(); @Override Number getDefaultValue(); @Override boolean hasDefaultValue(); @Override Number convert(Object objValue); @Override JSONObject toJson(); }
NumberField implements FieldType<Number> { @Override public Types getType() { return type; } NumberField(final Types type);  NumberField(final Types type, final Number defaultValue);  NumberField(final Types type, final int precision);  NumberField(final int scale, final Types type);  NumberField(final Types type, final int precision, final Number defaultValue);  NumberField(final int scale, final Types type, final Number defaultValue);  NumberField(final Types type, final int precision, final int scale);  NumberField(final Types type, final int precision, final int scale, final Number defaultValue); @Override Types getType(); int getPrecision(); Integer getScale(); @Override Number getDefaultValue(); @Override boolean hasDefaultValue(); @Override Number convert(Object objValue); @Override JSONObject toJson();  }