code: public int getLength(int positionA, int positionB, String startingChain) {
  
  		int positionStart, positionEnd;
  		if (positionA <= positionB) {
  			positionStart = positionA;
  			positionEnd = positionB;
  		} else {
  			positionStart = positionB;
  			positionEnd = positionA;
  		}
  
  		int count = 0;
  		// Inefficient search
  		for (Map.Entry<ResidueNumber, Integer> entry : treeMap.entrySet()) {
  			if (entry.getKey().getChainName().equals(startingChain)
  					&& positionStart <= entry.getValue()
  					&& entry.getValue() <= positionEnd)
  			{
  				count++;
  			}
  		}
  		return count;
  	}
docs: Calculates the number of residues of the specified chain in a given range, inclusive.
  @param positionA index of the first atom to count
  @param positionB index of the last atom to count
  @param startingChain Case-sensitive chain
  @return The number of atoms between A and B inclusive belonging to the given chain