com.hfg.util.collection.MatrixCell Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
package com.hfg.util.collection;
//------------------------------------------------------------------------------
import java.util.Comparator;
/**
Representation of a Matrix cell.
@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 MatrixCell implements Cloneable
{
private RK mRowKey;
private CK mColKey;
private V mValue;
private int mSortedCellIndex = -1;
public static final MatrixCellValueComparator VALUE_COMPARATOR = new MatrixCellValueComparator();
//##########################################################################
// CONSTRUCTORS
//##########################################################################
//--------------------------------------------------------------------------
private MatrixCell()
{
}
//--------------------------------------------------------------------------
public MatrixCell(RK inRowKey, CK inColKey)
{
mRowKey = inRowKey;
mColKey = inColKey;
}
//--------------------------------------------------------------------------
public MatrixCell(RK inRowKey, CK inColKey, V inValue)
{
this(inRowKey, inColKey);
mValue = inValue;
}
//##########################################################################
// PUBLIC METHODS
//##########################################################################
//--------------------------------------------------------------------------
@Override
public String toString()
{
return mRowKey + ", " + mColKey + ": " + mValue;
}
//--------------------------------------------------------------------------
public MatrixCell setRowKey(RK inRowKey)
{
mRowKey = inRowKey;
return this;
}
//--------------------------------------------------------------------------
public RK getRowKey()
{
return mRowKey;
}
//--------------------------------------------------------------------------
public MatrixCell setColKey(CK inColKey)
{
mColKey = inColKey;
return this;
}
//--------------------------------------------------------------------------
public CK getColKey()
{
return mColKey;
}
//--------------------------------------------------------------------------
public V getValue()
{
return mValue;
}
//--------------------------------------------------------------------------
public MatrixCell setValue(V inValue)
{
mValue = inValue;
return this;
}
//--------------------------------------------------------------------------
public int getSortedCellIndex()
{
return mSortedCellIndex;
}
//--------------------------------------------------------------------------
public void setSortedCellIndex(int inValue)
{
mSortedCellIndex = inValue;
}
//--------------------------------------------------------------------------
@Override
public MatrixCell clone()
{
MatrixCell clone;
try
{
clone = (MatrixCell) super.clone();
}
catch (CloneNotSupportedException e)
{
throw new RuntimeException(e);
}
return clone;
}
//##########################################################################
// INNER CLASS
//##########################################################################
private static class MatrixCellValueComparator implements Comparator
{
public int compare(MatrixCell inCell1, MatrixCell inCell2)
{
int result = 0;
if (inCell1 != null)
{
if (inCell2 != null)
{
if (inCell1.getValue() != null)
{
if (inCell2.getValue() != null)
{
result = inCell1.getValue().compareTo(inCell2.getValue());
}
else
{
result = 1;
}
}
else if (inCell2.getValue() != null)
{
result = -1;
}
}
else
{
result = 1;
}
}
else if (inCell2 != null)
{
result = -1;
}
return result;
}
}
}