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.meta;
020
021 import java.io.IOException;
022
023 import org.apache.hadoop.classification.InterfaceAudience;
024 import org.apache.hadoop.classification.InterfaceStability;
025 import org.apache.hadoop.record.RecordOutput;
026
027 /**
028 * Represents a type information for a field, which is made up of its
029 * ID (name) and its type (a TypeID object).
030 *
031 * @deprecated Replaced by <a href="http://hadoop.apache.org/avro/">Avro</a>.
032 */
033 @Deprecated
034 @InterfaceAudience.Public
035 @InterfaceStability.Stable
036 public class FieldTypeInfo
037 {
038
039 private String fieldID;
040 private TypeID typeID;
041
042 /**
043 * Construct a FiledTypeInfo with the given field name and the type
044 */
045 FieldTypeInfo(String fieldID, TypeID typeID) {
046 this.fieldID = fieldID;
047 this.typeID = typeID;
048 }
049
050 /**
051 * get the field's TypeID object
052 */
053 public TypeID getTypeID() {
054 return typeID;
055 }
056
057 /**
058 * get the field's id (name)
059 */
060 public String getFieldID() {
061 return fieldID;
062 }
063
064 void write(RecordOutput rout, String tag) throws IOException {
065 rout.writeString(fieldID, tag);
066 typeID.write(rout, tag);
067 }
068
069 /**
070 * Two FieldTypeInfos are equal if ach of their fields matches
071 */
072 @Override
073 public boolean equals(Object o) {
074 if (this == o)
075 return true;
076 if (!(o instanceof FieldTypeInfo))
077 return false;
078 FieldTypeInfo fti = (FieldTypeInfo) o;
079 // first check if fieldID matches
080 if (!this.fieldID.equals(fti.fieldID)) {
081 return false;
082 }
083 // now see if typeID matches
084 return (this.typeID.equals(fti.typeID));
085 }
086
087 /**
088 * We use a basic hashcode implementation, since this class will likely not
089 * be used as a hashmap key
090 */
091 @Override
092 public int hashCode() {
093 return 37*17+typeID.hashCode() + 37*17+fieldID.hashCode();
094 }
095
096
097 public boolean equals(FieldTypeInfo ti) {
098 // first check if fieldID matches
099 if (!this.fieldID.equals(ti.fieldID)) {
100 return false;
101 }
102 // now see if typeID matches
103 return (this.typeID.equals(ti.typeID));
104 }
105
106 }
107