\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] \PYG{c+c1}{// Depending on how often we intend to do this calculation and how we intend to do it, it would likely be better to put this method in the `Graph` class.} \PYG{c+c1}{// However, to keep in line with the simplicity of the classes as defined previously, I have opted to pass the Graph to the method as an argument rather than change the Graph class.} \PYG{c+c1}{// Input: A snapshot Graph object.} \PYG{c+c1}{// Output: A HashMap data structure in which the key is a Player (node) object and the value accessible by that key is the degree of that Player (node) object.} \PYG{k+kd}{public}\PYG{+w}{ }\PYG{n}{HashMap}\PYG{o}{\PYGZlt{}}\PYG{n}{Player}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{Integer}\PYG{o}{\PYGZgt{}}\PYG{+w}{ }\PYG{n+nf}{calculateDegrees}\PYG{p}{(}\PYG{n}{Graph}\PYG{+w}{ }\PYG{n}{graph}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} \PYG{+w}{ }\PYG{n}{HashMap}\PYG{o}{\PYGZlt{}}\PYG{n}{Player}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{Integer}\PYG{o}{\PYGZgt{}}\PYG{+w}{ }\PYG{n}{returnValues}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{HashMap}\PYG{o}{\PYGZlt{}\PYGZgt{}}\PYG{p}{();} \PYG{+w}{ }\PYG{c+c1}{// looping over each Edge in the Graph} \PYG{+w}{ }\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{Edge}\PYG{+w}{ }\PYG{n}{edge}\PYG{p}{:}\PYG{+w}{ }\PYG{n}{graph}\PYG{p}{.}\PYG{n+na}{edges}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} \PYG{+w}{ }\PYG{c+c1}{// loop over each Player in the Edge's `nodes` Set} \PYG{+w}{ }\PYG{c+c1}{// there should really be no more than two, practically speaking, and no less than 2 assuming that we are not dealing with multigraphs but the number of nodes an edge joins doesn't matter from an algorithmic perspective} \PYG{+w}{ }\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{Player}\PYG{+w}{ }\PYG{n}{player}\PYG{+w}{ }\PYG{p}{:}\PYG{+w}{ }\PYG{n}{edge}\PYG{p}{.}\PYG{n+na}{nodes}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} \PYG{+w}{ }\PYG{c+c1}{// get the current degree count for the player if it is already defined} \PYG{+w}{ }\PYG{n}{Integer}\PYG{+w}{ }\PYG{n}{degree}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{returnValues}\PYG{p}{.}\PYG{n+na}{get}\PYG{p}{(}\PYG{n}{player}\PYG{p}{);} \PYG{+w}{ }\PYG{c+c1}{// if the degree is not yet defined, set it to 1} \PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{degree}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{k+kc}{null}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} \PYG{+w}{ }\PYG{n}{degree}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;} \PYG{+w}{ }\PYG{p}{\PYGZcb{}} \PYG{+w}{ }\PYG{c+c1}{// otherwise increment it by 1} \PYG{+w}{ }\PYG{k}{else}\PYG{+w}{ }\PYG{p}{\PYGZob{}} \PYG{+w}{ }\PYG{n}{degree}\PYG{o}{++}\PYG{p}{;} \PYG{+w}{ }\PYG{p}{\PYGZcb{}} \PYG{+w}{ }\PYG{c+c1}{// set the player's degree in returnValues to the updated value} \PYG{+w}{ }\PYG{n}{returnValues}\PYG{p}{.}\PYG{n+na}{put}\PYG{p}{(}\PYG{n}{player}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{degree}\PYG{p}{);} \PYG{+w}{ }\PYG{p}{\PYGZcb{}} \PYG{+w}{ }\PYG{p}{\PYGZcb{}} \PYG{p}{\PYGZcb{}} \end{Verbatim}