@Override public ByteBuffer toByteBuffer(Date obj) { if (obj == null) { return null; } return LONG_SERIALIZER.toByteBuffer(obj.getTime()); }
@Override public ByteBuffer toByteBuffer(Double obj) { if (obj == null) { return null; } return LongSerializer.get().toByteBuffer(Double.doubleToRawLongBits(obj)); }
private void test(Long number) { assertEquals(number, ext.fromByteBuffer(ext.toByteBuffer(number))); // test compatibility with ByteBuffer default byte order if (number != null) { ByteBuffer b = ByteBuffer.allocate(8); b.putLong(number); b.rewind(); assertEquals(number, ext.fromByteBuffer(b)); } } }
@Test public void testConstruction() { List<Column> tColumns = new ArrayList<Column>(); ColumnSlice<String, Long> slice = new ColumnSliceImpl<String, Long>(tColumns, se, le); Assert.assertTrue(slice.getColumns().isEmpty()); Column column = new Column(ByteBuffer.wrap(new byte[]{})); column.setValue(ByteBuffer.wrap(new byte[]{})); column.setTimestamp(0L); tColumns.add(column); slice = new ColumnSliceImpl<String, Long>(tColumns, se, le); Assert.assertEquals(1, slice.getColumns().size()); tColumns = new ArrayList<Column>(); column = new Column(se.toByteBuffer("1")); column.setValue(le.toByteBuffer(1L)); column.setTimestamp(0L); tColumns.add(column); slice = new ColumnSliceImpl<String, Long>(tColumns, se, le); Assert.assertEquals((Long) 1L, slice.getColumnByName("1").getValue()); }
@Test public void testConstruction() { LongSerializer le = LongSerializer.get(); StringSerializer se = StringSerializer.get(); ByteBufferSerializer be = ByteBufferSerializer.get(); // empty one List<SuperColumn> tColumns = new ArrayList<SuperColumn>(); SuperSlice<String, Long, ByteBuffer> slice = new SuperSliceImpl<String, Long, ByteBuffer>(tColumns, se, le, be); Assert.assertTrue(slice.getSuperColumns().isEmpty()); // non-empty one Column c = new Column(le.toByteBuffer(5L)); c.setValue(be.toByteBuffer(ByteBuffer.wrap(new byte[] { 1 }))); c.setTimestamp(2L); tColumns.add(new SuperColumn(se.toByteBuffer("super"), Arrays.asList(c))); slice = new SuperSliceImpl<String, Long, ByteBuffer>(tColumns, se, le, be); Assert.assertEquals(1, slice.getSuperColumns().size()); Assert.assertEquals((Long) 5L, slice.getColumnByName("super").get(0).getName()); } }
@Override public ByteBuffer toByteBuffer(Date obj) { if (obj == null) { return null; } return LONG_SERIALIZER.toByteBuffer(obj.getTime()); }
@Override public ByteBuffer toByteBuffer(Date obj) { if (obj == null) { return null; } return LONG_SERIALIZER.toByteBuffer(obj.getTime()); }
@Override public ByteBuffer toByteBuffer(Double obj) { if (obj == null) { return null; } return LongSerializer.get().toByteBuffer(Double.doubleToRawLongBits(obj)); }
@Override public ByteBuffer toByteBuffer(Double obj) { if (obj == null) { return null; } return LongSerializer.get().toByteBuffer(Double.doubleToRawLongBits(obj)); }
public ByteBuffer toValue(Long value) throws IOException { return LongSerializer.get().toByteBuffer(value); }