@Override public AnyValue value( int offset ) { return Values.byteValue( value[offset] ); }
private static ByteValue readByte( ByteBuffer chunk, int offset ) { return byteValue( chunk.get( offset ) ); }
/** * @see RandomValues */ public ByteValue nextByteValue() { return byteValue( (byte) generator.nextInt() ); }
/** * Returns the next {@link ByteValue} between 0 (inclusive) and the specified value (exclusive) * * @param bound the upper bound (exclusive). Must be positive. * @return {@link ByteValue} */ public ByteValue nextByteValue( byte bound ) { return byteValue( (byte) generator.nextInt( bound ) ); }
@Override public Value value( PropertyBlock block, PropertyStore store ) { return Values.byteValue( block.getSingleValueByte() ); } },
private ByteValue readByte() { return Values.byteValue( PropertyBlock.fetchByte( currentBlock() ) ); }
public static NumberValue numberValue( Number number ) { if ( number instanceof Long ) { return longValue( number.longValue() ); } if ( number instanceof Integer ) { return intValue( number.intValue() ); } if ( number instanceof Double ) { return doubleValue( number.doubleValue() ); } if ( number instanceof Byte ) { return byteValue( number.byteValue() ); } if ( number instanceof Float ) { return floatValue( number.floatValue() ); } if ( number instanceof Short ) { return shortValue( number.shortValue() ); } throw new UnsupportedOperationException( "Unsupported type of Number " + number.toString() ); }
private static Test shouldNotMatch( byte propertyValue, Object value ) { return new Test( Values.byteValue( propertyValue ), value, false ); }
private static Test shouldMatch( byte propertyValue, Object value ) { return new Test( Values.byteValue( propertyValue ), value, true ); }
@Test public void shouldTurnAllIntegerTypesToLongs() { AnyValue[] values = new AnyValue[]{byteValue( (byte) 13 ), shortValue( (short) 13 ), intValue( 13 ), longValue( 13L )}; for ( AnyValue val : values ) { val.writeTo( converter ); Object value = converter.value(); assertThat( value, instanceOf( Long.class ) ); assertThat( value, equalTo( 13L ) ); } }
@Test void shouldSubtractSimpleIntegers() { NumberValue[] integers = new NumberValue[]{byteValue( (byte) 42 ), shortValue( (short) 42 ), intValue( 42 ), longValue( 42 )}; for ( NumberValue a : integers ) { for ( NumberValue b : integers ) { assertThat( a.minus( b ), equalTo( longValue( 0 ) ) ); assertThat( b.minus( a ), equalTo( longValue( 0 ) ) ); } } }
@Test void shouldHandleLists() { // Given PrettyPrinter printer = new PrettyPrinter(); ListValue list = VirtualValues.list( stringValue( "foo" ), byteValue( (byte) 42 ) ); // When list.writeTo( printer ); // Then assertThat( printer.value(), equalTo( "[\"foo\", 42]" ) ); }
@Test void shouldAddSimpleIntegers() { NumberValue[] integers = new NumberValue[]{byteValue( (byte) 42 ), shortValue( (short) 42 ), intValue( 42 ), longValue( 42 )}; for ( NumberValue a : integers ) { for ( NumberValue b : integers ) { assertThat( a.plus( b ), equalTo( longValue( 84 ) ) ); assertThat( b.plus( a ), equalTo( longValue( 84 ) ) ); } } }
@Test void shouldMultiplySimpleIntegers() { NumberValue[] integers = new NumberValue[]{byteValue( (byte) 42 ), shortValue( (short) 42 ), intValue( 42 ), longValue( 42 )}; for ( NumberValue a : integers ) { for ( NumberValue b : integers ) { assertThat( a.times( b ), equalTo( longValue( 42 * 42 ) ) ); assertThat( b.times( a ), equalTo( longValue( 42 * 42 ) ) ); } } }
@Test void shouldDivideSimpleIntegers() { NumberValue[] integers = new NumberValue[]{byteValue( (byte) 42 ), shortValue( (short) 42 ), intValue( 42 ), longValue( 42 )}; for ( NumberValue a : integers ) { for ( NumberValue b : integers ) { assertThat( a.divideBy( b ), equalTo( longValue( 1 ) ) ); assertThat( b.divideBy( a ), equalTo( longValue( 1 ) ) ); } } }
@Test void shouldSubtractSimpleFloats() { NumberValue[] integers = new NumberValue[]{byteValue( (byte) 42 ), shortValue( (short) 42 ), intValue( 42 ), longValue( 42 )}; NumberValue[] floats = new NumberValue[]{floatValue( 42 ), doubleValue( 42 )}; for ( NumberValue a : integers ) { for ( NumberValue b : floats ) { assertThat( a.minus( b ), equalTo( doubleValue( 0 ) ) ); assertThat( b.minus( a ), equalTo( doubleValue( 0 ) ) ); } } }
@Test void shouldMultiplySimpleFloats() { NumberValue[] integers = new NumberValue[]{byteValue( (byte) 42 ), shortValue( (short) 42 ), intValue( 42 ), longValue( 42 )}; NumberValue[] floats = new NumberValue[]{floatValue( 42 ), doubleValue( 42 )}; for ( NumberValue a : integers ) { for ( NumberValue b : floats ) { assertThat( a.times( b ), equalTo( doubleValue( 42 * 42 ) ) ); assertThat( b.times( a ), equalTo( doubleValue( 42 * 42 ) ) ); } } }
@Test void shouldDivideSimpleFloats() { NumberValue[] integers = new NumberValue[]{byteValue( (byte) 42 ), shortValue( (short) 42 ), intValue( 42 ), longValue( 42 )}; NumberValue[] floats = new NumberValue[]{floatValue( 42 ), doubleValue( 42 )}; for ( NumberValue a : integers ) { for ( NumberValue b : floats ) { assertThat( a.divideBy( b ), equalTo( doubleValue( 1.0 ) ) ); assertThat( b.divideBy( a ), equalTo( doubleValue( 1.0 ) ) ); } } }
@Test void shouldAddSimpleFloats() { NumberValue[] integers = new NumberValue[]{byteValue( (byte) 42 ), shortValue( (short) 42 ), intValue( 42 ), longValue( 42 )}; NumberValue[] floats = new NumberValue[]{floatValue( 42 ), doubleValue( 42 )}; for ( NumberValue a : integers ) { for ( NumberValue b : floats ) { assertThat( a.plus( b ), equalTo( doubleValue( 84 ) ) ); assertThat( b.plus( a ), equalTo( doubleValue( 84 ) ) ); } } }
@Test void shouldNotEqualVirtualValue() { VirtualValue virtual = new MyVirtualValue( 42 ); assertNotEqual( booleanValue( false ), virtual ); assertNotEqual( byteValue( (byte)0 ), virtual ); assertNotEqual( shortValue( (short)0 ), virtual ); assertNotEqual( intValue( 0 ), virtual ); assertNotEqual( longValue( 0 ), virtual ); assertNotEqual( floatValue( 0.0f ), virtual ); assertNotEqual( doubleValue( 0.0 ), virtual ); assertNotEqual( stringValue( "" ), virtual ); } }