// Path: src/libra/common/helpers/PathHelper.java
// public class PathHelper {
//     
//     private static final String[] COMPRESSED_EXT = {"gz", "bz2"};
//     
//     public static String getParent(String path) {
//         // check root
//         if(path.equals("/")) {
//             return null;
//         }
//         
//         int lastIdx = path.lastIndexOf("/");
//         if(lastIdx > 0) {
//             return path.substring(0, lastIdx);
//         } else {
//             return "/";
//         }
//     }
//     
//     public static String concatPath(String path1, String path2) {
//         StringBuffer sb = new StringBuffer();
//         
//         if(path1 != null && !path1.isEmpty()) {
//             sb.append(path1);
//         }
//         
//         if(!path1.endsWith("/")) {
//             sb.append("/");
//         }
//         
//         if(path2 != null && !path2.isEmpty()) {
//             if(path2.startsWith("/")) {
//                 sb.append(path2.substring(1, path2.length()));
//             } else {
//                 sb.append(path2);
//             }
//         }
//         
//         return sb.toString();
//     }
//     
//     public static String getExtensionOfDecompressedFile(String name) {
//         String myname = name;
//         int idx = myname.lastIndexOf(".");
//         if(idx > 0) {
//             String ext = myname.substring(idx + 1);
//             for(String cext : COMPRESSED_EXT) {
//                 if(cext.equalsIgnoreCase(ext)) {
//                     // compressed
//                     myname = myname.substring(0, idx);
//                     break;
//                 }
//             }
//         } else {
//             return null;
//         }
//         
//         idx = myname.lastIndexOf(".");
//         if(idx > 0) {
//             return myname.substring(idx + 1);
//         }
//         return null;
//     }
// }
// 
// Path: src/libra/preprocess/common/PreprocessorConstants.java
// public class PreprocessorConstants {
//     public static final String FILE_TABLE_FILENAME_EXTENSION = "ftbl";
//     public static final String KMER_FILTER_TABLE_FILENAME_EXTENSION = "kflt";
//     public static final String KMER_INDEX_TABLE_FILENAME_EXTENSION = "kidx";
//     public static final String KMER_INDEX_DATA_FILENAME_EXTENSION = "kidxc";
//     public static final String KMER_STATISTICS_TABLE_FILENAME_EXTENSION = "kstat";
//     
//     public static final String FILE_TABLE_DIRNAME = "filetable";
//     public static final String KMER_FILTER_DIRNAME = "filter";
//     public static final String KMER_INDEX_DIRNAME = "kmerindex";
//     public static final String KMER_STATISITCS_DIRNAME = "statistics";
// }
// 
// Path: src/libra/preprocess/common/kmerindex/KmerIndexDataPathFilter.java
// public class KmerIndexDataPathFilter implements PathFilter {
// 
//     @Override
//     public boolean accept(Path path) {
//         return KmerIndexHelper.isKmerIndexDataFile(path);
//     }
// }


import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import libra.common.helpers.PathHelper;
import libra.preprocess.common.PreprocessorConstants;
import libra.preprocess.common.kmerindex.KmerIndexDataPathFilter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
    public static boolean isSameKmerIndex(Path index1, Path index2) {
        return isSameKmerIndex(index1.getName(), index2.getName());
    }
    
    public static boolean isSameKmerIndex(String index1, String index2) {
        String fileTableName1 = getFileTableName(index1);
        String fileTableName2 = getFileTableName(index2);
        
        if(fileTableName1 == null || fileTableName2 == null) {
            return false;
        }
        
        return fileTableName1.equals(fileTableName2);
    }
    
    public static int getIndexDataID(Path indexFilePath) {
        return getIndexDataID(indexFilePath.getName());
    }
    
    public static int getIndexDataID(String indexFileName) {
        int idx = indexFileName.lastIndexOf(".");
        if(idx >= 0) {
            String partID = indexFileName.substring(idx + 1);
            return Integer.parseInt(partID);
        }
        return -1;
    }
    
    public static Path[] getKmerIndexDataFilePaths(Configuration conf, Path inputPath) throws IOException {
        List<Path> inputFiles = new ArrayList<Path>();
// Path: src/libra/common/helpers/PathHelper.java
// public class PathHelper {
//     
//     private static final String[] COMPRESSED_EXT = {"gz", "bz2"};
//     
//     public static String getParent(String path) {
//         // check root
//         if(path.equals("/")) {
//             return null;
//         }
//         
//         int lastIdx = path.lastIndexOf("/");
//         if(lastIdx > 0) {
//             return path.substring(0, lastIdx);
//         } else {
//             return "/";
//         }
//     }
//     
//     public static String concatPath(String path1, String path2) {
//         StringBuffer sb = new StringBuffer();
//         
//         if(path1 != null && !path1.isEmpty()) {
//             sb.append(path1);
//         }
//         
//         if(!path1.endsWith("/")) {
//             sb.append("/");
//         }
//         
//         if(path2 != null && !path2.isEmpty()) {
//             if(path2.startsWith("/")) {
//                 sb.append(path2.substring(1, path2.length()));
//             } else {
//                 sb.append(path2);
//             }
//         }
//         
//         return sb.toString();
//     }
//     
//     public static String getExtensionOfDecompressedFile(String name) {
//         String myname = name;
//         int idx = myname.lastIndexOf(".");
//         if(idx > 0) {
//             String ext = myname.substring(idx + 1);
//             for(String cext : COMPRESSED_EXT) {
//                 if(cext.equalsIgnoreCase(ext)) {
//                     // compressed
//                     myname = myname.substring(0, idx);
//                     break;
//                 }
//             }
//         } else {
//             return null;
//         }
//         
//         idx = myname.lastIndexOf(".");
//         if(idx > 0) {
//             return myname.substring(idx + 1);
//         }
//         return null;
//     }
// }
// 
// Path: src/libra/preprocess/common/PreprocessorConstants.java
// public class PreprocessorConstants {
//     public static final String FILE_TABLE_FILENAME_EXTENSION = "ftbl";
//     public static final String KMER_FILTER_TABLE_FILENAME_EXTENSION = "kflt";
//     public static final String KMER_INDEX_TABLE_FILENAME_EXTENSION = "kidx";
//     public static final String KMER_INDEX_DATA_FILENAME_EXTENSION = "kidxc";
//     public static final String KMER_STATISTICS_TABLE_FILENAME_EXTENSION = "kstat";
//     
//     public static final String FILE_TABLE_DIRNAME = "filetable";
//     public static final String KMER_FILTER_DIRNAME = "filter";
//     public static final String KMER_INDEX_DIRNAME = "kmerindex";
//     public static final String KMER_STATISITCS_DIRNAME = "statistics";
// }
// 
// Path: src/libra/preprocess/common/kmerindex/KmerIndexDataPathFilter.java
// public class KmerIndexDataPathFilter implements PathFilter {
// 
//     @Override
//     public boolean accept(Path path) {
//         return KmerIndexHelper.isKmerIndexDataFile(path);
//     }
// }


// Path: src/libra/preprocess/common/helpers/KmerIndexHelper.java
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import libra.common.helpers.PathHelper;
import libra.preprocess.common.PreprocessorConstants;
import libra.preprocess.common.kmerindex.KmerIndexDataPathFilter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;

    public static boolean isSameKmerIndex(Path index1, Path index2) {
        return isSameKmerIndex(index1.getName(), index2.getName());
    }
    
    public static boolean isSameKmerIndex(String index1, String index2) {
        String fileTableName1 = getFileTableName(index1);
        String fileTableName2 = getFileTableName(index2);
        
        if(fileTableName1 == null || fileTableName2 == null) {
            return false;
        }
        
        return fileTableName1.equals(fileTableName2);
    }
    
    public static int getIndexDataID(Path indexFilePath) {
        return getIndexDataID(indexFilePath.getName());
    }
    
    public static int getIndexDataID(String indexFileName) {
        int idx = indexFileName.lastIndexOf(".");
        if(idx >= 0) {
            String partID = indexFileName.substring(idx + 1);
            return Integer.parseInt(partID);
        }
        return -1;
    }
    
    public static Path[] getKmerIndexDataFilePaths(Configuration conf, Path inputPath) throws IOException {
        List<Path> inputFiles = new ArrayList<Path>();
        KmerIndexDataPathFilter filter = new KmerIndexDataPathFilter();