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 019package org.apache.hadoop.record.compiler; 020 021import org.apache.hadoop.classification.InterfaceAudience; 022import 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 031public 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 @Override 040 void genCompareTo(CodeBuffer cb, String fname, String other) { 041 cb.append(Consts.RIO_PREFIX + "ret = ("+fname+" == "+other+")? 0 : ("+ 042 fname+"?1:-1);\n"); 043 } 044 045 @Override 046 String getTypeIDObjectString() { 047 return "org.apache.hadoop.record.meta.TypeID.BoolTypeID"; 048 } 049 050 @Override 051 void genHashCode(CodeBuffer cb, String fname) { 052 cb.append(Consts.RIO_PREFIX + "ret = ("+fname+")?0:1;\n"); 053 } 054 055 // In Binary format, boolean is written as byte. true = 1, false = 0 056 @Override 057 void genSlurpBytes(CodeBuffer cb, String b, String s, String l) { 058 cb.append("{\n"); 059 cb.append("if ("+l+"<1) {\n"); 060 cb.append("throw new java.io.IOException(\"Boolean is exactly 1 byte."+ 061 " Provided buffer is smaller.\");\n"); 062 cb.append("}\n"); 063 cb.append(s+"++; "+l+"--;\n"); 064 cb.append("}\n"); 065 } 066 067 // In Binary format, boolean is written as byte. true = 1, false = 0 068 @Override 069 void genCompareBytes(CodeBuffer cb) { 070 cb.append("{\n"); 071 cb.append("if (l1<1 || l2<1) {\n"); 072 cb.append("throw new java.io.IOException(\"Boolean is exactly 1 byte."+ 073 " Provided buffer is smaller.\");\n"); 074 cb.append("}\n"); 075 cb.append("if (b1[s1] != b2[s2]) {\n"); 076 cb.append("return (b1[s1]<b2[s2])? -1 : 0;\n"); 077 cb.append("}\n"); 078 cb.append("s1++; s2++; l1--; l2--;\n"); 079 cb.append("}\n"); 080 } 081 } 082 083 class CppBoolean extends CppType { 084 085 CppBoolean() { 086 super("bool"); 087 } 088 089 @Override 090 String getTypeIDObjectString() { 091 return "new ::hadoop::TypeID(::hadoop::RIOTYPE_BOOL)"; 092 } 093 } 094 095 /** Creates a new instance of JBoolean */ 096 public JBoolean() { 097 setJavaType(new JavaBoolean()); 098 setCppType(new CppBoolean()); 099 setCType(new CType()); 100 } 101 102 @Override 103 String getSignature() { 104 return "z"; 105 } 106}