com.hfg.automation.platelayer.WellSampleLayer 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.HashMap;
import java.util.Map;
import com.hfg.exception.InvalidValueException;
import com.hfg.units.Quantity;
import com.hfg.units.QuantityType;
import com.hfg.util.StringUtil;
import com.hfg.util.collection.CollectionUtil;
import com.hfg.util.collection.OrderedMap;
//------------------------------------------------------------------------------
/**
Plate layer for specifying per-well volumes of samples.
@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 WellSampleLayer extends WellLayerImpl implements SampleLayer, WellVolumeLayer
{
private Class mSampleClass;
private Map mSampleMap;
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//---------------------------------------------------------------------------
public WellSampleLayer(Class inClass)
{
mSampleClass = inClass;
}
//---------------------------------------------------------------------------
public WellSampleLayer(S inValue, Class inClass)
{
this(inClass);
addSample(inValue);
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//---------------------------------------------------------------------------
public WellSampleLayer addSample(S inValue)
{
return addSample(inValue, null);
}
//---------------------------------------------------------------------------
public WellSampleLayer addSample(S inValue, Quantity inVolume)
{
if (null == mSampleMap)
{
mSampleMap = new OrderedMap<>(3);
}
if (inValue != null)
{
Quantity volume = mSampleMap.get(inValue);
if (volume != null)
{
mSampleMap.put(inValue, volume.add(inVolume));
}
else
{
mSampleMap.put(inValue, inVolume);
}
}
else if (! mSampleMap.containsKey(inValue))
{
mSampleMap.put(inValue, null);
}
return this;
}
//---------------------------------------------------------------------------
public S[] getSamples()
{
return mSampleMap != null ? mSampleMap.keySet().toArray((S[]) Array.newInstance(getSampleClass(), 0)) : null;
}
//---------------------------------------------------------------------------
public Class getSampleClass()
{
return mSampleClass;
}
//---------------------------------------------------------------------------
public WellSampleLayer setVolume(S inSample, Quantity inVolume)
{
if (inVolume != null
&& !inVolume.getUnit().getQuantityType().equals(QuantityType.VOLUME))
{
throw new InvalidValueException("The specified volume quantity " + StringUtil.singleQuote(inVolume) + " isn't specified in volume units!");
}
mSampleMap.put(inSample, inVolume);
return this;
}
//---------------------------------------------------------------------------
public WellSampleLayer addVolume(Quantity inVolume)
{
if (inVolume != null
&& !inVolume.getUnit().getQuantityType().equals(QuantityType.VOLUME))
{
throw new InvalidValueException("The specified volume quantity " + StringUtil.singleQuote(inVolume) + " isn't specified in volume units!");
}
if (inVolume != null)
{
if (CollectionUtil.hasValues(mSampleMap))
{
S sample = mSampleMap.keySet().iterator().next();
Quantity volume = mSampleMap.get(sample);
mSampleMap.put(sample, volume != null ? volume.add(inVolume) : inVolume);
}
else
{
mSampleMap = new HashMap<>(2);
mSampleMap.put(null, inVolume);
}
}
return this;
}
//---------------------------------------------------------------------------
public Quantity getVolume()
{
Quantity totalVolume = null;
if (CollectionUtil.hasValues(mSampleMap))
{
for (Quantity volume : mSampleMap.values())
{
if (volume != null)
{
if (null == totalVolume)
{
totalVolume = volume;
}
else
{
totalVolume = totalVolume.add(volume);
}
}
}
}
return totalVolume;
}
//---------------------------------------------------------------------------
public Quantity getVolume(S inSample)
{
return mSampleMap.get(inSample);
}
}