code: private final static int difference(int seq1, int seq2, int maxSequence) {
          int diff = seq1 - seq2;
          if (Math.abs(diff) <= maxSequence / 2)
              return diff;
          else
              return (-Integer.signum(diff) * maxSequence) + diff;
      }
docs: /*
  Example: maxSequence = 100; maxSequence/2 = 50;
  seq1 = 10;
  seq2 = 30;
  diff = -20;
  abs(-20 ) <= 50  ==>  return -20;
  
  seq1 = 30;
  seq2 = 10;
  diff = 20;
  abs(20) <= 50  ==>  return 20;
  
  
  seq1 = 70;
  seq2 = 10;
  diff = 60;
  abs(60) !<= 50  ==>  return (-1 * 100) + 60 = -40
  
  seq1 = 10;
  seq2 = 70;
  diff = -60;
  abs(-60) !<= 50  ==> return (--1 * 100) - 60 = 40