View Javadoc

1   /*
2    *   Copyright 2005 The Apache Software Foundation
3    *
4    *   Licensed under the Apache License, Version 2.0 (the "License");
5    *   you may not use this file except in compliance with the License.
6    *   You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *   Unless required by applicable law or agreed to in writing, software
11   *   distributed under the License is distributed on an "AS IS" BASIS,
12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *   See the License for the specific language governing permissions and
14   *   limitations under the License.
15   *
16   */
17  
18  package org.apache.asn1.der;
19  
20  /***
21   * DER Boolean object.
22   */
23  public class DERBoolean extends DERObject
24  {
25  	private static final byte[] trueArray  = { (byte)0xff };
26  	private static final byte[] falseArray = { (byte)0x00 };
27  	
28      public static final DERBoolean TRUE  = new DERBoolean( trueArray );
29      public static final DERBoolean FALSE = new DERBoolean( falseArray );
30      
31      /***
32       * Basic DERObject constructor.
33       */
34      public DERBoolean( byte[] value )
35      {
36          super( BOOLEAN, value );
37      }
38      
39      /***
40       * Static factory method, type-conversion operator.
41       */
42      public static DERBoolean valueOf( boolean value )
43      {
44          return ( value ? TRUE : FALSE );
45      }
46      
47      /***
48       * Lazy accessor
49       * @return boolean value
50       */
51      public boolean isTrue()
52      {
53          return value[ 0 ] == (byte)0xff;
54      }
55  }
56