Skip to content

Implement SourceChanger?! #224

Open
Open
@tischi

Description

@tischi

@NicoKiaru

Do you think this could be useful? If it works I think it could avoid quite some code duplication:

public class SourceChanger< T > implements Supplier< SourceAndConverter< ? > >
{
    private final SourceAndConverter< ? > sourceAndConverter;
    private final Function< Source< ? >, Source< ? > > sourceConverter;

    public SourceChanger( SourceAndConverter< T > sourceAndConverter, Function< Source< ? >, Source< ? > > sourceConverter )
    {
        this.sourceAndConverter = sourceAndConverter;
        this.sourceConverter = sourceConverter;
    }

    public SourceAndConverter< ? > get()
    {
        Source< ? > src = sourceConverter.apply( sourceAndConverter.getSpimSource() );

        if ( sourceAndConverter.asVolatile() != null )
        {
            Source< ? > vsrc = sourceConverter.apply( sourceAndConverter.asVolatile().getSpimSource() );

            SourceAndConverter< ? > vsac = new SourceAndConverter( vsrc, sourceAndConverter.asVolatile().getConverter(), sourceAndConverter.asVolatile() );

            final SourceAndConverter< ? > sourceAndConverter = new SourceAndConverter( src, this.sourceAndConverter.getConverter(), vsac );
            
            return sourceAndConverter;
        }
        else
        {
            final SourceAndConverter< ? > sourceAndConverter = new SourceAndConverter( src, this.sourceAndConverter.getConverter() );
            
            return sourceAndConverter;
        }
    }
}

The Function< Source< ? >, Source< ? > > sourceConverter would for example return a TransformedSource or a WarpedSource, given an input Source.

For this one needs to create a SourceTransformer implements Function< Source< ? >, Source< ? > > and a SourceWarper implements Function< Source< ? >, Source< ? > >. But we needed this anyway (see e.g. SourceResampler). The advantage would be that with above code the SourceResampler does not need to deal with the generic is of creating also the Volatile versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions