affyfusion-109/src/affymetrix/calvin/data/BitFlag.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 java.util.*;
11 13 Sep 07 nicklas 25
11 13 Sep 07 nicklas 26 /**  */
11 13 Sep 07 nicklas 27 public class BitFlag {
11 13 Sep 07 nicklas 28
11 13 Sep 07 nicklas 29     public static final byte DEFAULT_DATA_SET_HDR_FLAG = 0;
11 13 Sep 07 nicklas 30
11 13 Sep 07 nicklas 31     private static final int FLAG_SIZE = 16;
11 13 Sep 07 nicklas 32     
11 13 Sep 07 nicklas 33     private BitSet flags;
11 13 Sep 07 nicklas 34
11 13 Sep 07 nicklas 35     public BitFlag() { setFlags((short)0); }
11 13 Sep 07 nicklas 36
11 13 Sep 07 nicklas 37     public BitFlag(short p) { setFlags(p); }
11 13 Sep 07 nicklas 38
11 13 Sep 07 nicklas 39     /** Clear all flags. */
11 13 Sep 07 nicklas 40     public void clear() { flags = null; }
11 13 Sep 07 nicklas 41
11 13 Sep 07 nicklas 42     /** Get all flags.
11 13 Sep 07 nicklas 43      * @return number with flags set.
11 13 Sep 07 nicklas 44      */
11 13 Sep 07 nicklas 45     public short getFlags() {
11 13 Sep 07 nicklas 46         short val = 0;
11 13 Sep 07 nicklas 47         if (flags == null)
11 13 Sep 07 nicklas 48             return val;
11 13 Sep 07 nicklas 49         for (int i=0; i<FLAG_SIZE; i++)
11 13 Sep 07 nicklas 50         {
11 13 Sep 07 nicklas 51             if (flags.get(i) == true)
11 13 Sep 07 nicklas 52                 val += (1<<i);
11 13 Sep 07 nicklas 53         }
11 13 Sep 07 nicklas 54         return val;
11 13 Sep 07 nicklas 55     }
11 13 Sep 07 nicklas 56
11 13 Sep 07 nicklas 57     /** Set all flags.
11 13 Sep 07 nicklas 58      * @param p number with flags set.
11 13 Sep 07 nicklas 59      */
11 13 Sep 07 nicklas 60     public void setFlags(short p) {
11 13 Sep 07 nicklas 61         flags = new BitSet(FLAG_SIZE);
11 13 Sep 07 nicklas 62         for (short i=0; i<FLAG_SIZE/2; i++)
11 13 Sep 07 nicklas 63         {
11 13 Sep 07 nicklas 64             if ((p & 1 << i) >= 1)
11 13 Sep 07 nicklas 65                 flags.set(i, true);
11 13 Sep 07 nicklas 66             else
11 13 Sep 07 nicklas 67                 flags.set(i, false);
11 13 Sep 07 nicklas 68         }
11 13 Sep 07 nicklas 69     }
11 13 Sep 07 nicklas 70     
11 13 Sep 07 nicklas 71     /** True if the default data set header flag has been set.
11 13 Sep 07 nicklas 72      * @return true if the default data set header flag has been set.
11 13 Sep 07 nicklas 73      */
11 13 Sep 07 nicklas 74     public boolean hasDefaultDataSetHdr() { return flags.get(DEFAULT_DATA_SET_HDR_FLAG); }
11 13 Sep 07 nicklas 75
11 13 Sep 07 nicklas 76     /** Set the default data set header flag.
11 13 Sep 07 nicklas 77      * @param p true or false.
11 13 Sep 07 nicklas 78      */
11 13 Sep 07 nicklas 79     public void setDefaultDataSetHdr(boolean p) {
11 13 Sep 07 nicklas 80         if (flags == null)
11 13 Sep 07 nicklas 81             flags = new BitSet(FLAG_SIZE);
11 13 Sep 07 nicklas 82         flags.set(DEFAULT_DATA_SET_HDR_FLAG, p);
11 13 Sep 07 nicklas 83     }
11 13 Sep 07 nicklas 84
11 13 Sep 07 nicklas 85 }