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

com.hfg.bio.seq.alignment.PctId Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.bio.seq.alignment;


import com.hfg.html.HTMLTag;
import com.hfg.html.Span;
import com.hfg.util.CompareUtil;

//------------------------------------------------------------------------------
/**
 Container for holding percent identity components.
 
@author J. Alex Taylor, hairyfatguy.com
*/ //------------------------------------------------------------------------------ // com.hfg Library // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com // [email protected] //------------------------------------------------------------------------------ public class PctId implements Comparable { private Integer mNumIdentities; private Integer mComparisonLength; private String mFormatString = "%.1f"; //########################################################################## // CONSTRUCTORS //########################################################################## //-------------------------------------------------------------------------- public PctId() { } //-------------------------------------------------------------------------- public PctId(int inNumIdenties, int inComparisonLength) { mNumIdentities = inNumIdenties; mComparisonLength = inComparisonLength; } //########################################################################## // PUBLIC METHODS //########################################################################## //-------------------------------------------------------------------------- public int getNumIdentities() { return mNumIdentities; } //-------------------------------------------------------------------------- public PctId addIdentities(int inValue) { if (mNumIdentities != null) { mNumIdentities += inValue; } else { mNumIdentities = inValue; } return this; } //-------------------------------------------------------------------------- public int getComparisonLength() { return mComparisonLength; } //-------------------------------------------------------------------------- public PctId addComparisonLength(int inValue) { if (mComparisonLength != null) { mComparisonLength += inValue; } else { mComparisonLength = inValue; } return this; } //-------------------------------------------------------------------------- public PctId setFormatString(String inValue) { mFormatString = inValue; return this; } //-------------------------------------------------------------------------- public float floatValue() { float result = 0.0f; if (mNumIdentities != null && mComparisonLength != null) { result = (mComparisonLength > 0 ? 100f * mNumIdentities.floatValue() / mComparisonLength.floatValue() : 0.0f); } return result; } //-------------------------------------------------------------------------- public int intValue() { return (int) floatValue(); } //-------------------------------------------------------------------------- @Override public String toString() { return String.format(mFormatString, floatValue()); } //-------------------------------------------------------------------------- public HTMLTag toHTMLTag() { return new Span(toString()).setTitle(getNumIdentities() + " / " + getComparisonLength()); } //-------------------------------------------------------------------------- @Override public int hashCode() { return intValue(); } //--------------------------------------------------------------------------- @Override public boolean equals(Object inObj2) { return (inObj2 != null && inObj2 instanceof PctId && 0 == compareTo((PctId) inObj2)); } //-------------------------------------------------------------------------- @Override public int compareTo(PctId inObj2) { int result = -1; if (inObj2 != null) { result = CompareUtil.compare(floatValue(), inObj2.floatValue()); } return result; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy