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

com.hfg.automation.platelayer.PlateSelectionLayer Maven / Gradle / Ivy

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


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

import com.hfg.automation.AutomationXML;
import com.hfg.automation.WellRef;
import com.hfg.util.BooleanUtil;
import com.hfg.util.collection.CollectionUtil;
import com.hfg.util.collection.OrderedMap;
import com.hfg.xml.XMLNode;
import com.hfg.xml.XMLTag;

//------------------------------------------------------------------------------
/**
 Plate layer for specifying well selection.
 
@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 PlateSelectionLayer extends PlateLayerImpl implements SelectionLayer { private Map mSelectionMap; //########################################################################### // CONSTRUCTORS //########################################################################### //-------------------------------------------------------------------------- public PlateSelectionLayer() { } //-------------------------------------------------------------------------- public PlateSelectionLayer(XMLNode inXML) { super(inXML); List wellTags = inXML.getSubtagsByName(AutomationXML.WELL); if (CollectionUtil.hasValues(wellTags)) { for (XMLNode wellTag : wellTags) { setSelected(new WellRef(wellTag.getAttributeValue(AutomationXML.REF_ATT)), BooleanUtil.valueOf(wellTag.getAttributeValue(AutomationXML.SELECTED_ATT))); } } } //########################################################################### // PUBLIC METHODS //########################################################################### //--------------------------------------------------------------------------- public XMLNode toXMLNode() { XMLNode node = super.toXMLNode(); if (CollectionUtil.hasValues(mSelectionMap)) { for (WellRef wellRef : mSelectionMap.keySet()) { XMLNode wellTag = new XMLTag(AutomationXML.WELL); wellTag.setAttribute(AutomationXML.REF_ATT, wellRef); wellTag.setAttribute(AutomationXML.SELECTED_ATT, mSelectionMap.get(wellRef)); node.addSubtag(wellTag); } } return node; } //-------------------------------------------------------------------------- @Override public PlateSelectionLayer clone() { PlateSelectionLayer theClone = (PlateSelectionLayer) super.clone(); // TODO: Deep clone the data map if (mSelectionMap != null) { theClone.mSelectionMap = new OrderedMap<>(mSelectionMap); } return theClone; } //--------------------------------------------------------------------------- public PlateSelectionLayer setSelected(WellRef inWellRef, boolean inValue) { if (null == mSelectionMap) { mSelectionMap = new OrderedMap<>(); } mSelectionMap.put(inWellRef, inValue); return this; } //--------------------------------------------------------------------------- public boolean isSelected(WellRef inWellRef) { return mSelectionMap != null ? BooleanUtil.valueOf(mSelectionMap.get(inWellRef)) : false; } //--------------------------------------------------------------------------- public int getNumSelected() { int numSelected = 0; if (CollectionUtil.hasValues(mSelectionMap)) { for (Boolean selected : mSelectionMap.values()) { if (BooleanUtil.valueOf(selected)) { numSelected++; } } } return numSelected; } //--------------------------------------------------------------------------- @Override public Collection getOccupiedWellRefs() { List wellRefs = null; if (CollectionUtil.hasValues(mSelectionMap)) { wellRefs = new ArrayList<>(mSelectionMap.keySet()); // TODO: sort? need access to a PlateLayout } return wellRefs; } //--------------------------------------------------------------------------- @Override public WellLayer getWellLayer(WellRef inWellRef) { WellSelectionLayer wellLayer = new WellSelectionLayer(isSelected(inWellRef)); wellLayer.setName(name()); return wellLayer; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy