affyfusion-109/src/affymetrix/calvin/data/DataSetHeader.java

Code
Comments
Other
Rev Date Author Line
11 13 Sep 07 nicklas 1 /////////////////////////////////////////////////////////////////
11 13 Sep 07 nicklas 2 //
11 13 Sep 07 nicklas 3 // Copyright (C) 2005 Affymetrix, Inc.
11 13 Sep 07 nicklas 4 //
11 13 Sep 07 nicklas 5 // This library is free software; you can redistribute it and/or modify
11 13 Sep 07 nicklas 6 // it under the terms of the GNU Lesser General Public License as published
11 13 Sep 07 nicklas 7 // by the Free Software Foundation; either version 2.1 of the License,
11 13 Sep 07 nicklas 8 // or (at your option) any later version.
11 13 Sep 07 nicklas 9 //
11 13 Sep 07 nicklas 10 // This library is distributed in the hope that it will be useful, but
11 13 Sep 07 nicklas 11 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 13 Sep 07 nicklas 12 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11 13 Sep 07 nicklas 13 // for more details.
11 13 Sep 07 nicklas 14 //
11 13 Sep 07 nicklas 15 // You should have received a copy of the GNU Lesser General Public License
11 13 Sep 07 nicklas 16 // along with this library; if not, write to the Free Software Foundation, Inc.,
11 13 Sep 07 nicklas 17 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
11 13 Sep 07 nicklas 18 //
11 13 Sep 07 nicklas 19 /////////////////////////////////////////////////////////////////
11 13 Sep 07 nicklas 20
11 13 Sep 07 nicklas 21
11 13 Sep 07 nicklas 22 package affymetrix.calvin.data;
11 13 Sep 07 nicklas 23
11 13 Sep 07 nicklas 24 import affymetrix.calvin.parameter.*;
11 13 Sep 07 nicklas 25 import java.util.*;
11 13 Sep 07 nicklas 26
11 13 Sep 07 nicklas 27 /** The DataSetHeader information container class. */
11 13 Sep 07 nicklas 28 public class DataSetHeader {
11 13 Sep 07 nicklas 29     
11 13 Sep 07 nicklas 30     /** Constructs a new DataSetHeader class. */
11 13 Sep 07 nicklas 31     public DataSetHeader() {
11 13 Sep 07 nicklas 32         clear();
11 13 Sep 07 nicklas 33     }
11 13 Sep 07 nicklas 34     
11 13 Sep 07 nicklas 35     /** total rows in the dataGroup */
11 13 Sep 07 nicklas 36     private int rowCount;
11 13 Sep 07 nicklas 37     
11 13 Sep 07 nicklas 38     /** data dataGroup name */
11 13 Sep 07 nicklas 39     private String name;
11 13 Sep 07 nicklas 40     
11 13 Sep 07 nicklas 41     /** name/value pairs */
11 13 Sep 07 nicklas 42     private Vector /*ParameterNameValue*/ nameValParams;
11 13 Sep 07 nicklas 43     
11 13 Sep 07 nicklas 44     /** column information */
11 13 Sep 07 nicklas 45     private Vector /*ColumnInfo*/ columnTypes;
11 13 Sep 07 nicklas 46     
11 13 Sep 07 nicklas 47     /** file position of the start of the dataSet header */
11 13 Sep 07 nicklas 48     private int headerStartFilePos;
11 13 Sep 07 nicklas 49     
11 13 Sep 07 nicklas 50     /** file position of the start of the data */
11 13 Sep 07 nicklas 51     private int dataStartFilePos;
11 13 Sep 07 nicklas 52     
11 13 Sep 07 nicklas 53     /** file position of the next dataSet header */
11 13 Sep 07 nicklas 54     private int nextSetFilePos;
11 13 Sep 07 nicklas 55
11 13 Sep 07 nicklas 56     public void clear() {
11 13 Sep 07 nicklas 57         rowCount = 0;
11 13 Sep 07 nicklas 58   name="";
11 13 Sep 07 nicklas 59   nameValParams=null;
11 13 Sep 07 nicklas 60         columnTypes=null;
11 13 Sep 07 nicklas 61   headerStartFilePos = 0;
11 13 Sep 07 nicklas 62   dataStartFilePos = 0;
11 13 Sep 07 nicklas 63   nextSetFilePos = 0;
11 13 Sep 07 nicklas 64     }
11 13 Sep 07 nicklas 65
11 13 Sep 07 nicklas 66     /**  */
11 13 Sep 07 nicklas 67     public int getDataSize() { return getRowSize() * rowCount; }
11 13 Sep 07 nicklas 68
11 13 Sep 07 nicklas 69     /**  */
11 13 Sep 07 nicklas 70     public int getRowSize() {
11 13 Sep 07 nicklas 71         int result = 0;
11 13 Sep 07 nicklas 72   int sz = getColumnCnt();
11 13 Sep 07 nicklas 73   for(int i = 0; i < sz; i++)
11 13 Sep 07 nicklas 74   {
11 13 Sep 07 nicklas 75             result += getColumnInfo(i).getSize();
11 13 Sep 07 nicklas 76   }
11 13 Sep 07 nicklas 77   return result;
11 13 Sep 07 nicklas 78     }
11 13 Sep 07 nicklas 79
11 13 Sep 07 nicklas 80     /**  */
11 13 Sep 07 nicklas 81     public void setName(String p) { name = p; }
11 13 Sep 07 nicklas 82
11 13 Sep 07 nicklas 83     /**  */
11 13 Sep 07 nicklas 84     public String getName() { return name; }
11 13 Sep 07 nicklas 85
11 13 Sep 07 nicklas 86     /**  */
11 13 Sep 07 nicklas 87     public int getNameValParamCnt() {
11 13 Sep 07 nicklas 88         if (nameValParams != null)
11 13 Sep 07 nicklas 89             return nameValParams.size();
11 13 Sep 07 nicklas 90         else
11 13 Sep 07 nicklas 91             return 0;
11 13 Sep 07 nicklas 92     }
11 13 Sep 07 nicklas 93
11 13 Sep 07 nicklas 94     /**  */
11 13 Sep 07 nicklas 95     public void addNameValParam(ParameterNameValue p) {
11 13 Sep 07 nicklas 96         if (nameValParams == null)
11 13 Sep 07 nicklas 97             nameValParams = new Vector();
11 13 Sep 07 nicklas 98         nameValParams.add(p);        
11 13 Sep 07 nicklas 99     }
11 13 Sep 07 nicklas 100
11 13 Sep 07 nicklas 101     /**  */
11 13 Sep 07 nicklas 102     public Vector getNameValParameters() { return nameValParams; }
11 13 Sep 07 nicklas 103
11 13 Sep 07 nicklas 104     /** Finds a ParameterNameValueType by name in the nameValPairs collection
11 13 Sep 07 nicklas 105      *  @param name The name of the NameValPair to find
11 13 Sep 07 nicklas 106      *  @return Reference to a ParameterNameValue if found, null otherwise.
11 13 Sep 07 nicklas 107      */
11 13 Sep 07 nicklas 108     public ParameterNameValue findNameValParam(String name) {
11 13 Sep 07 nicklas 109         
11 13 Sep 07 nicklas 110         if (nameValParams == null)
11 13 Sep 07 nicklas 111             return null;
11 13 Sep 07 nicklas 112         
11 13 Sep 07 nicklas 113         int n = nameValParams.size();
11 13 Sep 07 nicklas 114         for (int i=0; i<n; i++)
11 13 Sep 07 nicklas 115         {
11 13 Sep 07 nicklas 116             ParameterNameValue param = (ParameterNameValue) nameValParams.elementAt(i);
11 13 Sep 07 nicklas 117             if (name.compareTo(param.getName()) == 0)
11 13 Sep 07 nicklas 118                 return param;
11 13 Sep 07 nicklas 119         }
11 13 Sep 07 nicklas 120         return null;
11 13 Sep 07 nicklas 121     }
11 13 Sep 07 nicklas 122
11 13 Sep 07 nicklas 123     /**  */
11 13 Sep 07 nicklas 124     public void addColumn(ColumnInfo colInfo) {
11 13 Sep 07 nicklas 125         if (columnTypes == null)
11 13 Sep 07 nicklas 126             columnTypes = new Vector();
11 13 Sep 07 nicklas 127         columnTypes.add(colInfo);
11 13 Sep 07 nicklas 128     }
11 13 Sep 07 nicklas 129
11 13 Sep 07 nicklas 130     /**  */
11 13 Sep 07 nicklas 131     public void addIntColumn(String name) {
11 13 Sep 07 nicklas 132         if (columnTypes == null)
11 13 Sep 07 nicklas 133             columnTypes = new Vector();
11 13 Sep 07 nicklas 134         columnTypes.add(new IntColumn(name));
11 13 Sep 07 nicklas 135     }
11 13 Sep 07 nicklas 136
11 13 Sep 07 nicklas 137     /**  */
11 13 Sep 07 nicklas 138     public void addUIntColumn(String name) {
11 13 Sep 07 nicklas 139         if (columnTypes == null)
11 13 Sep 07 nicklas 140             columnTypes = new Vector();
11 13 Sep 07 nicklas 141         columnTypes.add(new UIntColumn(name));
11 13 Sep 07 nicklas 142     }
11 13 Sep 07 nicklas 143
11 13 Sep 07 nicklas 144     /**  */
11 13 Sep 07 nicklas 145     public void addShortColumn(String name) {
11 13 Sep 07 nicklas 146        if (columnTypes == null)
11 13 Sep 07 nicklas 147             columnTypes = new Vector();
11 13 Sep 07 nicklas 148        columnTypes.add(new ShortColumn(name));       
11 13 Sep 07 nicklas 149     }
11 13 Sep 07 nicklas 150
11 13 Sep 07 nicklas 151     /**  */
11 13 Sep 07 nicklas 152     public void addUShortColumn(String name) {
11 13 Sep 07 nicklas 153        if (columnTypes == null)
11 13 Sep 07 nicklas 154             columnTypes = new Vector();
11 13 Sep 07 nicklas 155        columnTypes.add(new UShortColumn(name));
11 13 Sep 07 nicklas 156     }
11 13 Sep 07 nicklas 157
11 13 Sep 07 nicklas 158     /**  */
11 13 Sep 07 nicklas 159     public void addByteColumn(String name) {
11 13 Sep 07 nicklas 160        if (columnTypes == null)
11 13 Sep 07 nicklas 161             columnTypes = new Vector();
11 13 Sep 07 nicklas 162         columnTypes.add(new ByteColumn(name));
11 13 Sep 07 nicklas 163     }
11 13 Sep 07 nicklas 164
11 13 Sep 07 nicklas 165     /**  */
11 13 Sep 07 nicklas 166     public void addUByteColumn(String name) {
11 13 Sep 07 nicklas 167        if (columnTypes == null)
11 13 Sep 07 nicklas 168             columnTypes = new Vector();
11 13 Sep 07 nicklas 169         columnTypes.add(new UByteColumn(name));
11 13 Sep 07 nicklas 170     }
11 13 Sep 07 nicklas 171
11 13 Sep 07 nicklas 172     /**  */
11 13 Sep 07 nicklas 173     public void addFloatColumn(String name) {
11 13 Sep 07 nicklas 174        if (columnTypes == null)
11 13 Sep 07 nicklas 175             columnTypes = new Vector();
11 13 Sep 07 nicklas 176         columnTypes.add(new FloatColumn(name));
11 13 Sep 07 nicklas 177     }
11 13 Sep 07 nicklas 178
11 13 Sep 07 nicklas 179     /**
11 13 Sep 07 nicklas 180      * @param len Maximum number of char in string
11 13 Sep 07 nicklas 181      */
11 13 Sep 07 nicklas 182     public void addAsciiColumn(String name, int len) {
11 13 Sep 07 nicklas 183        if (columnTypes == null)
11 13 Sep 07 nicklas 184             columnTypes = new Vector();
11 13 Sep 07 nicklas 185         columnTypes.add(new ASCIIColumn(name, len));
11 13 Sep 07 nicklas 186     }
11 13 Sep 07 nicklas 187
11 13 Sep 07 nicklas 188     /**
11 13 Sep 07 nicklas 189      * @param len Maximum number of wchar_t in string
11 13 Sep 07 nicklas 190      */
11 13 Sep 07 nicklas 191     public void addUnicodeColumn(String name, int len) {
11 13 Sep 07 nicklas 192        if (columnTypes == null)
11 13 Sep 07 nicklas 193             columnTypes = new Vector();
11 13 Sep 07 nicklas 194         columnTypes.add(new UnicodeColumn(name, len));
11 13 Sep 07 nicklas 195     }
11 13 Sep 07 nicklas 196
11 13 Sep 07 nicklas 197     /**  */
11 13 Sep 07 nicklas 198     public ColumnInfo getColumnInfo(int index) {
11 13 Sep 07 nicklas 199         if (columnTypes != null)
11 13 Sep 07 nicklas 200             return (ColumnInfo) columnTypes.elementAt(index);
11 13 Sep 07 nicklas 201         return null;
11 13 Sep 07 nicklas 202     }
11 13 Sep 07 nicklas 203
11 13 Sep 07 nicklas 204     /**  */
11 13 Sep 07 nicklas 205     public int getRowCnt() { return rowCount; }
11 13 Sep 07 nicklas 206
11 13 Sep 07 nicklas 207     /**  */
11 13 Sep 07 nicklas 208     public void setRowCnt(int p) { rowCount = p; }
11 13 Sep 07 nicklas 209
11 13 Sep 07 nicklas 210     /**  */
11 13 Sep 07 nicklas 211     public int getColumnCnt() {
11 13 Sep 07 nicklas 212         if (columnTypes != null)
11 13 Sep 07 nicklas 213             return columnTypes.size();
11 13 Sep 07 nicklas 214         return 0;
11 13 Sep 07 nicklas 215     }
11 13 Sep 07 nicklas 216
11 13 Sep 07 nicklas 217     /** Set the file position of the start of the DataSet header.
11 13 Sep 07 nicklas 218      *  The value set here is not written to the file.
11 13 Sep 07 nicklas 219      */
11 13 Sep 07 nicklas 220     public void setHeaderStartFilePos(int pos) { headerStartFilePos = pos; }
11 13 Sep 07 nicklas 221
11 13 Sep 07 nicklas 222     /** Get the file position of the start of the DataSet header. */
11 13 Sep 07 nicklas 223     public int getHeaderStartFilePos() { return headerStartFilePos; }
11 13 Sep 07 nicklas 224
11 13 Sep 07 nicklas 225     /** Set the file position of the start of the DataSet data.
11 13 Sep 07 nicklas 226     *  The value set here is not written to the file.
11 13 Sep 07 nicklas 227     */
11 13 Sep 07 nicklas 228     public void setDataStartFilePos(int pos) { dataStartFilePos  = pos; }
11 13 Sep 07 nicklas 229
11 13 Sep 07 nicklas 230     /** Get the file position of the start of the DataSet data. */
11 13 Sep 07 nicklas 231     public int getDataStartFilePos() { return dataStartFilePos; }
11 13 Sep 07 nicklas 232
11 13 Sep 07 nicklas 233     /** Set the file position of the next DataSet header. */
11 13 Sep 07 nicklas 234     public void setNextSetFilePos(int pos) { nextSetFilePos = pos; }
11 13 Sep 07 nicklas 235
11 13 Sep 07 nicklas 236     /** Get the file position of the next DataSet header. */
11 13 Sep 07 nicklas 237     public int getNextSetFilePos() { return nextSetFilePos; }
11 13 Sep 07 nicklas 238
11 13 Sep 07 nicklas 239 }
11 13 Sep 07 nicklas 240