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