public void funnel(CharSequence from, PrimitiveSink into) { into.putString(from, charset); }
@Override public void write(byte[] bytes, int off, int len) { sink.putBytes(bytes, off, len); }
@Override public void funnel( final EdgeIdTypeKey from, final PrimitiveSink into ) { final UUID id = from.node.getUuid(); final String type = from.node.getType(); into.putLong( id.getMostSignificantBits() ); into.putLong( id.getLeastSignificantBits() ); into.putString( type, StringHashUtils.UTF8 ); into.putString( from.edgeType, StringHashUtils.UTF8 ); } };
public void testAsOutputStream() throws Exception { PrimitiveSink sink = mock(PrimitiveSink.class); OutputStream out = Funnels.asOutputStream(sink); byte[] bytes = {1, 2, 3, 4}; out.write(255); out.write(bytes); out.write(bytes, 1, 2); verify(sink).putByte((byte) 255); verify(sink).putBytes(bytes); verify(sink).putBytes(bytes, 1, 2); }
Funnels.stringFunnel().funnel((CharSequence) value, into); } else if (value instanceof Boolean) { into.putBoolean(((Boolean) value).booleanValue()); } else if (value instanceof Byte) { into.putByte(((Byte) value).byteValue()); } else if (value instanceof Double) { into.putDouble(((Double) value).doubleValue()); } else if (value instanceof BigDecimal) { String bdString = ((BigDecimal) value).toEngineeringString(); into.putString(bdString); } else if (value instanceof Float) { into.putFloat(((Float) value).floatValue()); } else if (value instanceof Integer) { into.putInt(((Integer) value).intValue()); } else if (value instanceof BigInteger) { byte[] bigBytes = ((BigInteger) value).toByteArray(); into.putBytes(bigBytes); } else if (value instanceof Long) { into.putLong(((Long) value).longValue()); } else if (value.getClass().isArray()) { int length = Array.getLength(value); into.putInt(length); for (int i = 0; i < length; i++) { Object arrayElem = Array.get(value, i); long most = uuid.getMostSignificantBits(); long least = uuid.getLeastSignificantBits(); into.putLong(most); into.putLong(least);
break; case BOOLEAN: into.putBoolean(((Boolean) value).booleanValue()); break; case BYTE: into.putByte(((Byte) value).byteValue()); break; case SHORT: into.putShort(((Short) value).byteValue()); break; case CHAR: into.putChar(((Character) value).charValue()); break; case INTEGER: into.putInt(((Integer) value).intValue()); break; case LONG: into.putLong(((Long) value).longValue()); break; case FLOAT: into.putFloat(((Float) value).floatValue()); break; case DOUBLE: into.putDouble(((Double) value).doubleValue()); break; case STRING: case CHAR_ARRAY: { int length = Array.getLength(value);
public void funnel(Integer from, PrimitiveSink into) { into.putInt(from); }
public void funnel(Long from, PrimitiveSink into) { into.putLong(from); }
public void funnel(CharSequence from, PrimitiveSink into) { into.putUnencodedChars(from); }
@Override public void write(int b) { sink.putByte((byte) b); }
@Override public void funnel(Map<String, String> from, PrimitiveSink into) { for (Entry<String, String> entry : from.entrySet()) { into.putUnencodedChars(entry.getKey()) .putByte((byte) -1) // separate key and value .putUnencodedChars(entry.getValue()); } } }
@Override public void funnel(DoubleVector from, PrimitiveSink into) { if (from.isSparse()) { Iterator<DoubleVectorElement> iterator = from.iterateNonZero(); while (iterator.hasNext()) { DoubleVectorElement next = iterator.next(); into.putInt(next.getIndex()); into.putDouble(next.getValue()); } } else { final int dimension = from.getDimension(); // traverse backwards, because sparse vectors are iterated descending, so // we get the same funneling for same vectors of different types. for (int i = dimension - 1; i >= 0; i--) { into.putInt(i); into.putDouble(from.get(i)); } } }
@Override void performAction(Random random, Iterable<? extends PrimitiveSink> sinks) { double value = random.nextDouble(); for (PrimitiveSink sink : sinks) { sink.putDouble(value); } } },
@Override void performAction(Random random, Iterable<? extends PrimitiveSink> sinks) { float value = random.nextFloat(); for (PrimitiveSink sink : sinks) { sink.putFloat(value); } } },
break; case BOOLEAN: into.putBoolean(((Boolean) value).booleanValue()); break; case BYTE: into.putByte(((Byte) value).byteValue()); break; case SHORT: into.putShort(((Short) value).byteValue()); break; case CHAR: into.putChar(((Character) value).charValue()); break; case INTEGER: into.putInt(((Integer) value).intValue()); break; case LONG: into.putLong(((Long) value).longValue()); break; case FLOAT: into.putFloat(((Float) value).floatValue()); break; case DOUBLE: into.putDouble(((Double) value).doubleValue()); break; case STRING: case CHAR_ARRAY: { int length = Array.getLength(value);
public void funnel(Integer from, PrimitiveSink into) { into.putInt(from); }
public void funnel(Long from, PrimitiveSink into) { into.putLong(from); }
public void funnel(CharSequence from, PrimitiveSink into) { into.putUnencodedChars(from); }
@Override public void write(int b) { sink.putByte((byte) b); }
public void testAsOutputStream() throws Exception { PrimitiveSink sink = mock(PrimitiveSink.class); OutputStream out = Funnels.asOutputStream(sink); byte[] bytes = { 1, 2, 3, 4 }; out.write(255); out.write(bytes); out.write(bytes, 1, 2); verify(sink).putByte((byte) 255); verify(sink).putBytes(bytes); verify(sink).putBytes(bytes, 1, 2); }