@Test public void testStrangeValues() { { ValueNode vn = getValueNode( " true" ); assertNotNull( vn ); assertTrue( vn.isBooleanNode() ); assertTrue( vn instanceof BooleanNode ); assertTrue( ((BooleanNode) vn).getValue() ); } { ValueNode vn = getValueNode( " false " ); assertNotNull( vn ); assertTrue( vn.isBooleanNode() ); assertTrue( vn instanceof BooleanNode ); assertFalse( ((BooleanNode) vn).getValue() ); } { ValueNode vn = getValueNode( " 1 " ); assertNotNull( vn ); assertTrue( vn.isLongNode() ); assertTrue( vn instanceof LongNode ); assertEquals( 1L, ((LongNode) vn).getValue() ); } { ValueNode vn = getValueNode( " - 123456789 " ); assertNotNull( vn ); assertFalse( vn.isLongNode() ); assertTrue( vn.isTextNode() ); } { ValueNode vn = getValueNode( "-123456789-" ); assertNotNull( vn ); assertFalse( vn.isLongNode() ); assertTrue( vn.isTextNode() ); } { ValueNode vn = getValueNode( "0.0" ); assertNotNull( vn ); assertTrue( vn.isDoubleNode() ); assertTrue( vn instanceof DoubleNode ); assertEquals( 0d, ((DoubleNode) vn).getValue(), 0.01 ); } { ValueNode vn = getValueNode( "0.001" ); assertNotNull( vn ); assertTrue( vn.isDoubleNode() ); assertTrue( vn instanceof DoubleNode ); assertEquals( 0.001d, ((DoubleNode) vn).getValue(), 0.0001 ); } { ValueNode vn = getValueNode( "1234567.8901" ); assertNotNull( vn ); assertTrue( vn.isDoubleNode() ); assertTrue( vn instanceof DoubleNode ); assertEquals( 1234567.8901d, ((DoubleNode) vn).getValue(), 0.001 ); } { ValueNode vn = getValueNode( "-1234567.8901" ); assertNotNull( vn ); assertTrue( vn.isDoubleNode() ); assertTrue( vn instanceof DoubleNode ); assertEquals( -1234567.8901d, ((DoubleNode) vn).getValue(), 0.001 ); } { ValueNode vn = getValueNode( "123.45E2" ); assertNotNull( vn ); assertFalse( vn.isDoubleNode() ); assertTrue( vn.isTextNode() ); assertTrue( vn instanceof TextNode ); } { ValueNode vn = getValueNode( "" ); assertNotNull( vn ); assertTrue( vn.isTextNode() ); assertTrue( vn instanceof TextNode ); assertEquals( "", ((TextNode) vn).getValue() ); } { ValueNode vn = getValueNode( " test\n " ); assertNotNull( vn ); assertTrue( vn.isTextNode() ); assertTrue( vn instanceof TextNode ); assertEquals( "test", ((TextNode) vn).getValue() ); } { ValueNode vn = getValueNode( "test 123 " ); assertNotNull( vn ); assertTrue( vn.isTextNode() ); assertTrue( vn instanceof TextNode ); assertEquals( "test 123", ((TextNode) vn).getValue() ); } }
public ValueNode getValueNode( String value ) { if ( value == null ) { return NullNode.getInstance(); } value = value.trim(); if ( value != null && ("true".equalsIgnoreCase( value.trim() ) || "false".equalsIgnoreCase( value.trim() ))) { try { boolean b = Boolean.parseBoolean( value.trim() ); return BooleanNode.valueOf( b ); } catch ( Exception e ) { } } if ( LONG_PATTERN.matcher( value ).matches() ) { try { long l = Long.parseLong( value ); return LongNode.valueOf( l ); } catch ( NumberFormatException e ) { } } if ( DOUBLE_PATTERN.matcher( value ).matches() ) { try { double d = Double.parseDouble( value ); return DoubleNode.valueOf( d ); } catch ( NumberFormatException e ) { } } return TextNode.valueOf( value ); }
ValueNodeFactory { public ValueNode getValueNode( String value ) { if ( value == null ) { return NullNode.getInstance(); } value = value.trim(); if ( value != null && ("true".equalsIgnoreCase( value.trim() ) || "false".equalsIgnoreCase( value.trim() ))) { try { boolean b = Boolean.parseBoolean( value.trim() ); return BooleanNode.valueOf( b ); } catch ( Exception e ) { } } if ( LONG_PATTERN.matcher( value ).matches() ) { try { long l = Long.parseLong( value ); return LongNode.valueOf( l ); } catch ( NumberFormatException e ) { } } if ( DOUBLE_PATTERN.matcher( value ).matches() ) { try { double d = Double.parseDouble( value ); return DoubleNode.valueOf( d ); } catch ( NumberFormatException e ) { } } return TextNode.valueOf( value ); } }
ValueNodeFactory { public ValueNode getValueNode( String value ) { if ( value == null ) { return NullNode.getInstance(); } value = value.trim(); if ( value != null && ("true".equalsIgnoreCase( value.trim() ) || "false".equalsIgnoreCase( value.trim() ))) { try { boolean b = Boolean.parseBoolean( value.trim() ); return BooleanNode.valueOf( b ); } catch ( Exception e ) { } } if ( LONG_PATTERN.matcher( value ).matches() ) { try { long l = Long.parseLong( value ); return LongNode.valueOf( l ); } catch ( NumberFormatException e ) { } } if ( DOUBLE_PATTERN.matcher( value ).matches() ) { try { double d = Double.parseDouble( value ); return DoubleNode.valueOf( d ); } catch ( NumberFormatException e ) { } } return TextNode.valueOf( value ); }  }
ValueNodeFactory { public ValueNode getValueNode( String value ) { if ( value == null ) { return NullNode.getInstance(); } value = value.trim(); if ( value != null && ("true".equalsIgnoreCase( value.trim() ) || "false".equalsIgnoreCase( value.trim() ))) { try { boolean b = Boolean.parseBoolean( value.trim() ); return BooleanNode.valueOf( b ); } catch ( Exception e ) { } } if ( LONG_PATTERN.matcher( value ).matches() ) { try { long l = Long.parseLong( value ); return LongNode.valueOf( l ); } catch ( NumberFormatException e ) { } } if ( DOUBLE_PATTERN.matcher( value ).matches() ) { try { double d = Double.parseDouble( value ); return DoubleNode.valueOf( d ); } catch ( NumberFormatException e ) { } } return TextNode.valueOf( value ); }  ValueNode getValueNode( String value ); }
ValueNodeFactory { public ValueNode getValueNode( String value ) { if ( value == null ) { return NullNode.getInstance(); } value = value.trim(); if ( value != null && ("true".equalsIgnoreCase( value.trim() ) || "false".equalsIgnoreCase( value.trim() ))) { try { boolean b = Boolean.parseBoolean( value.trim() ); return BooleanNode.valueOf( b ); } catch ( Exception e ) { } } if ( LONG_PATTERN.matcher( value ).matches() ) { try { long l = Long.parseLong( value ); return LongNode.valueOf( l ); } catch ( NumberFormatException e ) { } } if ( DOUBLE_PATTERN.matcher( value ).matches() ) { try { double d = Double.parseDouble( value ); return DoubleNode.valueOf( d ); } catch ( NumberFormatException e ) { } } return TextNode.valueOf( value ); }  ValueNode getValueNode( String value ); public Pattern LONG_PATTERN; public Pattern DOUBLE_PATTERN; }