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 */
018package org.apache.hadoop.hdfs;
019
020import org.apache.commons.lang.builder.EqualsBuilder;
021import org.apache.commons.lang.builder.HashCodeBuilder;
022import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
023
024/**
025 * An immutable key which identifies a block.
026 */
027final public class ExtendedBlockId {
028  /**
029   * The block ID for this block.
030   */
031  private final long blockId;
032
033  /**
034   * The block pool ID for this block.
035   */
036  private final String bpId;
037
038  public static ExtendedBlockId fromExtendedBlock(ExtendedBlock block) {
039    return new ExtendedBlockId(block.getBlockId(), block.getBlockPoolId());
040  }
041  
042  public ExtendedBlockId(long blockId, String bpId) {
043    this.blockId = blockId;
044    this.bpId = bpId;
045  }
046
047  public long getBlockId() {
048    return this.blockId;
049  }
050
051  public String getBlockPoolId() {
052    return this.bpId;
053  }
054
055  @Override
056  public boolean equals(Object o) {
057    if ((o == null) || (o.getClass() != this.getClass())) {
058      return false;
059    }
060    ExtendedBlockId other = (ExtendedBlockId)o;
061    return new EqualsBuilder().
062        append(blockId, other.blockId).
063        append(bpId, other.bpId).
064        isEquals();
065  }
066
067  @Override
068  public int hashCode() {
069    return new HashCodeBuilder().
070        append(this.blockId).
071        append(this.bpId).
072        toHashCode();
073  }
074
075  @Override
076  public String toString() {
077    return new StringBuilder().append(blockId).
078        append("_").append(bpId).toString();
079  }
080}