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 import org.apache.hadoop.classification.InterfaceAudience;
023 import org.apache.hadoop.classification.InterfaceStability;
024 import org.apache.hadoop.record.RecordOutput;
025
026 /**
027 * Represents typeID for a Map
028 *
029 * @deprecated Replaced by <a href="http://hadoop.apache.org/avro/">Avro</a>.
030 */
031 @Deprecated
032 @InterfaceAudience.Public
033 @InterfaceStability.Stable
034 public class MapTypeID extends TypeID {
035
036 private TypeID typeIDKey;
037 private TypeID typeIDValue;
038
039 public MapTypeID(TypeID typeIDKey, TypeID typeIDValue) {
040 super(RIOType.MAP);
041 this.typeIDKey = typeIDKey;
042 this.typeIDValue = typeIDValue;
043 }
044
045 /**
046 * get the TypeID of the map's key element
047 */
048 public TypeID getKeyTypeID() {
049 return this.typeIDKey;
050 }
051
052 /**
053 * get the TypeID of the map's value element
054 */
055 public TypeID getValueTypeID() {
056 return this.typeIDValue;
057 }
058
059 @Override
060 void write(RecordOutput rout, String tag) throws IOException {
061 rout.writeByte(typeVal, tag);
062 typeIDKey.write(rout, tag);
063 typeIDValue.write(rout, tag);
064 }
065
066 /**
067 * Two map typeIDs are equal if their constituent elements have the
068 * same type
069 */
070 @Override
071 public boolean equals(Object o) {
072 if (!super.equals(o))
073 return false;
074
075 MapTypeID mti = (MapTypeID) o;
076
077 return this.typeIDKey.equals(mti.typeIDKey) &&
078 this.typeIDValue.equals(mti.typeIDValue);
079 }
080
081 /**
082 * We use a basic hashcode implementation, since this class will likely not
083 * be used as a hashmap key
084 */
085 @Override
086 public int hashCode() {
087 return 37*17+typeIDKey.hashCode() + 37*17+typeIDValue.hashCode();
088 }
089
090 }