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.hdfs.protocol;
019    
020    import java.util.Arrays;
021    
022    /**
023     * Contains a list of paths corresponding to corrupt files and a cookie
024     * used for iterative calls to NameNode.listCorruptFileBlocks.
025     *
026     */
027    public class CorruptFileBlocks {
028      // used for hashCode
029      private static final int PRIME = 16777619;
030    
031      private String[] files;
032      private String cookie;
033    
034      public CorruptFileBlocks() {
035        this(new String[0], "");
036      }
037    
038      public CorruptFileBlocks(String[] files, String cookie) {
039        this.files = files;
040        this.cookie = cookie;
041      }
042    
043      public String[] getFiles() {
044        return files;
045      }
046    
047      public String getCookie() {
048        return cookie;
049      }
050    
051      @Override
052      public boolean equals(Object obj) {
053        if (this == obj) {
054          return true;
055        }
056        if (!(obj instanceof CorruptFileBlocks)) {
057          return false;
058        }
059        CorruptFileBlocks other = (CorruptFileBlocks) obj;
060        return cookie.equals(other.cookie) &&
061          Arrays.equals(files, other.files);
062      }
063    
064      
065      @Override
066      public int hashCode() {
067        int result = cookie.hashCode();
068    
069        for (String file : files) {
070          result = PRIME * result + file.hashCode();
071        }
072    
073        return result;
074      }
075    }