1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.hadoop.record.compiler; 20 21 import org.apache.hadoop.classification.InterfaceAudience; 22 import org.apache.hadoop.classification.InterfaceStability; 23 24 /** 25 * @deprecated Replaced by <a href="http://hadoop.apache.org/avro/">Avro</a>. 26 */ 27 @Deprecated 28 @InterfaceAudience.Public 29 @InterfaceStability.Stable 30 public class JFloat extends JType { 31 32 class JavaFloat extends JavaType { 33 JavaFloat()34 JavaFloat() { 35 super("float", "Float", "Float", "TypeID.RIOType.FLOAT"); 36 } 37 38 @Override getTypeIDObjectString()39 String getTypeIDObjectString() { 40 return "org.apache.hadoop.record.meta.TypeID.FloatTypeID"; 41 } 42 43 @Override genHashCode(CodeBuffer cb, String fname)44 void genHashCode(CodeBuffer cb, String fname) { 45 cb.append(Consts.RIO_PREFIX + "ret = Float.floatToIntBits("+fname+");\n"); 46 } 47 48 @Override genSlurpBytes(CodeBuffer cb, String b, String s, String l)49 void genSlurpBytes(CodeBuffer cb, String b, String s, String l) { 50 cb.append("{\n"); 51 cb.append("if ("+l+"<4) {\n"); 52 cb.append("throw new java.io.IOException(\"Float is exactly 4 bytes."+ 53 " Provided buffer is smaller.\");\n"); 54 cb.append("}\n"); 55 cb.append(s+"+=4; "+l+"-=4;\n"); 56 cb.append("}\n"); 57 } 58 59 @Override genCompareBytes(CodeBuffer cb)60 void genCompareBytes(CodeBuffer cb) { 61 cb.append("{\n"); 62 cb.append("if (l1<4 || l2<4) {\n"); 63 cb.append("throw new java.io.IOException(\"Float is exactly 4 bytes."+ 64 " Provided buffer is smaller.\");\n"); 65 cb.append("}\n"); 66 cb.append("float f1 = org.apache.hadoop.record.Utils.readFloat(b1, s1);\n"); 67 cb.append("float f2 = org.apache.hadoop.record.Utils.readFloat(b2, s2);\n"); 68 cb.append("if (f1 != f2) {\n"); 69 cb.append("return ((f1-f2) < 0) ? -1 : 0;\n"); 70 cb.append("}\n"); 71 cb.append("s1+=4; s2+=4; l1-=4; l2-=4;\n"); 72 cb.append("}\n"); 73 } 74 } 75 76 class CppFloat extends CppType { 77 CppFloat()78 CppFloat() { 79 super("float"); 80 } 81 82 @Override getTypeIDObjectString()83 String getTypeIDObjectString() { 84 return "new ::hadoop::TypeID(::hadoop::RIOTYPE_FLOAT)"; 85 } 86 } 87 88 /** Creates a new instance of JFloat */ JFloat()89 public JFloat() { 90 setJavaType(new JavaFloat()); 91 setCppType(new CppFloat()); 92 setCType(new CType()); 93 } 94 95 @Override getSignature()96 String getSignature() { 97 return "f"; 98 } 99 } 100