  public static class MasteringHadoopReduceSideJoinReduce extends
             Reducer<CompositeJoinKeyWritable, Text, Text, LongWritable>{
 
         private static LongWritable populationValue = new LongWritable(0);
         private static Text countryValue = new Text("");
         private static short POPULATION_INDEX = 4;
 
         @Override
         protected void reduce(CompositeJoinKeyWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
 
             long populationTotal = 0;
             boolean firstRecord = true;
             String country = null;
             for(Text record : values){
 
                 String[] tokens = record.toString().split(",", -1);
                 if(firstRecord){
                     firstRecord = false;
                     if(tokens.length > 1)
                         break;
                     else
                       country = tokens[0];
                 }
                 else{
                     String populationString = tokens[POPULATION_INDEX];
 
                     if(populationString != null && populationString.isEmpty() == false){
                         populationTotal += Long.parseLong(populationString);
                     }
 
                 }
             }
 
             if(country != null){
                 populationValue.set(populationTotal);
                 countryValue.set(country);
                 context.write(countryValue, populationValue);
 
             }
 
 
         }
     }
 
