code: @SuppressWarnings("unused")
  	private static void checkAndCoSort(int[] positions, Class<?>[] types) {
  		if (positions.length != types.length) {
  			throw new IllegalArgumentException("The positions and types must be of the same length");
  		}
  		
  		TreeMap<Integer, Class<?>> map = new TreeMap<Integer, Class<?>>();
  		
  		for (int i = 0; i < positions.length; i++) {
  			if (positions[i] < 0) {
  				throw new IllegalArgumentException("The field " + " (" + positions[i] + ") is invalid.");
  			}
  			if (types[i] == null) {
  				throw new IllegalArgumentException("The type " + i + " is invalid (null)");
  			}
  			
  			if (map.containsKey(positions[i])) {
  				throw new IllegalArgumentException("The position " + positions[i] + " occurs multiple times.");
  			}
  			
  			map.put(positions[i], types[i]);
  		}
  		
  		int i = 0;
  		for (Map.Entry<Integer, Class<?>> entry : map.entrySet()) {
  			positions[i] = entry.getKey();
  			types[i] = entry.getValue();
  			i++;
  		}
  	}
docs: --------------------------------------------------------------------------------------------