
org.github.evenjn.align.alphabet.TupleAlignmentAlphabetSerializer Maven / Gradle / Ivy
/**
*
* Copyright 2016 Marco Trevisan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.github.evenjn.align.alphabet;
import java.util.function.Function;
import org.github.evenjn.yarn.Cursable;
import org.github.evenjn.yarn.Cursor;
import org.github.evenjn.yarn.Hook;
import org.github.evenjn.yarn.PastTheEndException;
public class TupleAlignmentAlphabetSerializer
implements Cursable {
private final Function a_serializer;
private final Function b_serializer;
private TupleAlignmentAlphabet alphabet;
public TupleAlignmentAlphabetSerializer(
TupleAlignmentAlphabet alphabet,
Function a_serializer,
Function b_serializer) {
this.alphabet = alphabet;
this.a_serializer = a_serializer;
this.b_serializer = b_serializer;
}
@Override
public Cursor pull( Hook hook ) {
return new Cursor( ) {
int id = 0;
@Override
public String next( )
throws PastTheEndException {
if (id >= alphabet.size( )) {
throw PastTheEndException.neo;
}
TupleAlignmentAlphabetPair next = alphabet.get( id );
StringBuilder builder = new StringBuilder( );
builder.append( id );
id++;
builder.append( "," );
builder.append( a_serializer.apply( next.above ) );
for ( SymbolBelow sb : next.below.asIterable( ) ) {
builder.append( "," );
builder.append( b_serializer.apply( sb ) );
}
return builder.toString( );
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy