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.meta; 020 021import java.io.IOException; 022 023import org.apache.hadoop.classification.InterfaceAudience; 024import org.apache.hadoop.classification.InterfaceStability; 025import org.apache.hadoop.record.RecordOutput; 026 027/** 028 * Represents typeID for basic types. 029 * 030 * @deprecated Replaced by <a href="https://hadoop.apache.org/avro/">Avro</a>. 031 */ 032@Deprecated 033@InterfaceAudience.Public 034@InterfaceStability.Stable 035public class TypeID { 036 037 /** 038 * constants representing the IDL types we support 039 */ 040 public static final class RIOType { 041 public static final byte BOOL = 1; 042 public static final byte BUFFER = 2; 043 public static final byte BYTE = 3; 044 public static final byte DOUBLE = 4; 045 public static final byte FLOAT = 5; 046 public static final byte INT = 6; 047 public static final byte LONG = 7; 048 public static final byte MAP = 8; 049 public static final byte STRING = 9; 050 public static final byte STRUCT = 10; 051 public static final byte VECTOR = 11; 052 } 053 054 /** 055 * Constant classes for the basic types, so we can share them. 056 */ 057 public static final TypeID BoolTypeID = new TypeID(RIOType.BOOL); 058 public static final TypeID BufferTypeID = new TypeID(RIOType.BUFFER); 059 public static final TypeID ByteTypeID = new TypeID(RIOType.BYTE); 060 public static final TypeID DoubleTypeID = new TypeID(RIOType.DOUBLE); 061 public static final TypeID FloatTypeID = new TypeID(RIOType.FLOAT); 062 public static final TypeID IntTypeID = new TypeID(RIOType.INT); 063 public static final TypeID LongTypeID = new TypeID(RIOType.LONG); 064 public static final TypeID StringTypeID = new TypeID(RIOType.STRING); 065 066 protected byte typeVal; 067 068 /** 069 * Create a TypeID object 070 */ 071 TypeID(byte typeVal) { 072 this.typeVal = typeVal; 073 } 074 075 /** 076 * Get the type value. One of the constants in RIOType. 077 */ 078 public byte getTypeVal() { 079 return typeVal; 080 } 081 082 /** 083 * Serialize the TypeID object 084 */ 085 void write(RecordOutput rout, String tag) throws IOException { 086 rout.writeByte(typeVal, tag); 087 } 088 089 /** 090 * Two base typeIDs are equal if they refer to the same type 091 */ 092 @Override 093 public boolean equals(Object o) { 094 if (this == o) 095 return true; 096 097 if (o == null) 098 return false; 099 100 if (this.getClass() != o.getClass()) 101 return false; 102 103 TypeID oTypeID = (TypeID) o; 104 return (this.typeVal == oTypeID.typeVal); 105 } 106 107 /** 108 * We use a basic hashcode implementation, since this class will likely not 109 * be used as a hashmap key 110 */ 111 @Override 112 public int hashCode() { 113 // See 'Effectve Java' by Joshua Bloch 114 return 37*17+(int)typeVal; 115 } 116} 117