com.hfg.automation.platelayer.LayerWell 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.automation.platelayer;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import com.hfg.automation.AutomationException;
import com.hfg.automation.Well;
import com.hfg.automation.WellRef;
import com.hfg.automation.WellType;
import com.hfg.exception.ProgrammingException;
import com.hfg.units.Quantity;
import com.hfg.util.CompareUtil;
import com.hfg.util.StringUtil;
import com.hfg.util.collection.CollectionUtil;
import com.hfg.util.collection.OrderedSet;
//------------------------------------------------------------------------------
/**
Generic well in a plate that supports layers.
@author J. Alex Taylor, hairyfatguy.com
*/
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding 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 LayerWell implements Well, Comparable
{
private WellRef mLocation;
private WellType mType;
private LayerPlate mPlate;
private List mLayers;
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//---------------------------------------------------------------------------
public LayerWell(WellRef inLocation)
{
mLocation = inLocation;
}
//---------------------------------------------------------------------------
public LayerWell(WellRef inLocation, WellType inType)
{
mLocation = inLocation;
mType = inType;
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//---------------------------------------------------------------------------
@Override
public int compareTo(LayerWell inLayerWell)
{
int result = 1;
if (inLayerWell instanceof LayerWell)
{
LayerWell otherLayerWell = (LayerWell) inLayerWell;
result = CompareUtil.compare(getRef().getColIndex(), otherLayerWell.getRef().getColIndex());
if (0 == result)
{
result = CompareUtil.compare(getRef().getRowIndex(), otherLayerWell.getRef().getRowIndex());
}
}
return result;
}
//---------------------------------------------------------------------------
@Override
public String toString()
{
return getRef().toString();
}
//---------------------------------------------------------------------------
public WellRef getRef()
{
return mLocation;
}
//---------------------------------------------------------------------------
public int getRow()
{
return mLocation.getRowIndex();
}
//---------------------------------------------------------------------------
public int getCol()
{
return mLocation.getColIndex();
}
//---------------------------------------------------------------------------
public LayerWell setType(WellType inValue)
{
mType = inValue;
return this;
}
//---------------------------------------------------------------------------
public WellType getType()
{
return mType;
}
//---------------------------------------------------------------------------
public LayerWell setPlate(LayerPlate inValue)
{
mPlate = inValue;
updatePlateLayers();
return this;
}
//---------------------------------------------------------------------------
public LayerPlate getPlate()
{
return mPlate;
}
//---------------------------------------------------------------------------
public LayerWell setSelected()
{
return setSelected(true);
}
//---------------------------------------------------------------------------
public LayerWell setSelected(boolean inValue)
{
WellSelectionLayer selectionLayer = getSelectionLayer();
if (null == selectionLayer)
{
selectionLayer = new WellSelectionLayer(inValue);
addLayer(selectionLayer);
}
else
{
selectionLayer.setSelected(inValue);
updatePlateLayers(selectionLayer);
}
return this;
}
//---------------------------------------------------------------------------
public boolean isSelected()
{
WellSelectionLayer selectionLayer = getSelectionLayer();
return (selectionLayer != null
&& selectionLayer.isSelected());
}
//---------------------------------------------------------------------------
public LayerWell addSample(S inValue)
{
return addSample(inValue, null);
}
//---------------------------------------------------------------------------
/**
Adds a sample to the well.
* @param inValue an object designated as the sample. Cannot be null.
* @param inVolume an optional volume to associate with the sample
* @param the sample class
* @return this Well object to allow for method chaining
*/
public LayerWell addSample(S inValue, Quantity inVolume)
{
if (inValue != null)
{
WellSampleLayer sampleLayer = getSampleLayer((Class) inValue.getClass());
if (null == sampleLayer)
{
sampleLayer = new WellSampleLayer<>((Class) inValue.getClass());
addLayer(sampleLayer);
}
sampleLayer.addSample(inValue, inVolume);
updatePlateLayers(sampleLayer);
}
return this;
}
//---------------------------------------------------------------------------
public S[] getSamples(Class inClass)
{
List samples = null;
List sampleLayers = getSampleLayers();
if(CollectionUtil.hasValues(sampleLayers))
{
for (WellSampleLayer layer : getSampleLayers())
{
if (layer.getSampleClass().equals(inClass)
|| inClass.isAssignableFrom(layer.getSampleClass()))
{
if (null == samples)
{
samples = new ArrayList<>(4);
}
for (Object sample : layer.getSamples())
{
samples.add((S) sample);
}
}
}
}
return samples != null ? samples.toArray((S[]) Array.newInstance(inClass, 0)) : null;
}
//---------------------------------------------------------------------------
public Quantity getSampleVolume()
{
Quantity sampleVolume = null;
List sampleLayers = getSampleLayers();
if (CollectionUtil.hasValues(sampleLayers))
{
for (WellSampleLayer layer : getSampleLayers())
{
if (layer.getVolume() != null)
{
if (null == sampleVolume)
{
sampleVolume = layer.getVolume();
}
else
{
sampleVolume = sampleVolume.add(layer.getVolume());
}
}
}
}
return sampleVolume;
}
//---------------------------------------------------------------------------
public Comparable[] getSamples()
{
Set