1 2 23 24 package net.fenyo.gnetwatch.targets; 25 26 import net.fenyo.gnetwatch.*; 27 import net.fenyo.gnetwatch.GUI.GUI; 28 import net.fenyo.gnetwatch.GUI.VisualElement; 29 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 import java.net.*; 33 34 39 40 public class TargetIPv4Subnet extends Target { 41 private static Log log = LogFactory.getLog(TargetIPv4Subnet.class); 42 43 private Inet4Address network; private Inet4Address netmask; 46 53 public TargetIPv4Subnet(final String name, final Inet4Address network, final Inet4Address netmask) throws AlgorithmException { 55 super(name); 56 if (network == null || netmask == null) throw new AlgorithmException("network or netmask is null"); 57 this.network = network; 58 this.netmask = netmask; 59 setItem(network.getHostAddress() + "/" + netmask.getHostAddress()); 60 } 61 62 67 public void initialize(final GUI gui) { 68 super.initialize(gui); 69 if (gui != null) setImageNetwork(); 70 } 71 72 77 protected Inet4Address getNetwork() { 79 return network; 80 } 81 82 87 protected Inet4Address getNetmask() { 89 return netmask; 90 } 91 92 97 public boolean canManageThisChild(final VisualElement visual_element) { 98 if (TargetIPv4.class.isInstance(visual_element)) return true; 99 return false; 100 } 101 102 107 public boolean equals(final Object o) { 109 if (this == o) return true; 110 if ((o == null) || (o.getClass() != getClass())) return false; 111 final TargetIPv4Subnet target = (TargetIPv4Subnet) o; 112 return getNetwork().equals(target.getNetwork()) && 113 getNetmask().equals(target.getNetmask()); 114 } 115 116 121 public int hashCode() { 123 return getNetwork().hashCode() ^ getNetmask().hashCode(); 124 } 125 } 126 | Popular Tags |