code: public static int getTotalHydrogenCount(IAtomContainer container) {
          if (container == null) throw new IllegalArgumentException("null container provided");
          int hydrogens = 0;
          for (IAtom atom : container.atoms()) {
  
              if (Elements.HYDROGEN.getSymbol().equals(atom.getSymbol())) {
                  hydrogens++;
              }
  
              // rare but a hydrogen may have an implicit hydrogen so we don't use 'else'
              Integer implicit = atom.getImplicitHydrogenCount();
              if (implicit != null) {
                  hydrogens += implicit;
              }
  
          }
          return hydrogens;
      }
docs: Counts the number of hydrogens on the provided IAtomContainer. As this
  method will sum all implicit hydrogens on each atom it is important to
  ensure the atoms have already been perceived (and thus have an implicit
  hydrogen count) (see. {@link #percieveAtomTypesAndConfigureAtoms}).
  
  @param container the container to count the hydrogens on
  @return the total number of hydrogens
  @see org.openscience.cdk.interfaces.IAtom#getImplicitHydrogenCount()
  @see #percieveAtomTypesAndConfigureAtoms
  @throws IllegalArgumentException if the provided container was null