In Java, when to write separate methods for different jobs - best practices?
<p>I wrote a small <a href="http://writtingplugin.blogspot.de/#!/2013/04/checking-ipv4-and-ipv6-addresses-with.html" rel="nofollow">program</a> that validates IP addresses, esp. strips off some metadata like range and network mask of an IP v4 address before passig it to the IPAddress Checker.</p>

<p>While stripping off the network mask of an IP address I need the resulting IP address (I call it the base IP address) and the network mask in separate variables, for further validation. </p>

<p>I was wondering if the way I did it in the cutOffNetMask method is ok or if I should split the jobs</p>

<ol>
<li>extract base ip</li>
<li>extract the network mask</li>
</ol>

<p>into separate methods?</p>

<p>Is the way I set the <code>private Integer netMask;</code> ìn the cutOffNetMask method the state of the art or how does the elegant way doing it looks like?</p>

<p>Here is the snippet:</p>

<pre><code>public class IPAddress {

     private String base;
     private Integer netMask;
     private boolean ipRangeValid;
     private boolean netMaskValid;

 public IPAddress(String value){
     ipAddress = value;
     base = ipAddress;
     base.replace(" ","");

     if(isIPv6Address(base) == false){

       if(hasNetMask(base) == true){
          base = cutOffNetMask(base);
       }

       if(hasIPRange(base) == true){
          base = stripOffIPRange(base);
          ipRangeValid = ipRangeValid(octet1, octet2, octet3, octet4);
       } else {
            ipRangeValid = true;
       }
     }
 }

 private static boolean hasNetMask(String base){
     return (base.indexOf("/") != -1);
 }


  private static String cutOffNetMask(String base){
      netMask = base.substring(base.indexOf("/") + 1);
      return base.replace(netMask, "");
  }

  private String stripOffIPRange(String base){
      String[] octets = base.split("\\.");
      base = "";

      octet1 = new IPOctet(octets[0]);
      base = base + (octet1.getBase() + ".");

      octet2 = new IPOctet(octets[1]);
      base = base + (octet2.getBase() + ".");

      octet3 = new IPOctet(octets[2]);
      base = base + (octet3.getBase() + ".");

      octet4 = new IPOctet(octets[3]);
      base = base + (octet4.getBase());

      return base;
  }
</code></pre>
