Hi Together,

I refactored the branch (refactoring/java_generify) a bit so that you now can 
do following:

PlcReadRequest req = new BulkPlcReadRequest()
req.addItem(new ReadRequestItem<>(Byte.class, inputs));
req.addItem(new ReadRequestItem<>(Boolean.class, outputs, 3));
CompletableFuture future = plcReader.read(req);
PlcReadResponse resp = (PlcReadResponse) future.get();
Only difference on the requirement from Chris is, that you now need a specific 
request implementation and add the <> onto the Request Items.
Currently following Types are implemented (PlcReadRequest* is a interface now):
BulkPlc(Read|Write)Re(quest|ponse)
CheckedBulkPlc(Read|Write)Re(quest|ponse)
SinglePlc(Read|Write)Re(quest|ponse)

The tag of the pre-refacotring is „pre_bulk_refactoring“ if needed for 
comparison (On branch refactoring/java_generify).

Essential is the hierarchy of the implementation now:

                        PlcReadRequest
                        /                       \
SinglePlcReadRequest            BulkPlcReadRequest
                                                                |
                                                CheckedBulkPlcReadRequest

With this following Signatures can be used to conveniently work with strong 
typing:

public interface PlcReader {

    CompletableFuture<? extends PlcReadResponse> read(PlcReadRequest 
readRequest);

    @SuppressWarnings("unchecked")
    default <T> CompletableFuture<SinglePlcReadResponse<T>> 
read(SinglePlcReadRequest<T> readRequest) {
        return (CompletableFuture<SinglePlcReadResponse<T>>) 
read((PlcReadRequest) readRequest);
    }

    @SuppressWarnings("unchecked")
    default CompletableFuture<BulkPlcReadResponse> read(BulkPlcReadRequest 
readRequest) {
        return (CompletableFuture<BulkPlcReadResponse>) read((PlcReadRequest) 
readRequest);
    }

   @SuppressWarnings("unchecked")
    default <T> CompletableFuture<CheckedBulkPlcReadResponse<T>> 
read(CheckedBulkPlcReadRequest<T> readRequest) {
        return (CompletableFuture<CheckedBulkPlcReadResponse<T>>) 
read((PlcReadRequest) readRequest);
    }

}


The mentioned hierarchy is essential to make the overloaded methods work.

As always Im happy about feedback :)

Sebastian

Reply via email to