All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.maizegenetics.analysis.chart.ManhattanNumberFormat Maven / Gradle / Ivy

Go to download

TASSEL is a software package to evaluate traits associations, evolutionary patterns, and linkage disequilibrium.

The newest version!
/*
 *  ManhattanNumberFormat
 * 
 *  Created on Dec 8, 2016
 */
package net.maizegenetics.analysis.chart;

import java.text.FieldPosition;
import java.text.NumberFormat;
import java.text.ParsePosition;
import java.util.List;

/**
 *
 * @author Terry Casstevens
 */
public class ManhattanNumberFormat extends NumberFormat {

    private final List myActualPosition;
    private final NumberFormat myBase;

    public ManhattanNumberFormat(NumberFormat base, List actualPosition) {
        myBase = base;
        myActualPosition = actualPosition;
    }

    @Override
    public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
        return myBase.format(translate((long) number), toAppendTo, pos);
    }

    @Override
    public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
        return myBase.format(translate(number), toAppendTo, pos);
    }

    @Override
    public Number parse(String source, ParsePosition parsePosition) {
        return myBase.parse(source, parsePosition);
    }

    private long translate(long number) {
        long result = 0l;
        for (long current : myActualPosition) {
            if (number >= current) {
                result = current;
            } else {
                break;
            }
        }
        return number - result;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy