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