View Javadoc

1   /*
2    * Copyright (c) 1998-2002 The Jgroup Team.
3    *
4    * This program is free software; you can redistribute it and/or modify
5    * it under the terms of the GNU Lesser General Public License version 2 as
6    * published by the Free Software Foundation.
7    *
8    * This program is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   * GNU Lesser General Public License for more details.
12   *
13   * You should have received a copy of the GNU Lesser General Public License
14   * along with this program; if not, write to the Free Software
15   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16   *
17   */
18  
19  package jgroup.relacs.types;
20  
21  import java.io.IOException;
22  import java.io.ObjectInput;
23  import java.io.ObjectOutput;
24  
25  /**
26   *  The <code>Flag</code> class wraps a value of the relacs daemon type 
27   *  "flag" in an object. A flag is a boolean type that can assume the
28   *  values {0, 1}. 
29   *
30   *  @author Alberto Montresor
31   *  @author Hein Meling
32   *  @since  Jgroup 1.2
33   */
34  public final class Flag
35  {
36    
37    ////////////////////////////////////////////////////////////////////////////////////////////
38    // Constants
39    ////////////////////////////////////////////////////////////////////////////////////////////
40  
41    /** Size of this object in bytes */
42    public static final int SIZE = 1;
43  
44  
45    ////////////////////////////////////////////////////////////////////////////////////////////
46    // Fields
47    ////////////////////////////////////////////////////////////////////////////////////////////
48    
49    /** Wrapped value */
50    private int value;
51  
52  
53    ////////////////////////////////////////////////////////////////////////////////////////////
54    // Constructor
55    ////////////////////////////////////////////////////////////////////////////////////////////
56    
57    /**
58     *  Creates a <CODE>Flag</CODE> object containing the specified
59     *  value.
60     */
61    public Flag(int value)
62    {
63      this.value = value;
64    }
65    
66    
67    ////////////////////////////////////////////////////////////////////////////////////////////
68    // Accessor method
69    ////////////////////////////////////////////////////////////////////////////////////////////
70    
71    /**
72     *  Returned the wrapped value.
73     */
74    public int getValue()
75    {
76      return value;
77    }
78    
79    ////////////////////////////////////////////////////////////////////////////////////////////
80    // Marshaling / unmarshaling methods
81    ////////////////////////////////////////////////////////////////////////////////////////////
82    
83    /**
84     *  Marshals the specified flag to an outgoing message.
85     */
86    public static void marshal(ObjectOutput msg, boolean value)
87      throws IOException
88    {
89      msg.writeBoolean(value);
90    }
91    
92    /**
93     *  Unmarshals a flag from an incoming message.
94     */
95    public static boolean unmarshal(ObjectInput msg)
96      throws IOException
97    {
98      return msg.readBoolean();
99    }
100 
101   /**
102    *  Unmarshals a flag from a byte.
103    */
104   public static boolean unmarshal(byte value)
105   {
106     return (value == 1 ? true : false);
107   }
108 
109 } // END Flag