Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package io.deephaven.csv.sinks;
import io.deephaven.csv.util.MutableObject;
import java.util.function.Supplier;
/**
* An interface which allows the CsvReader to write to column data structures whose details it is unaware of. Using this
* interface, the caller provides factory methods that make a Sink<TARRAY> for the corresponding data type. The
* integral parsers (byte, short, int, long) also provide a Source<TARRAY> via an out parameter, because the
* inference algorithm wants a fast path for reading back data it has already written. This is used in the case where
* the algorithm makes some forward progress on a numeric type but then decides to fall back to a wider numeric type.
* The system also supports more general kinds of fallback (e.g. from int to string), but in cases like that the system
* just reparses the original input text rather than asking the collection to read the data back.
*
*
* For example, if the system has parsed N shorts for a given column and then encounters an int value that doesn't fit
* in a short (or, alternatively, it encounters a reserved short and needs to reject it), it will read back the shorts
* already written and write them to an integer sink instead.
*
*
* The methods allow the caller to specify "reserved" values for types where it makes sense to have one. If a reserved
* value is encountered, the type inference process will move to the next wider type and try again. In typical practice
* this is used in systems that have a reserved sentinel value that represents null. For example, for a byte column, a
* system might reserve the value ((byte)-128) to represent the null byte, yet allow ((short)-128) to be a permissible
* short value. Likewise a system might reserve the value ((short)-32768) to represent the null short, but allow
* ((int)-32768) to be a permissible int value.
*
*
* Thread safety: Implementing classes are required to be threadsafe, because the methods in this interface are likely
* to be invoked concurrently.
*/
public interface SinkFactory {
/**
* Create a {@link SinkFactory} from the corresponding lambdas. As a service to the caller, we make the
* {@link SinkFactory} threadsafe by synchronizing all the forXXX methods. This is probably not necessary for most
* suppliers but we do it in order to provide an extra level of protection.
*/
static & Source, TSHORTSINK extends Sink & Source, TINTSINK extends Sink & Source, TLONGSINK extends Sink & Source, TFLOATSINK extends Sink, TDOUBLESINK extends Sink, TBOOLASBYTESINK extends Sink, TCHARSINK extends Sink, TSTRINGSINK extends Sink, TDATETIMEASLONGSINK extends Sink, TTIMESTAMPASLONGSINK extends Sink> SinkFactory of(
Supplier byteSinkSupplier,
Byte reservedByte,
Supplier shortSinkSupplier,
Short reservedShort,
Supplier intSinkSupplier,
Integer reservedInt,
Supplier longSinkSupplier,
Long reservedLong,
Supplier floatSinkSupplier,
Float reservedFloat,
Supplier doubleSinkSupplier,
Double reservedDouble,
Supplier booleanAsByteSinkSupplier, // no Byte reservedBooleanAsByte,
Supplier charSinkSupplier,
Character reservedChar,
Supplier stringSinkSupplier,
String reservedString,
Supplier dateTimeAsLongSinkSupplier,
Long reservedDateTimeAsLong,
Supplier timestampAsLongSinkSupplier,
Long reservedTimestampAsLong) {
return new SinkFactory() {
@Override
public synchronized Sink forByte(MutableObject> source) {
final TBYTESINK result = byteSinkSupplier.get();
source.setValue(result);
return result;
}
@Override
public Byte reservedByte() {
return reservedByte;
}
@Override
public synchronized Sink forShort(MutableObject> source) {
final TSHORTSINK result = shortSinkSupplier.get();
source.setValue(result);
return result;
}
@Override
public Short reservedShort() {
return reservedShort;
}
@Override
public synchronized Sink forInt(MutableObject> source) {
final TINTSINK result = intSinkSupplier.get();
source.setValue(result);
return result;
}
@Override
public Integer reservedInt() {
return reservedInt;
}
@Override
public synchronized Sink forLong(MutableObject> source) {
final TLONGSINK result = longSinkSupplier.get();
source.setValue(result);
return result;
}
@Override
public Long reservedLong() {
return reservedLong;
}
@Override
public synchronized Sink forFloat() {
return floatSinkSupplier.get();
}
@Override
public Float reservedFloat() {
return reservedFloat;
}
@Override
public synchronized Sink forDouble() {
return doubleSinkSupplier.get();
}
@Override
public Double reservedDouble() {
return reservedDouble;
}
@Override
public synchronized Sink forBooleanAsByte() {
return booleanAsByteSinkSupplier.get();
}
@Override
public synchronized Sink forChar() {
return charSinkSupplier.get();
}
@Override
public Character reservedChar() {
return reservedChar;
}
@Override
public synchronized Sink forString() {
return stringSinkSupplier.get();
}
@Override
public String reservedString() {
return reservedString;
}
@Override
public synchronized Sink forDateTimeAsLong() {
return dateTimeAsLongSinkSupplier.get();
}
@Override
public Long reservedDateTimeAsLong() {
return reservedDateTimeAsLong;
}
@Override
public synchronized Sink forTimestampAsLong() {
return timestampAsLongSinkSupplier.get();
}
@Override
public Long reservedTimestampAsLong() {
return reservedTimestampAsLong;
}
};
}
/** Provide a Sink and a Source for the byte representation. */
Sink forByte(MutableObject> source);
/** The optional reserved value for the byte representation. */
Byte reservedByte();
/** Provide a Sink and a Source for the short representation. */
Sink forShort(MutableObject> source);
/** The optional reserved value for the short representation. */
Short reservedShort();
/** Provide a Sink and a Source for the int representation. */
Sink forInt(MutableObject> source);
/** The optional reserved value for the int representation. */
Integer reservedInt();
/** Provide a Sink and a Source for the long representation. */
Sink forLong(MutableObject> source);
/** The optional reserved value for the long representation. */
Long reservedLong();
/** Provide a Sink for the float representation. */
Sink forFloat();
/** The optional reserved value for the float representation. */
Float reservedFloat();
/** Provide a Sink for the double representation. */
Sink forDouble();
/** The optional reserved value for the double representation. */
Double reservedDouble();
/** Provide a Sink for the boolean (as byte) representation. */
Sink forBooleanAsByte();
// there is no reserved value for the boolean as byte representation, as none is needed.
/** Provide a Sink for the char representation. */
Sink forChar();
/** The optional reserved value for the char representation. */
Character reservedChar();
/** Provide a Sink for the String representation. */
Sink forString();
/** The optional reserved value for the String representation. */
String reservedString();
/** Provide a Sink for the DateTime (as long) representation. */
Sink forDateTimeAsLong();
/** The optional reserved value for the DateTime (as long) representation. */
Long reservedDateTimeAsLong();
/** Provide a Sink for the Timestamp (as long) representation. */
Sink forTimestampAsLong();
/** The optional reserved value for the Timestamp (as long) representation. */
Long reservedTimestampAsLong();
}