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

com.hfg.automation.SimplePlate Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.automation;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.hfg.util.collection.CollectionUtil;
import com.hfg.util.collection.OrderedMap;
import com.hfg.xml.XMLNode;

//------------------------------------------------------------------------------
/**
 Generic sample plate container.
 
@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 SimplePlate extends PlateImpl { private Map mOccupiedWellMap; //########################################################################### // CONSTRUCTORS //########################################################################### //--------------------------------------------------------------------------- public SimplePlate(PlateType inType) { this(inType, null); } //--------------------------------------------------------------------------- public SimplePlate(PlateType inType, String inName) { super(inType, inName); mOccupiedWellMap = new OrderedMap<>(inType.size()); init(); } //-------------------------------------------------------------------------- public SimplePlate(XMLNode inXML) { super(inXML); init(); } //--------------------------------------------------------------------------- protected SimplePlate() { init(); } //-------------------------------------------------------------------------- private void init() { setWellFactory(new SimpleWellFactory()); } //########################################################################### // PUBLIC METHODS //########################################################################### //-------------------------------------------------------------------------- public XMLNode toXMLNode() { XMLNode node = super.toXMLNode(); if (CollectionUtil.hasValues(mOccupiedWellMap)) { for (WellRef wellRef : mOccupiedWellMap.keySet()) { node.addSubtag(mOccupiedWellMap.get(wellRef).toXMLNode()); } } return node; } //-------------------------------------------------------------------------- @Override public SimplePlate clone() { SimplePlate theClone = (SimplePlate) super.clone(); if (CollectionUtil.hasValues(mOccupiedWellMap)) { theClone.mOccupiedWellMap = new OrderedMap<>(mOccupiedWellMap.size()); for (SimpleWell well : mOccupiedWellMap.values()) { theClone.setWell(well.clone()); } } return theClone; } //--------------------------------------------------------------------------- public SimplePlate setName(String inValue) { return (SimplePlate) super.setName(inValue); } //--------------------------------------------------------------------------- public SimplePlate setBarcode(String inValue) { return (SimplePlate) super.setBarcode(inValue); } //--------------------------------------------------------------------------- public SimplePlate setLayout(PlateLayout inValue) { return (SimplePlate) super.setLayout(inValue); } //--------------------------------------------------------------------------- public SimpleWell getWell(String inWellRef) { return getWell(new WellRef(inWellRef)); } //--------------------------------------------------------------------------- public SimpleWell getWell(WellRef inRef) { return mOccupiedWellMap.get(inRef); } //--------------------------------------------------------------------------- public SimpleWell allocateWell(String inWellRef) { return allocateWell(new WellRef(inWellRef)); } //--------------------------------------------------------------------------- public SimpleWell allocateWell(WellRef inWellRef) { SimpleWell well = new SimpleWell(inWellRef); setWell(well); return well; } //--------------------------------------------------------------------------- public SimplePlate setWell(SimpleWell inWell) { inWell.setPlate(this); mOccupiedWellMap.put(inWell.getRef(), inWell); return this; } //--------------------------------------------------------------------------- public SimplePlate setWells(Collection inWells) { mOccupiedWellMap.clear(); if (CollectionUtil.hasValues(inWells)) { for (SimpleWell well : inWells) { setWell(well); } } return this; } //--------------------------------------------------------------------------- public Collection getOccupiedWells() { List wells = null; if (CollectionUtil.hasValues(mOccupiedWellMap)) { wells = new ArrayList<>(mOccupiedWellMap.values()); Collections.sort(wells, getLayout()); } return wells; } //--------------------------------------------------------------------------- /** Flags all occupied wells as selected. */ public void selectAllWells() { Collection occupiedWells = getOccupiedWells(); if (CollectionUtil.hasValues(occupiedWells)) { for (SimpleWell well : occupiedWells) { well.setSelected(); } } } //--------------------------------------------------------------------------- /** Returns wells which have been flagged as selected. @return wells which have been flagged as selected. */ public Collection getSelectedWells() { List selectedWells = new ArrayList<>(); Collection occupiedWells = getOccupiedWells(); if (CollectionUtil.hasValues(occupiedWells)) { for (SimpleWell well : occupiedWells) { if (well.isSelected()) { selectedWells.add(well); } } } Collections.sort(selectedWells, getLayout()); return selectedWells; } //--------------------------------------------------------------------------- public void clearSampleWells() { mOccupiedWellMap.clear(); } //--------------------------------------------------------------------------- public WellRef getNextAvailableSampleWellRef() { WellRef nextWellRef = null; Iterator iterator = getLayout().wellRefIterator(); while (iterator.hasNext()) { WellRef wellRef = iterator.next(); if (! mOccupiedWellMap.containsKey(wellRef)) { nextWellRef = wellRef; break; } } return nextWellRef; } //--------------------------------------------------------------------------- public boolean isFull() { int totalWells = getType().size(); int unoccupiedWells = totalWells - mOccupiedWellMap.size(); // Are there wells that were designated to be kept empty? if (CollectionUtil.hasValues(getLayout().getWellsToKeepEmpty())) { unoccupiedWells -= getLayout().getWellsToKeepEmpty().size(); } return 0 == unoccupiedWells; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy