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    package org.apache.hadoop.fs;
019    
020    import org.apache.commons.lang.builder.EqualsBuilder;
021    import org.apache.commons.lang.builder.HashCodeBuilder;
022    import org.apache.hadoop.classification.InterfaceAudience;
023    import org.apache.hadoop.classification.InterfaceStability;
024    
025    /**
026     * HDFS-specific volume identifier which implements {@link VolumeId}. Can be
027     * used to differentiate between the data directories on a single datanode. This
028     * identifier is only unique on a per-datanode basis.
029     */
030    @InterfaceStability.Unstable
031    @InterfaceAudience.Public
032    public class HdfsVolumeId implements VolumeId {
033    
034      private final byte id;
035      private final boolean isValid;
036    
037      public HdfsVolumeId(byte id, boolean isValid) {
038        this.id = id;
039        this.isValid = isValid;
040      }
041    
042      @Override
043      public boolean isValid() {
044        return isValid;
045      }
046    
047      @Override
048      public int compareTo(VolumeId arg0) {
049        return hashCode() - arg0.hashCode();
050      }
051    
052      @Override
053      public int hashCode() {
054        return new HashCodeBuilder().append(id).toHashCode();
055      }
056    
057      @Override
058      public boolean equals(Object obj) {
059        if (obj == null || obj.getClass() != getClass()) {
060          return false;
061        }
062        if (obj == this) {
063          return true;
064        }
065    
066        HdfsVolumeId that = (HdfsVolumeId) obj;
067        return new EqualsBuilder().append(this.id, that.id).isEquals();
068      }
069    
070      @Override
071      public String toString() {
072        return Byte.toString(id);
073      }
074    }