001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    
019    package org.apache.hadoop.record.compiler;
020    
021    import org.apache.hadoop.classification.InterfaceAudience;
022    import org.apache.hadoop.classification.InterfaceStability;
023    
024    
025    /**
026     * @deprecated Replaced by <a href="http://hadoop.apache.org/avro/">Avro</a>.
027     */
028    @Deprecated
029    @InterfaceAudience.Public
030    @InterfaceStability.Stable
031    public class JBoolean extends JType {
032      
033      class JavaBoolean extends JType.JavaType {
034        
035        JavaBoolean() {
036          super("boolean", "Bool", "Boolean", "TypeID.RIOType.BOOL");
037        }
038        
039        void genCompareTo(CodeBuffer cb, String fname, String other) {
040          cb.append(Consts.RIO_PREFIX + "ret = ("+fname+" == "+other+")? 0 : ("+
041              fname+"?1:-1);\n");
042        }
043        
044        String getTypeIDObjectString() {
045          return "org.apache.hadoop.record.meta.TypeID.BoolTypeID";
046        }
047    
048        void genHashCode(CodeBuffer cb, String fname) {
049          cb.append(Consts.RIO_PREFIX + "ret = ("+fname+")?0:1;\n");
050        }
051        
052        // In Binary format, boolean is written as byte. true = 1, false = 0
053        void genSlurpBytes(CodeBuffer cb, String b, String s, String l) {
054          cb.append("{\n");
055          cb.append("if ("+l+"<1) {\n");
056          cb.append("throw new java.io.IOException(\"Boolean is exactly 1 byte."+
057                    " Provided buffer is smaller.\");\n");
058          cb.append("}\n");
059          cb.append(s+"++; "+l+"--;\n");
060          cb.append("}\n");
061        }
062        
063        // In Binary format, boolean is written as byte. true = 1, false = 0
064        void genCompareBytes(CodeBuffer cb) {
065          cb.append("{\n");
066          cb.append("if (l1<1 || l2<1) {\n");
067          cb.append("throw new java.io.IOException(\"Boolean is exactly 1 byte."+
068                    " Provided buffer is smaller.\");\n");
069          cb.append("}\n");
070          cb.append("if (b1[s1] != b2[s2]) {\n");
071          cb.append("return (b1[s1]<b2[s2])? -1 : 0;\n");
072          cb.append("}\n");
073          cb.append("s1++; s2++; l1--; l2--;\n");
074          cb.append("}\n");
075        }
076      }
077      
078      class CppBoolean extends CppType {
079        
080        CppBoolean() {
081          super("bool");
082        }
083        
084        String getTypeIDObjectString() {
085          return "new ::hadoop::TypeID(::hadoop::RIOTYPE_BOOL)";
086        }
087      }
088    
089      /** Creates a new instance of JBoolean */
090      public JBoolean() {
091        setJavaType(new JavaBoolean());
092        setCppType(new CppBoolean());
093        setCType(new CType());
094      }
095      
096      String getSignature() {
097        return "z";
098      }
099    }