code: private Class findNearestMatchingRelationClass(final String sourceTypeName, final String relType, final String targetTypeName) {
  
  		final Class sourceType               = getNodeEntityClass(sourceTypeName);
  		final Class targetType               = getNodeEntityClass(targetTypeName);
  		final Map<Integer, Class> candidates = new TreeMap<>();
  
  		for (final Class candidate : getRelationClassCandidatesForRelType(relType)) {
  
  			final Relation rel = instantiate(candidate);
  			final int distance = getDistance(rel.getSourceType(), sourceType, -1) + getDistance(rel.getTargetType(), targetType, -1);
  
  			if (distance >= 2000) {
  				candidates.put(distance - 2000, candidate);
  			}
  
  		}
  
  		if (candidates.isEmpty()) {
  			return null;
  
  		} else {
  
  			final Entry<Integer, Class> candidateEntry = candidates.entrySet().iterator().next();
  			final Class c = candidateEntry.getValue();
  
  			combinedTypeRelationClassCache.put(getCombinedType(sourceTypeName, relType, targetTypeName), c);
  
  			return c;
  		}
  	}
docs: Find the most specialized relation class matching the given
  parameters.
  
  If no direct match is found (source and target type are equal), we
  count the levels of inheritance, including interfaces.
  
  @param sourceTypeName
  @param relType
  @param targetTypeName
  @param rel
  @param candidate
  @return class