//        @Override
    //        protected void map(ImmutableBytesWritable key, Text value, Context context) throws
    // IOException, InterruptedException {
    //            Text combinedKeyValue = new Text();
    //            //the structure is key###value
    //            combinedKeyValue.set(Bytes.toString(key.get()) + "###" + value.toString());
    //            context.write(one, combinedKeyValue);
    //        }
    @Override
    protected void map(ImmutableBytesWritable key, Result columns, Context context)
        throws IOException, InterruptedException {

      Text combinedKeyValue = new Text();
      // the structure is key###value
      String value = null;
      try {
        for (KeyValue kv : columns.list()) {
          byte[] gmmData = kv.getValue();
          String gmmString = Bytes.toStringBinary(gmmData);

          // /* just for checking that gmm is correctly constructed
          MixtureModel m = null;
          m = (MixtureModel) ObjectAndByte.byteArrayToObject(Bytes.toBytesBinary(gmmString));
          System.out.println("m.size:" + m.size);
          // */
          combinedKeyValue.set(Bytes.toString(key.get()) + "###" + gmmString);
          context.write(one, combinedKeyValue);
          //                    context.write(key, new Text(gmmString));

        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    @Override
    protected void reduce(IntWritable key, Iterable<Text> values, Context context)
        throws IOException, InterruptedException {
      for (Text value : values) {
        String kv = value.toString();
        // kv is of form key###value
        int indexSeparator = kv.indexOf("###");
        String keyOnly = kv.substring(0, indexSeparator);
        String gmmString = kv.substring(indexSeparator + 3);

        /*
         * just for testing that casting is error free
         */
        byte[] gmmBinary = Bytes.toBytesBinary(gmmString);
        MixtureModel m = null;
        try {
          m = (MixtureModel) ObjectAndByte.byteArrayToObject(gmmBinary);
          // System.out.println("m.size:" + m.size);
          System.out.println("Gmm in good state:" + keyOnly);
          keyList.add(keyOnly);
          valueList.add(gmmString);
        } catch (ClassNotFoundException ex) {
          ex.printStackTrace();
        } catch (ArrayStoreException ase) {
          System.out.println("array store exception:");
          System.out.println("gmm corrupted :" + keyOnly);
        }
        /*
         * testing ends here
         */
      }
      int numOfGmm = keyList.size();
      for (int i = 0; i < numOfGmm; i++) {
        for (int j = i + 1; j < numOfGmm; j++) {
          outKey.set(keyList.get(i) + ":" + keyList.get(j));
          outValue.set(valueList.get(i) + "###" + valueList.get(j));
          context.write(outKey, outValue);
        }
      }
    }