PageRenderTime 88ms CodeModel.GetById 82ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/MapTypeInfo.java

#
Java | 105 lines | 52 code | 17 blank | 36 comment | 4 complexity | 8ba5a8b7ecb91deb4ec987798b43718e MD5 | raw file
  1/**
  2 * Licensed to the Apache Software Foundation (ASF) under one
  3 * or more contributor license agreements.  See the NOTICE file
  4 * distributed with this work for additional information
  5 * regarding copyright ownership.  The ASF licenses this file
  6 * to you under the Apache License, Version 2.0 (the
  7 * "License"); you may not use this file except in compliance
  8 * with the License.  You may obtain a copy of the License at
  9 *
 10 *     http://www.apache.org/licenses/LICENSE-2.0
 11 *
 12 * Unless required by applicable law or agreed to in writing, software
 13 * distributed under the License is distributed on an "AS IS" BASIS,
 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18
 19package org.apache.hadoop.hive.serde2.typeinfo;
 20
 21import java.io.Serializable;
 22
 23import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
 24
 25/**
 26 * A Map Type has homogeneous keys and homogeneous values. All keys of the Map
 27 * have the same TypeInfo, which is returned by getMapKeyTypeInfo(); and all
 28 * values of the Map has the same TypeInfo, which is returned by
 29 * getMapValueTypeInfo().
 30 * 
 31 * Always use the TypeInfoFactory to create new TypeInfo objects, instead of
 32 * directly creating an instance of this class.
 33 */
 34public final class MapTypeInfo extends TypeInfo implements Serializable {
 35
 36  private static final long serialVersionUID = 1L;
 37
 38  private TypeInfo mapKeyTypeInfo;
 39  private TypeInfo mapValueTypeInfo;
 40
 41  /**
 42   * For java serialization use only.
 43   */
 44  public MapTypeInfo() {
 45  }
 46
 47  @Override
 48  public String getTypeName() {
 49    return org.apache.hadoop.hive.serde.Constants.MAP_TYPE_NAME + "<"
 50        + mapKeyTypeInfo.getTypeName() + "," + mapValueTypeInfo.getTypeName()
 51        + ">";
 52  }
 53
 54  /**
 55   * For java serialization use only.
 56   */
 57  public void setMapKeyTypeInfo(TypeInfo mapKeyTypeInfo) {
 58    this.mapKeyTypeInfo = mapKeyTypeInfo;
 59  }
 60
 61  /**
 62   * For java serialization use only.
 63   */
 64  public void setMapValueTypeInfo(TypeInfo mapValueTypeInfo) {
 65    this.mapValueTypeInfo = mapValueTypeInfo;
 66  }
 67
 68  // For TypeInfoFactory use only
 69  MapTypeInfo(TypeInfo keyTypeInfo, TypeInfo valueTypeInfo) {
 70    mapKeyTypeInfo = keyTypeInfo;
 71    mapValueTypeInfo = valueTypeInfo;
 72  }
 73
 74  @Override
 75  public Category getCategory() {
 76    return Category.MAP;
 77  }
 78
 79  public TypeInfo getMapKeyTypeInfo() {
 80    return mapKeyTypeInfo;
 81  }
 82
 83  public TypeInfo getMapValueTypeInfo() {
 84    return mapValueTypeInfo;
 85  }
 86
 87  @Override
 88  public boolean equals(Object other) {
 89    if (this == other) {
 90      return true;
 91    }
 92    if (!(other instanceof MapTypeInfo)) {
 93      return false;
 94    }
 95    MapTypeInfo o = (MapTypeInfo) other;
 96    return o.getMapKeyTypeInfo().equals(getMapKeyTypeInfo())
 97        && o.getMapValueTypeInfo().equals(getMapValueTypeInfo());
 98  }
 99
100  @Override
101  public int hashCode() {
102    return mapKeyTypeInfo.hashCode() ^ mapValueTypeInfo.hashCode();
103  }
104
105}