package MasteringHadoop;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FSDataInputStream;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.mapreduce.*;
 import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
 import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
 import org.apache.hadoop.util.GenericOptionsParser;
 import org.apache.hadoop.util.LineReader;
 
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.TreeMap;
 
 public class MasteringHadoopMapSideJoin {
 
     public static class MasteringHadoopMapSideJoinMap extends Mapper<LongWritable, Text, Text, LongWritable> {
 
         private static short COUNTRY_CODE_INDEX = 0;
         private static short COUNTRY_NAME_INDEX = 1;
         private static short POPULATION_INDEX = 4;
 
 
         private TreeMap<String, String> countryCodesTreeMap = new TreeMap<String, String>();
         private Text countryKey = new Text("");
         private LongWritable populationValue = new LongWritable(0);
 
 
         @Override
         protected void setup(Context context) throws IOException, InterruptedException {
 
             URI[] localFiles = context.getCacheFiles();
 
             String path = null;
             for(URI uri : localFiles){
                 path = uri.getPath();
                 if(path.trim().equals("countrycodes.txt")){
                      break;
                 }
 
             }
 
             if(path != null){
                getCountryCodes(path, context);
             }
 
         }
 
 
