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