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 * @deprecated Replaced by <a href="http://hadoop.apache.org/avro/">Avro</a>.
026 */
027 @Deprecated
028 @InterfaceAudience.Public
029 @InterfaceStability.Stable
030 public class JFloat extends JType {
031
032 class JavaFloat extends JavaType {
033
034 JavaFloat() {
035 super("float", "Float", "Float", "TypeID.RIOType.FLOAT");
036 }
037
038 String getTypeIDObjectString() {
039 return "org.apache.hadoop.record.meta.TypeID.FloatTypeID";
040 }
041
042 void genHashCode(CodeBuffer cb, String fname) {
043 cb.append(Consts.RIO_PREFIX + "ret = Float.floatToIntBits("+fname+");\n");
044 }
045
046 void genSlurpBytes(CodeBuffer cb, String b, String s, String l) {
047 cb.append("{\n");
048 cb.append("if ("+l+"<4) {\n");
049 cb.append("throw new java.io.IOException(\"Float is exactly 4 bytes."+
050 " Provided buffer is smaller.\");\n");
051 cb.append("}\n");
052 cb.append(s+"+=4; "+l+"-=4;\n");
053 cb.append("}\n");
054 }
055
056 void genCompareBytes(CodeBuffer cb) {
057 cb.append("{\n");
058 cb.append("if (l1<4 || l2<4) {\n");
059 cb.append("throw new java.io.IOException(\"Float is exactly 4 bytes."+
060 " Provided buffer is smaller.\");\n");
061 cb.append("}\n");
062 cb.append("float f1 = org.apache.hadoop.record.Utils.readFloat(b1, s1);\n");
063 cb.append("float f2 = org.apache.hadoop.record.Utils.readFloat(b2, s2);\n");
064 cb.append("if (f1 != f2) {\n");
065 cb.append("return ((f1-f2) < 0) ? -1 : 0;\n");
066 cb.append("}\n");
067 cb.append("s1+=4; s2+=4; l1-=4; l2-=4;\n");
068 cb.append("}\n");
069 }
070 }
071
072 class CppFloat extends CppType {
073
074 CppFloat() {
075 super("float");
076 }
077
078 String getTypeIDObjectString() {
079 return "new ::hadoop::TypeID(::hadoop::RIOTYPE_FLOAT)";
080 }
081 }
082
083 /** Creates a new instance of JFloat */
084 public JFloat() {
085 setJavaType(new JavaFloat());
086 setCppType(new CppFloat());
087 setCType(new CType());
088 }
089
090 String getSignature() {
091 return "f";
092 }
093 }