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.hadoop.classification.InterfaceAudience;
021 import org.apache.hadoop.classification.InterfaceStability;
022
023 /**
024 * Opaque interface that identifies a disk location. Subclasses
025 * should implement {@link Comparable} and override both equals and hashCode.
026 */
027 @InterfaceStability.Unstable
028 @InterfaceAudience.Public
029 public interface VolumeId extends Comparable<VolumeId> {
030
031 /**
032 * Represents an invalid Volume ID (ID for unknown content).
033 */
034 public static final VolumeId INVALID_VOLUME_ID = new VolumeId() {
035
036 @Override
037 public int compareTo(VolumeId arg0) {
038 // This object is equal only to itself;
039 // It is greater than null, and
040 // is always less than any other VolumeId:
041 if (arg0 == null) {
042 return 1;
043 }
044 if (arg0 == this) {
045 return 0;
046 } else {
047 return -1;
048 }
049 }
050
051 @Override
052 public boolean equals(Object obj) {
053 // this object is equal only to itself:
054 return (obj == this);
055 }
056
057 @Override
058 public int hashCode() {
059 return Integer.MIN_VALUE;
060 }
061
062 @Override
063 public boolean isValid() {
064 return false;
065 }
066
067 @Override
068 public String toString() {
069 return "Invalid VolumeId";
070 }
071 };
072
073 /**
074 * Indicates if the disk identifier is valid. Invalid identifiers indicate
075 * that the block was not present, or the location could otherwise not be
076 * determined.
077 *
078 * @return true if the disk identifier is valid
079 */
080 public boolean isValid();
081
082 @Override
083 abstract public int compareTo(VolumeId arg0);
084
085 @Override
086 abstract public int hashCode();
087
088 @Override
089 abstract public boolean equals(Object obj);
090
091 }