code: int calculateReplicationFactor(List<HostToken> allHostTokens) {
          Map<Long, Integer> groups = new HashMap<>();
  
          Set<HostToken> uniqueHostTokens = new HashSet<>(allHostTokens);
  
          String dataCenter = cpConfig.getLocalDataCenter();
          if (dataCenter == null) {
              dataCenter = localRack.substring(0, localRack.length() - 1);
          }
  
          for (HostToken hostToken: uniqueHostTokens) {
          	if (hostToken.getHost().getRack().contains(dataCenter)) {
  				Long token = hostToken.getToken();
  				if (groups.containsKey(token)) {
  					int current = groups.get(token);
  					groups.put(token, current + 1);
  				} else {
  					groups.put(token, 1);
  				}
  			}
          }
  
          Set<Integer> uniqueCounts = new HashSet<>(groups.values());
  
          if (uniqueCounts.size() > 1) {
              throw new RuntimeException("Invalid configuration - replication factor cannot be asymmetric");
          }
  
          int rf = uniqueCounts.toArray(new Integer[uniqueCounts.size()])[0];
  
          if (rf > 3) {
              logger.warn("Replication Factor is high: " + uniqueHostTokens);
          }
  
          return rf;
      }
docs: /*package private