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

com.github.jessemull.microflexbiginteger.io.PlateWriter Maven / Gradle / Ivy

The newest version!
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

/*--------------------------- Package Declaration ----------------------------*/

package com.github.jessemull.microflexbiginteger.io;

/*------------------------------- Dependencies -------------------------------*/

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.math.BigInteger;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.github.jessemull.microflexbiginteger.plate.Plate;
import com.github.jessemull.microflexbiginteger.plate.Stack;
import com.github.jessemull.microflexbiginteger.plate.Well;
import com.github.jessemull.microflexbiginteger.plate.WellSet;

/**
 * Formats and writes stacks, plates, well sets and wells to an output stream or 
 * string. Supports the following formats:
 * 
 * 
 *    
 *    
 *       
 *    
 *    
 *       
 *    
 *    
 *       
 *    
 *    
 *       
 *    
 * 
Formats
Plate Map
Result Table
JSON
XML
* * Result tables and maps are separated using a user defined delimiter or the * default tab delimiter. * *

* *
*
*

Example Result Plate Map:

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Result
123456
A911426674214515412937882
B895348275149979225146448
C632848965130965551201485
D266152904057237412002724
*
*
*

Example Result Table:

* * * * * * * * * * * * * * * * * * * * * * * * * *
Result
IndexValue
A14877
A25032
A36723
B14981
*
*
*

Example Result JSON:

*
 *  {
 *   "results" : [ {
 *     "type" : "BigInteger",
 *     "label" : "Example Result",
 *     "size" : 10,
 *     "wells" : {
 *       "A11" : 5645,
 *       "A2" : 6149,
 *       "A5" : 5846,
 *       "D10" : 5895,
 *       "D2" : 5452,
 *       "E4" : 5682,
 *       "E8" : 6116,
 *       "E9" : 4945,
 *       "G6" : 5874,
 *       "H1" : 4911
 *     }
 *   } ]
 *  }
 *       
*
*
*

Example Result XML:

*
 *  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 *  <results>
 *     <result>
 *         <type>BigInteger</type>
 *         <label>Example Result</label>
 *         <size>3</size>
 *         <wells>
 *             <well>
 *                 <index>A2</index>
 *                 <value>5587</value>
 *             </well>
 *             <well>
 *                 <index>A3</index>
 *                 <value>5389</value>
 *             </well>
 *             <well>
 *                 <index>A4</index>
 *                 <value>4937</value>
 *             </well>
 *         </wells>
 *     </result>
 *  </results>
 *       
*
*
*
*
*

Example Well JSON:

*
 *  {
 *    "wells" : [ {
 *      "type" : "BigInteger",
 *      "index" : "F8",
 *      "size" : 24,
 *      "values" : [ 1511, 2882, 5254 ]
 *    } ]
 *  }
 *        
*
*
*

Example Well Set JSON:

*
 *  {
 *    "wellsets" : [ {
 *      "type" : "BigInteger",
 *      "label" : "Example Well Set",
 *      "size" : 1,
 *      "wells" : [ {
 *        "index" : "A3",
 *        "values" : [ 4470, 9116, 5215 ]
 *      } ]
 *    } ]
 *  }
 *        
*
*
*

Example Plate JSON:

*
 *  {
 *    "plates" : [ {
 *      "type" : "BigInteger",
 *      "label" : "Example Plate",
 *      "descriptor" : "96-Well",
 *      "rows" : 8,
 *      "columns" : 12,
 *      "size" : 1,
 *      "wellsets" : [ {
 *        "label" : "Example Well Set",
 *        "size" : 3,
 *        "wells" : [ "C5", "D4", "F7" ]
 *      } ],
 *      "wells" : [ {
 *        "index" : "A7",
 *        "values" : [ 4451, 3453, 5592 ]
 *      } ]
 *    } ]
 *  }
 *        
*
*
*

Example Stack JSON:

*
 *  {
 *    "stacks" : [ {
 *      "type" : "BigInteger",
 *      "label" : "Example Stack",
 *      "rows" : 8,
 *      "columns" : 12,
 *      "size" : 1,
 *      "plates" : [ {
 *        "type" : "BigInteger",
 *        "label" : "Example Plate",
 *        "descriptor" : "96-Well",
 *        "rows" : 8,
 *        "columns" : 12,
 *        "size" : 1,
 *        "wellsets" : [ {
 *          "label" : "Example Well Set",
 *          "size" : 3,
 *          "wells" : [ "B6", "G1", "G12" ]
 *        } ],
 *        "wells" : [ {
 *          "index" : "A2",
 *          "values" : [ 3594, 2817, 2100 ]
 *        } ]
 *      } ]
 *    } ]
 *  }
 *        
*
*
*
*
*

Example Well XML:

*
 *  <wells>
 *     <well>
 *         <type>BigInteger</type>
 *         <index>H8</index>
 *         <size>24</size>
 *         <values>
 *             <value>7870</value>
 *             <value>7296</value>
 *             <value>3898</value>
 *         </values>
 *     </well>
 *  </wells>
 *       
*
*
*

Example Well Set XML:

*
 *  <wellsets>
 *     <wellset>
 *         <type>BigInteger</type>
 *         <label>Example Well Set</label>
 *         <size>1</size>
 *         <wells>
 *             <well>
 *                 <index>A11</index>
 *                 <values>
 *                     <value>1739</value>
 *                     <value>5465</value>
 *                     <value>5412</value>
 *                 </values>
 *             </well>
 *         </wells>
 *     </wellset>
 *  </wellsets>
 *       
*
*
*

Example Plate XML:

*
 *  <plates>
 *     <plate>
 *         <type>BigInteger</type>
 *         <label>Example Plate</label>
 *         <descriptor>96-Well</descriptor>
 *         <rows>8</rows>
 *         <columns>12</columns>
 *         <size>1</size>
 *         <wellsets>
 *             <wellset>
 *                 <label>Example Well Set</label>
 *                 <size>3</size>
 *                 <wells>
 *                     <well>B12</well>
 *                     <well>E2</well>
 *                     <well>H8</well>
 *                 </wells>
 *             </wellset>
 *         </wellsets>
 *         <wells>
 *             <well>
 *                 <index>A5</index>
 *                 <values>
 *                     <value>1389</value>
 *                     <value>9246</value>
 *                     <value>1948</value>
 *                 </values>
 *             </well>
 *         </wells>
 *     </plate>
 *  </plates>
 *       
*
*
*

Example Stack XML:

*
 *  <stacks>
 *     <stack>
 *         <type>BigInteger</type>
 *         <label>Example Stack</label>
 *         <rows>8</rows>
 *         <columns>12</columns>
 *         <size>1</size>
 *         <plates>
 *             <plate>
 *                 <type>BigInteger</type>
 *                 <label>Example Plate</label>
 *                 <descriptor>96-Well</descriptor>
 *                 <rows>8</rows>
 *                 <columns>12</columns>
 *                 <size>1</size>
 *                 <wellsets>
 *                     <wellset>
 *                         <label>Example Well Set</label>
 *                         <size>3</size>
 *                         <wells>
 *                             <well>B7</well>
 *                             <well>H2</well>
 *                             <well>H3</well>
 *                         </wells>
 *                     </wellset>
 *                 </wellsets>
 *                 <wells>
 *                     <well>
 *                         <index>A2</index>
 *                         <values>
 *                             <value>1303</value>
 *                             <value>5321</value>
 *                             <value>2808</value>
 *                         </values>
 *                     </well>
 *                 </wells>
 *             </plate>
 *         </plates>
 *     </stack>
 *  </stacks>
 *       
*
*
* * @author Jesse L. Mull * @update Updated Oct 17, 2016 * @address http://www.jessemull.com * @email [email protected] */ public class PlateWriter extends PrintWriter { /*---------------------------- Private Fields ----------------------------*/ /* Number of character types available for the row ID */ private int ALPHA_BASE = 26; /* The delimiter for delimiter separated values */ private String delimiter = "\t"; /*------------------------------ Constructors ----------------------------*/ /** * Creates a new PlateWriterBigInteger without automatic line flushing using * the specified file. * @param File file the output file * @throws FileNotFoundException */ public PlateWriter(File file) throws FileNotFoundException { super(file); } /** * Creates a new PlateWriterBigInteger without automatic line flushing using * the specified file and character set. * @param File file the output file * @param String csn the character set * @throws UnsupportedEncodingException * @throws FileNotFoundException */ public PlateWriter(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException { super(file, csn); } /** * Creates a new PlateWriterBigInteger, without automatic line flushing using * the OutputStream. * @param OutputStream out the output stream */ public PlateWriter(OutputStream out) { super(out); } /** * Creates a new PlateWriterBigInteger with automatic line flushing, using the * OutputStream. * @param OutputStream out the output stream * @param boolean autoFlush sets automatic flush when true */ public PlateWriter(OutputStream out, boolean autoFlush) { super(out, autoFlush); } /** * Creates a new PlateWriterBigInteger without automatic line flushing using the * specified file name. * @param String fileName the file name * @throws FileNotFoundException */ public PlateWriter(String fileName) throws FileNotFoundException { super(fileName); } /** * Creates a new PlateWriterBigInteger without automatic line flushing using the * specified file name and character set. * @param String fileName the file name * @param String csn the character set * @throws UnsupportedEncodingException * @throws FileNotFoundException */ public PlateWriter(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException { super(fileName, csn); } /** * Creates a new PlateWriterBigInteger without automatic line flushing using the * writer. * @param Writer out the writer */ public PlateWriter(Writer out) { super(out); } /** * Creates a new PlateWriterBigInteger with automatic line flushing using the * writer. * @param Writer out the writer * @param boolean autoFlush sets auto flush when true */ public PlateWriter(Writer out, boolean autoFlush) { super(out, autoFlush); } /*--------------------- Methods for Plate Map Output ---------------------*/ /** * Prints the plate map. * @param Map data the data set * @param int type the plate type * @throws UnsupportedEncodingException * @throws FileNotFoundException */ public void resultToPlateMap(Map data, int type) throws FileNotFoundException, UnsupportedEncodingException { int rows = parseRows(type); int columns = parseColumns(type); TreeMap sorted = new TreeMap(data); this.printMapResult(sorted, rows, columns, "Result"); this.flush(); } /** * Returns a string containing the plate map. * @param Map data the data set * @param int type the plate type */ public String resultToPlateMapAsString(Map data, int type) { int rows = parseRows(type); int columns = parseColumns(type); TreeMap sorted = new TreeMap(data); return this.printMapResultAsString(sorted, rows, columns, "Result"); } /** * Prints the plate map for each data set in the list. * @param List> data list of data sets * @param int type the plate type * @throws UnsupportedEncodingException * @throws FileNotFoundException */ public void resultToPlateMap(List> data, int type) throws FileNotFoundException, UnsupportedEncodingException { int rows = parseRows(type); int columns = parseColumns(type); for(Map map : data) { TreeMap sorted = new TreeMap(map); this.printMapResult(sorted, rows, columns, "Result"); this.println(); } this.flush(); } /** * Returns a string holding the plate map for each data set in the list. * @param List> data list of data sets * @param int type the plate type * @return String the plate maps */ public String resultToPlateMapAsString(List> data, int type) { String result = ""; int rows = parseRows(type); int columns = parseColumns(type); for(Map map : data) { TreeMap sorted = new TreeMap(map); result += this.printMapResultAsString(sorted, rows, columns, "Result"); result += "\n"; } return result; } /** * Prints the plate map. * @param Map data the data set * @param int rows number of rows * @param int columns number of columns * @throws UnsupportedEncodingException * @throws FileNotFoundException */ public void resultToPlateMap(Map data, int rows, int columns) throws FileNotFoundException, UnsupportedEncodingException { TreeMap sorted = new TreeMap(data); this.printMapResult(sorted, rows, columns, "Result"); this.flush(); } /** * Returns a string holding the plate map. * @param Map data the data set * @param int rows number of rows * @param int columns number of columns * @return String the plate map */ public String resultToPlateMapAsString(Map data, int rows, int columns) { TreeMap sorted = new TreeMap(data); return this.printMapResultAsString(sorted, rows, columns, "Result"); } /** * Prints the plate map for each data set in the list. * @param List> data list of data sets * @param int rows number of rows * @param int columns number of columns * @throws UnsupportedEncodingException * @throws FileNotFoundException */ public void resultToPlateMap(List> data, int rows, int columns) throws FileNotFoundException, UnsupportedEncodingException { for(Map map : data) { TreeMap sorted = new TreeMap(map); this.printMapResult(sorted, rows, columns, "Result"); this.println(); } this.flush(); } /** * Returns a string holding the plate map for each data set in the list. * @param List> data list of data sets * @param int rows number of rows * @param int columns number of columns * @return String the plate maps */ public String resultToPlateMapAsString(List> data, int rows, int columns) { String result = ""; for(Map map : data) { TreeMap sorted = new TreeMap(map); result += this.printMapResultAsString(sorted, rows, columns, "Result"); result += "\n"; } return result; } /** * Prints the plate map. * @param Map data the data set * @param int type the plate type * @param String label the data set label * @throws UnsupportedEncodingException * @throws FileNotFoundException */ public void resultToPlateMap(Map data, int type, String label) throws FileNotFoundException, UnsupportedEncodingException { int rows = parseRows(type); int columns = parseColumns(type); TreeMap sorted = new TreeMap(data); this.printMapResult(sorted, rows, columns, label); this.flush(); } /** * Returns a string holding the plate map. * @param Map data the data set * @param int type the plate type * @param String label the data set label * @return String the plate map */ public String resultToPlateMapAsString(Map data, int type, String label) { int rows = parseRows(type); int columns = parseColumns(type); TreeMap sorted = new TreeMap(data); return this.printMapResultAsString(sorted, rows, columns, label); } /** * Prints the plate map for each data set in the list. * @param List> data list of data sets * @param int type the plate type * @param List label list of data set labels * @throws UnsupportedEncodingException * @throws FileNotFoundException */ public void resultToPlateMap(List> data, int type, List labels) throws FileNotFoundException, UnsupportedEncodingException { int rows = parseRows(type); int columns = parseColumns(type); for(int i = 0; i < data.size(); i++) { TreeMap sorted = new TreeMap(data.get(i)); String label = i > labels.size() ? "Result" : labels.get(i); this.printMapResult(sorted, rows, columns, label); this.println(); } this.flush(); } /** * Returns a string containing the plate map for each data set in the list. * @param List> data list of data sets * @param int type the plate type * @param List label list of data set labels * @return String the plate maps */ public String resultToPlateMapAsString(List> data, int type, List labels) { String result = ""; int rows = parseRows(type); int columns = parseColumns(type); for(int i = 0; i < data.size(); i++) { TreeMap sorted = new TreeMap(data.get(i)); String label = i > labels.size() ? "Result" : labels.get(i); result += this.printMapResultAsString(sorted, rows, columns, label); result += "\n"; } return result; } /** * Prints the plate map. * @param Map data the data set * @param int rows number of rows * @param int columns number of columns * @param String label the data set label * @throws UnsupportedEncodingException * @throws FileNotFoundException */ public void resultToPlateMap(Map data, int rows, int columns, String label) throws FileNotFoundException, UnsupportedEncodingException { TreeMap sorted = new TreeMap(data); this.printMapResult(sorted, rows, columns, label); this.flush(); } /** * Returns a string containing the plate map. * @param Map data the data set * @param int rows number of rows * @param int columns number of columns * @param String label the data set label * @return String the plate map */ public String resultToPlateMapAsString(Map data, int rows, int columns, String label) { TreeMap sorted = new TreeMap(data); return this.printMapResultAsString(sorted, rows, columns, label); } /** * Prints the plate map for each data set in the list. * @param List> data list of data sets * @param int rows number of rows * @param int columns number of columns * @param List label list of data set labels * @throws UnsupportedEncodingException * @throws FileNotFoundException */ public void resultToPlateMap(List> data, int rows, int columns, List labels) throws FileNotFoundException, UnsupportedEncodingException { for(int i = 0; i < data.size(); i++) { TreeMap sorted = new TreeMap(data.get(i)); String label = i > labels.size() ? "Result" : labels.get(i); this.printMapResult(sorted, rows, columns, label); this.println(); } this.flush(); } /** * Returns a string containing the plate map for each data set in the list. * @param List> data list of data sets * @param int rows number of rows * @param int columns number of columns * @param List label list of data set labels * @return String the plate maps */ public String resultToPlateMapAsString(List> data, int rows, int columns, List labels) { String result = ""; for(int i = 0; i < data.size(); i++) { TreeMap sorted = new TreeMap(data.get(i)); String label = i > labels.size() ? "Result" : labels.get(i); result += this.printMapResultAsString(sorted, rows, columns, label); result += "\n"; } return result; } /** * Prints the plate map. * @param Map data the data set * @param int rows number of rows * @param int columns number of columns * @param String label the data set label * @throws FileNotFoundException * @throws UnsupportedEncodingException */ public void printMapResult(Map data, int rows, int columns, String label) throws FileNotFoundException, UnsupportedEncodingException { this.println(label); this.print(delimiter); for(int k = 0; k < columns; k++) { this.print((k + 1) + delimiter); } this.println(); for(int i = 0; i < rows; i++) { this.print(this.rowString(i) + delimiter); for(int j = 1; j < columns + 1; j++) { Well well = new Well(i, j); if(data.containsKey(well)) { this.print(data.get(well) + delimiter); } else { this.print("Null" + delimiter); } } this.println(); } this.println(); } /** * Returns a string containing the plate map. * @param Map data the data set * @param int rows number of rows * @param int columns number of columns * @param String label the data set label * @return String the plate map */ public String printMapResultAsString(Map data, int rows, int columns, String label) { String result = label + "\n"; result += this.delimiter; for(int k = 0; k < columns; k++) { result += (k + 1) + delimiter; } result += "\n"; for(int i = 0; i < rows; i++) { result += this.rowString(i) + delimiter; for(int j = 1; j < columns + 1; j++) { Well well = new Well(i, j); if(data.containsKey(well)) { result += data.get(well) + delimiter; } else { result += "Null" + delimiter; } } result += "\n";; } return result; } /*----------------------- Methods for Table Output -----------------------*/ /** * Prints the well value pairs as a delimiter separated table. * @param Map data the data set * @throws UnsupportedEncodingException * @throws FileNotFoundException */ public void resultToTable(Map data) throws FileNotFoundException, UnsupportedEncodingException { TreeMap sorted = new TreeMap(data); this.printTableResult(sorted, "Result"); this.flush(); } /** * Returns a string containing the well value pairs as a delimiter separated * table. * @param Map data the data set * @return String the table */ public String resultToTableAsString(Map data) { TreeMap sorted = new TreeMap(data); return this.printTableResultAsString(sorted, "Result"); } /** * Prints each set of well value pairs as a delimiter separated table. * @param List> data list of data sets * @throws UnsupportedEncodingException * @throws FileNotFoundException */ public void resultToTable(List> data) throws FileNotFoundException, UnsupportedEncodingException { for(Map map : data) { TreeMap sorted = new TreeMap(map); this.printTableResult(sorted, "Result"); this.print("\n"); } this.flush(); } /** * Returns a string containing each set of well value pairs as a delimiter * separated table. * @param List> data list of data sets * @return String the tables */ public String resultToTableAsString(List> data) { String result = ""; for(Map map : data) { TreeMap sorted = new TreeMap(map); result += this.printTableResultAsString(sorted, "Result"); result += "\n"; } return result; } /** * Prints the well value pairs as a delimiter separated table. * @param Map data the data set * @param String label the data set label * @throws UnsupportedEncodingException * @throws FileNotFoundException */ public void resultToTable(Map data, String label) throws FileNotFoundException, UnsupportedEncodingException { TreeMap sorted = new TreeMap(data); this.printTableResult(sorted, label); this.flush(); } /** * Returns a string containing the well value pairs as a delimiter separated * table. * @param Map data the data set * @param String label the data set label * @return String the table */ public String resultToTableAsString(Map data, String label) { TreeMap sorted = new TreeMap(data); return this.printTableResultAsString(sorted, label); } /** * Prints the well value pairs as a delimiter separated table. * @param List> data list of data sets * @param List label list of data set labels * @throws UnsupportedEncodingException * @throws FileNotFoundException */ public void resultToTable(List> data, List labels) throws FileNotFoundException, UnsupportedEncodingException { for(int i = 0; i < data.size(); i++) { TreeMap sorted = new TreeMap(data.get(i)); String label = i > labels.size() ? "Result" : labels.get(i); this.printTableResult(sorted, label); this.print("\n"); } this.flush(); } /** * Returns a string containing the well value pairs as a delimiter separated * table. * @param List> data list of data sets * @param List label list of data set labels * @return String the tables */ public String resultToTableAsString(List> data, List labels) { String result = ""; for(int i = 0; i < data.size(); i++) { TreeMap sorted = new TreeMap(data.get(i)); String label = i > labels.size() ? "Result" : labels.get(i); result += this.printTableResultAsString(sorted, label); result += "\n"; } return result; } /** * Prints the well value pairs as a delimiter separated table. * @param Map data the data set * @param String label the data set label * @throws UnsupportedEncodingException * @throws FileNotFoundException */ public void printTableResult(Map data, String label) throws FileNotFoundException, UnsupportedEncodingException { this.println(label); this.println("Index" + this.delimiter + "Value"); for (Map.Entry entry : data.entrySet()) { this.println(entry.getKey().index() + this.delimiter + entry.getValue()); } this.println(); } /** * Resturns a string holding the well value pairs as a delimiter separated table. * @param Map data the data set * @param String label the data set label * @return String the table string */ public String printTableResultAsString(Map data, String label) { String result = label + "\n"; result += "Index" + this.delimiter + "Value\n"; for (Map.Entry entry : data.entrySet()) { result += entry.getKey().index() + this.delimiter + entry.getValue(); result += "\n"; } result += "\n"; return result; } /*------------------- Methods for Data Set JSON Output -------------------*/ /** * Prints the well value pairs in a JSON format. * @param Map data the data set * @throws IOException */ public void resultToJSON(Map data) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new ResultListPOJO(data)); } /** * Returns a string containing the well value pairs in a JSON format. * @param Map data the data set * @return String the JSON formatted result * @throws JsonProcessingException */ public String resultToJSONAsString(Map data) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new ResultListPOJO(data)); } /** * Prints the well value pairs in a JSON format for each data set. * @param List> data the list of data sets * @throws IOException */ public void resultToJSON(List> data) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new ResultListPOJO(data)); } /** * Returns a string containing the well value pairs in a JSON format for each data set. * @param List> data the list of data sets * @return String the JSON formatted results * @throws JsonProcessingException */ public String resultToJSONAsString(List> data) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new ResultListPOJO(data)); } /** * Prints the well value pairs in a JSON format using the label. * @param Map data the data set * @param String label the data set label * @throws IOException */ public void resultToJSON(Map data, String label) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new ResultListPOJO(data, label)); } /** * Returns a string containing the well value pairs in a JSON format using the label. * @param Map data the data set * @param String label the data set label * @return String the JSON formatted result */ public String resultToJSONAsString(Map data, String label) throws IOException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new ResultListPOJO(data, label)); } /** * Prints the well value pairs in a JSON format for each data set using the * specified labels. * @param List> data the list of data sets * @param List labels the list of data set labels * @throws IOException */ public void resultToJSON(List> data, List labels) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new ResultListPOJO(data, labels)); } /** * Returns a string containing the well value pairs in a JSON format for each data set using the * specified labels. * @param List> data the list of data sets * @param List labels the list of data set labels * @return String the JSON formatted results * @throws JsonProcessingException */ public String resultToJSONAsString(List> data, List labels) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new ResultListPOJO(data, labels)); } /*--------------------- Methods for Well JSON Output ---------------------*/ /** * Prints the well values in a JSON format. * @param Well the well * @throws IOException */ public void wellToJSON(Well well) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new WellListPOJO(well)); } /** * Returns a string containing the well values in a JSON format. * @param Well the well * @return String the JSON formatted well * @throws JsonProcessingException */ public String wellToJSONAsString(Well well) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new WellListPOJO(well)); } /** * Prints the collection of wells in a JSON format. * @param Collection collection the collection of wells * @throws IOException */ public void wellToJSON(Collection collection) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new WellListPOJO(collection)); } /** * Returns a string containing the collection of wells in a JSON format. * @param Collection collection the collection of wells * @return String the JSON formatted wells * @throws JsonProcessingException */ public String wellToJSONAsString(Collection collection) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new WellListPOJO(collection)); } /** * Prints the wells values in the array in a JSON format. * @param WellBigInteger[] array the array of wells * @throws IOException */ public void wellToJSON(Well[] array) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new WellListPOJO(array)); } /** * Returns a string containing the well values in the array in a JSON format. * @param WellBigInteger[] array the array of wells * @return String the JSON formatted wells * @throws JsonProcessingException */ public String wellToJSONAsString(Well[] array) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new WellListPOJO(array)); } /*------------------- Methods for Well Set JSON Output -------------------*/ /** * Prints the well set values in a JSON format. * @param WellSet set the well set * @throws IOException */ public void setToJSON(WellSet set) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new WellSetListPOJO(set)); } /** * Returns a string containing the well set values in a JSON format. * @param WellSet set the well set * @return String the JSON formatted set * @throws JsonProcessingException */ public String setToJSONAsString(WellSet set) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new WellSetListPOJO(set)); } /** * Prints the collection of well sets in a JSON format. * @param Collection collection the collection of well sets * @throws IOException */ public void setToJSON(Collection collection) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new WellSetListPOJO(collection)); } /** * Returns a string containing the collection of well sets in a JSON format. * @param Collection collection the collection of well sets * @return String the JSON formatted set * @throws JsonProcessingException */ public String setToJSONAsString(Collection collection) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new WellSetListPOJO(collection)); } /** * Prints the well set values in a JSON format. * @param WellSetBigInteger[] array the array of well sets * @throws IOException */ public void setToJSON(WellSet[] array) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new WellSetListPOJO(array)); } /** * Returns a string containing the well set values in a JSON format. * @param WellSetBigInteger[] array the array of well sets * @return String the JSON formatted set * @throws JsonProcessingException */ public String setToJSONAsString(WellSet[] array) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new WellSetListPOJO(array)); } /*-------------------- Methods for Plate JSON Output ---------------------*/ /** * Prints the plate values in a JSON format. * @param Plate plate the plate * @throws IOException */ public void plateToJSON(Plate plate) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new PlateListPOJO(plate)); } /** * Returns a string containing the plate values in a JSON format. * @param Plate plate the plate * @return String the JSON formatted plate * @throws JsonProcessingException */ public String plateToJSONAsString(Plate plate) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new PlateListPOJO(plate)); } /** * Prints the collection of plates in a JSON format. * @param Collection collection the collection of plates * @throws IOException */ public void plateToJSON(Collection collection) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new PlateListPOJO(collection)); } /** * Returns a string containing the collection of plates in a JSON format. * @param Collection collection the collection of plates * @return String the JSON formatted plates * @throws JsonProcessingException */ public String plateToJSONAsString(Collection collection) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new PlateListPOJO(collection)); } /** * Prints the array of plates in a JSON format. * @param PlateBigInteger[] array the array of plates * @throws IOException */ public void plateToJSON(Plate[] array) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new PlateListPOJO(array)); } /** * Returns a string containing the array of plates in a JSON format. * @param PlateBigInteger[] array the array of plates * @throws JsonProcessingException */ public String plateToJSONAsString(Plate[] array) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new PlateListPOJO(array)); } /*-------------------- Methods for Stack JSON Output ---------------------*/ /** * Prints the plate stack in a JSON format. * @param Stack stack the plate stack * @throws IOException */ public void stackToJSON(Stack stack) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new StackListPOJO(stack)); } /** * Returns a string containing the plate stack in a JSON format. * @param Stack stack the plate stack * @return String the JSON formatted stack * @throws JsonProcessingException */ public String stackToJSONAsString(Stack stack) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new StackListPOJO(stack)); } /** * Prints the collection of plate stacks in a JSON format. * @param Collection collection the collection of plate stacks * @throws IOException */ public void stackToJSON(Collection collection) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new StackListPOJO(collection)); } /** * Returns a string containing the collection of plate stacks in a JSON format. * @param Collection collection the collection of plate stacks * @return String the JSON formatted stacks * @throws JsonProcessingException */ public String stackToJSONAsString(Collection collection) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new StackListPOJO(collection)); } /** * Prints the array of plate stacks in a JSON format. * @param StackBigInteger[] array the array of plate stacks * @throws IOException */ public void stackToJSON(Stack[] array) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.writerWithDefaultPrettyPrinter().writeValue(this, new StackListPOJO(array)); } /** * Prints the array of plate stacks in a JSON format. * @param StackBigInteger[] array the array of plate stacks * @return String the JSON formatted stacks * @throws JsonProcessingException */ public String stackToJSONAsString(Stack[] array) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new StackListPOJO(array)); } /*-------------------- Methods for Result XML Output --------------------*/ /** * Prints the well result values in an XML format. * @param Map map the result map * @throws IOException * @throws ParserConfigurationException * @throws TransformerException */ public void resultToXML(Map map) throws IOException, ParserConfigurationException, TransformerException { ResultListXML resultList = new ResultListXML(map); this.printXMLResult(resultList); } /** * Returns a string containing the result values in an XML format. * @param Map map the result map * @return String the XML formatted result */ public String resultToXMLAsString(Map map) { ResultListXML resultList = new ResultListXML(map); return this.printXMLResultAsString(resultList); } /** * Prints the well result values in an XML format. * @param Map map the result map * @param String label the label * @throws IOException * @throws ParserConfigurationException * @throws TransformerException */ public void resultToXML(Map map, String label) throws IOException, ParserConfigurationException, TransformerException { ResultListXML resultList = new ResultListXML(map, label); this.printXMLResult(resultList); } /** * Returns a string containing the result values in an XML format. * @param Map map the result map * @param String label the label * @return String the XML formatted result values */ public String resultToXMLAsString(Map map, String label) { ResultListXML resultList = new ResultListXML(map, label); return this.printXMLResultAsString(resultList); } /** * Prints the collection of result values in an XML format. * @param Collection collection the collection of well sets * @throws IOException * @throws TransformerException * @throws ParserConfigurationException */ public void resultToXML(Collection> collection) throws IOException, TransformerException, ParserConfigurationException { ResultListXML resultList = new ResultListXML(collection); this.printXMLResult(resultList); } /** * Returns a string containing the collection of result values in an XML format. * @param Collection collection the collection of well sets * @return String the XML formatted result values */ public String resultToXMLAsString(Collection> collection) { ResultListXML resultList = new ResultListXML(collection); return this.printXMLResultAsString(resultList); } /** * Prints the collection of result values in an XML format. * @param Collection collection the collection of well sets * @param List labels result labels * @throws IOException * @throws TransformerException * @throws ParserConfigurationException */ public void resultToXML(Collection> collection, List labels) throws IOException, TransformerException, ParserConfigurationException { ResultListXML resultList = new ResultListXML(collection, labels); this.printXMLResult(resultList); } /** * Returns a string containing the collection of result values in an XML format. * @param Collection collection the collection of well sets * @param List labels result labels * @return String the XML formatted result values */ public String resultToXMLAsString(Collection> collection, List labels) { ResultListXML resultList = new ResultListXML(collection, labels); return this.printXMLResultAsString(resultList); } /** * Prints the well set as an XML object. * @param ResultListXML resultList the XML result list * @throws IOException */ private void printXMLResult(ResultListXML resultList) throws IOException { try { JAXBContext context = JAXBContext.newInstance(ResultListXML.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(resultList, this); } catch (JAXBException e) { e.printStackTrace(); } } /** * Returns a string containing the result as an XML object. * @param ResultListXML resultList the XML result list * @return String the XML formatted result list */ private String printXMLResultAsString(ResultListXML resultList) { try { StringWriter writer = new StringWriter(); JAXBContext context = JAXBContext.newInstance(ResultListXML.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(resultList, writer); return writer.toString(); } catch (JAXBException e) { e.printStackTrace(); return null; } } /*--------------------- Methods for Well XML Output ----------------------*/ /** * Prints the well values in an XML format. * @param Well set the set * @throws IOException * @throws ParserConfigurationException * @throws TransformerException */ public void wellToXML(Well well) throws IOException, ParserConfigurationException, TransformerException { WellListXML wellList = new WellListXML(well); this.printXMLWell(wellList); } /** * Returns a string containing the well values in an XML format. * @param Well set the set * @return String the XML formatted well values */ public String wellToXMLAsString(Well well) { WellListXML wellList = new WellListXML(well); return this.printXMLWellAsString(wellList); } /** * Prints the collection of well values in an XML format. * @param Collection collection the collection of wells * @throws IOException * @throws TransformerException * @throws ParserConfigurationException */ public void wellToXML(Collection collection) throws IOException, TransformerException, ParserConfigurationException { WellListXML wellList = new WellListXML(collection); this.printXMLWell(wellList); } /** * Returns a string containing the collection of well values in an XML format. * @param Collection collection the collection of wells * @return String the XML formatted wells */ public String wellToXMLAsString(Collection collection) throws IOException, TransformerException, ParserConfigurationException { WellListXML wellList = new WellListXML(collection); return this.printXMLWellAsString(wellList); } /** * Prints the well values in the array in an XML format. * @param WellBigInteger[] array the array of wells * @throws IOException * @throws ParserConfigurationException * @throws TransformerException */ public void wellToXML(Well[] array) throws IOException, ParserConfigurationException, TransformerException { WellListXML wellList = new WellListXML(array); this.printXMLWell(wellList); } /** * Prints the well values in the array in an XML format. * @param WellBigInteger[] array the array of wells * @return String the XML formatted wells */ public String wellToXMLAsString(Well[] array) throws IOException, ParserConfigurationException, TransformerException { WellListXML wellList = new WellListXML(array); return this.printXMLWellAsString(wellList); } /** * Prints the well list as an XML object. * @param WellListXML wellList the well list * @throws IOException */ private void printXMLWell(WellListXML wellList) throws IOException { try { JAXBContext context = JAXBContext.newInstance(WellListXML.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(wellList, this); } catch (JAXBException e) { e.printStackTrace(); } } /** * Returns a string containing the well list as an XML object. * @param WellListXML wellList the well list * @return String the XML formatted well list */ private String printXMLWellAsString(WellListXML wellList) { try { StringWriter writer = new StringWriter(); JAXBContext context = JAXBContext.newInstance(WellListXML.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(wellList, writer); return writer.toString(); } catch (JAXBException e) { e.printStackTrace(); return null; } } /*-------------------- Methods for Well Set XML Output --------------------*/ /** * Prints the well set values in an XML format. * @param WellSet set the well set * @throws IOException * @throws ParserConfigurationException * @throws TransformerException */ public void setToXML(WellSet set) throws IOException, ParserConfigurationException, TransformerException { WellSetListXML setList = new WellSetListXML(set); this.printXMLSet(setList); } /** * Returns a string containing the well set values in an XML format. * @param WellSet set the well set * @return String the XML formatted well sets */ public String setToXMLAsString(WellSet set) { WellSetListXML setList = new WellSetListXML(set); return this.printXMLSetAsString(setList); } /** * Prints the collection of well sets in an XML format. * @param Collection collection the collection of well sets * @throws IOException * @throws TransformerException * @throws ParserConfigurationException */ public void setToXML(Collection collection) throws IOException, TransformerException, ParserConfigurationException { WellSetListXML setList = new WellSetListXML(collection); this.printXMLSet(setList); } /** * Returns a string containing the collection of well sets in an XML format. * @param Collection collection the collection of well sets * @return String the XML formatted well sets */ public String setToXMLAsString(Collection collection) { WellSetListXML setList = new WellSetListXML(collection); return this.printXMLSetAsString(setList); } /** * Prints the well set values in an XML format. * @param WellSetBigInteger[] array the array of well sets * @throws IOException * @throws ParserConfigurationException * @throws TransformerException */ public void setToXML(WellSet[] array) throws IOException, ParserConfigurationException, TransformerException { WellSetListXML setList = new WellSetListXML(array); this.printXMLSet(setList); } /** * Returns a string containing the well set values in an XML format. * @param WellSetBigInteger[] array the array of well sets * @return String the XML formatted well sets */ public String setToXMLAsString(WellSet[] array) { WellSetListXML setList = new WellSetListXML(array); return this.printXMLSetAsString(setList); } /** * Prints the well set as an XML object. * @param WellSetListXML setList the well set list * @throws IOException */ private void printXMLSet(WellSetListXML setList) throws IOException { try { JAXBContext context = JAXBContext.newInstance(WellSetListXML.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(setList, this); } catch (JAXBException e) { e.printStackTrace(); } } /** * Returns a string containing the well set as an XML object. * @param WellSetListXML setList the well set list * @return String the XML formatted set list */ private String printXMLSetAsString(WellSetListXML setList) { try { StringWriter writer = new StringWriter(); JAXBContext context = JAXBContext.newInstance(WellSetListXML.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(setList, writer); return writer.toString(); } catch (JAXBException e) { e.printStackTrace(); return null; } } /*-------------------- Methods for Plate XML Output ---------------------*/ /** * Prints the plate values in an XML format. * @param Plate plate the plate * @throws IOException * @throws TransformerException * @throws ParserConfigurationException */ public void plateToXML(Plate plate) throws IOException, TransformerException, ParserConfigurationException { PlateListXML plateList = new PlateListXML(plate); this.printXMLPlate(plateList); } /** * Returns a string containing the plate values in an XML format. * @param Plate plate the plate * @return String the XML formatted plates */ public String plateToXMLAsString(Plate plate) { PlateListXML plateList = new PlateListXML(plate); return this.printXMLPlateAsString(plateList); } /** * Prints the collection of plates in an XML format. * @param Collection collection the collection of plates * @throws IOException * @throws TransformerException * @throws ParserConfigurationException */ public void plateToXML(Collection collection) throws IOException, TransformerException, ParserConfigurationException { PlateListXML plateList = new PlateListXML(collection); this.printXMLPlate(plateList); } /** * Returns a string containing the collection of plates in an XML format. * @param Collection collection the collection of plates * @return String the XML formatted plates */ public String plateToXMLAsString(Collection collection) { PlateListXML plateList = new PlateListXML(collection); return this.printXMLPlateAsString(plateList); } /** * Prints the array of plates in an XML format. * @param PlateBigInteger[] array the array of plates * @throws IOException * @throws ParserConfigurationException * @throws TransformerException */ public void plateToXML(Plate[] array) throws IOException, ParserConfigurationException, TransformerException { PlateListXML plateList = new PlateListXML(array); this.printXMLPlate(plateList); } /** * Returns a string containing the array of plates in an XML format. * @param PlateBigInteger[] array the array of plates * @return String the XML formatted plates */ public String plateToXMLAsString(Plate[] array) { PlateListXML plateList = new PlateListXML(array); return this.printXMLPlateAsString(plateList); } /** * Prints the plate as an XML object. * @param PlateListXML plateList the plate list * @throws IOException */ private void printXMLPlate(PlateListXML plateList) throws IOException { try { JAXBContext context = JAXBContext.newInstance(PlateListXML.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(plateList, this); } catch (JAXBException e) { e.printStackTrace(); } } /** * Prints the plate as an XML object. * @param PlateListXML plateList the plate list * @return String the XML formatted plate list */ private String printXMLPlateAsString(PlateListXML plateList) { try { StringWriter writer = new StringWriter(); JAXBContext context = JAXBContext.newInstance(PlateListXML.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(plateList, writer); return writer.toString(); } catch (JAXBException e) { e.printStackTrace(); return null; } } /*-------------------- Methods for Stack XML Output ---------------------*/ /** * Prints the plate stack in an XML format. * @param Stack stack the plate stack * @throws IOException * @throws TransformerException * @throws ParserConfigurationException */ public void stackToXML(Stack stack) throws IOException, TransformerException, ParserConfigurationException { StackListXML stackList = new StackListXML(stack); this.printXMLStack(stackList); } /** * Returns a string containing the plate stack in an XML format. * @param Stack stack the plate stack * @return String the XML formatted stacks */ public String stackToXMLAsString(Stack stack) { StackListXML stackList = new StackListXML(stack); return this.printXMLStackAsString(stackList); } /** * Prints the collection of plate stacks in an XML format. * @param Collection collection the collection of plate stacks * @throws IOException * @throws ParserConfigurationException * @throws TransformerException */ public void stackToXML(Collection collection) throws IOException, ParserConfigurationException, TransformerException { StackListXML stackList = new StackListXML(collection); this.printXMLStack(stackList); } /** * Returns a string containing the collection of plate stacks in an XML format. * @param Collection collection the collection of plate stacks * @return String the XML formatted stacks */ public String stackToXMLAsString(Collection collection) { StackListXML stackList = new StackListXML(collection); return this.printXMLStackAsString(stackList); } /** * Prints the array of plate stacks in an XML format. * @param StackBigInteger[] array the array of plate stacks * @throws IOException * @throws ParserConfigurationException * @throws TransformerException */ public void stackToXML(Stack[] array) throws IOException, ParserConfigurationException, TransformerException { StackListXML stackList = new StackListXML(array); this.printXMLStack(stackList); } /** * Returns a string containing the array of plate stacks in an XML format. * @param StackBigInteger[] array the array of plate stacks * @return String the XML formatted stacks */ public String stackToXMLAsString(Stack[] array) { StackListXML stackList = new StackListXML(array); return this.printXMLStackAsString(stackList); } /** * Prints the stack as an XML object. * @param StackListXML stackList the stack list * @throws IOException * @throws TransformerException */ public void printXMLStack(StackListXML stackList) throws IOException, TransformerException { try { JAXBContext context = JAXBContext.newInstance(StackListXML.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(stackList, this); } catch (JAXBException e) { e.printStackTrace(); } } /** * Returns a string containing the stack list as an XML object. * @param StackListXML stackList the stack list * @return String the XML formatted stack list */ public String printXMLStackAsString(StackListXML stackList) { try { StringWriter writer = new StringWriter(); JAXBContext context = JAXBContext.newInstance(StackListXML.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(stackList, writer); return writer.toString(); } catch (JAXBException e) { e.printStackTrace(); return null; } } /*-------------------- Methods for Setting Delimiter ---------------------*/ /** * Sets the delimiter for the plate writer. * @param String delimiter the delimiter */ public void setDelimiter(String delimiter) { this.delimiter = delimiter; } /** * Returns the delimiter. * @return String the delimiter */ public String getDelimiter() { return this.delimiter; } /*----------------------- Helper Methods for Output ----------------------*/ /** * Returns the row ID. * @return String row ID */ private String rowString(int row) { String rowString = ""; while (row >= 0) { rowString = (char) (row % ALPHA_BASE + 65) + rowString; row = (row / ALPHA_BASE) - 1; } return rowString; } /** * Returns the row number for the plate type. * @param int type the plate type * @return int the number of plate rows */ private int parseRows(int type) { switch(type) { case Plate.PLATE_6WELL: return Plate.ROWS_6WELL; case Plate.PLATE_12WELL: return Plate.ROWS_12WELL; case Plate.PLATE_24WELL: return Plate.ROWS_24WELL; case Plate.PLATE_48WELL: return Plate.ROWS_48WELL; case Plate.PLATE_96WELL: return Plate.ROWS_96WELL; case Plate.PLATE_384WELL: return Plate.ROWS_384WELL; case Plate.PLATE_1536WELL: return Plate.ROWS_1536WELL; default: throw new IllegalArgumentException("Invalid plate type."); } } /** * Returns the column number for the plate type. * @param int type the plate type * @return int the number of plate columns */ private int parseColumns(int type) { switch(type) { case Plate.PLATE_6WELL: return Plate.COLUMNS_6WELL; case Plate.PLATE_12WELL: return Plate.COLUMNS_12WELL; case Plate.PLATE_24WELL: return Plate.COLUMNS_24WELL; case Plate.PLATE_48WELL: return Plate.COLUMNS_48WELL; case Plate.PLATE_96WELL: return Plate.COLUMNS_96WELL; case Plate.PLATE_384WELL: return Plate.COLUMNS_384WELL; case Plate.PLATE_1536WELL: return Plate.COLUMNS_1536WELL; default: throw new IllegalArgumentException("Invalid plate type."); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy