KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > fenyo > gnetwatch > targets > TargetIPv4Range


1
2 /*
3  * GNetWatch
4  * Copyright 2006, 2007 Alexandre Fenyo
5  * gnetwatch@fenyo.net
6  *
7  * This file is part of GNetWatch.
8  *
9  * GNetWatch is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * GNetWatch is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with GNetWatch; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22  */

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 /**
35  * TargetIPv4Range implements a range defined by two IPv4 adresses.
36  * @author Alexandre Fenyo
37  * @version $Id: TargetIPv4Range.java,v 1.10 2007/03/03 00:38:19 fenyo Exp $
38  */

39
40 public class TargetIPv4Range extends Target {
41   private static Log log = LogFactory.getLog(TargetIPv4Subnet.class);
42
43   private Inet4Address begin; // not null
44
private Inet4Address end; // not null
45

46   /**
47    * Constructor.
48    * @param name target name.
49    * @param begin first address.
50    * @param end last address.
51    * @throws AlgorithmException exception.
52    */

53   // GUI thread
54
public TargetIPv4Range(final String JavaDoc name, final Inet4Address begin, final Inet4Address end) throws AlgorithmException {
55     super(name);
56     if (begin == null || end == null) throw new AlgorithmException("begin or end is null");
57     this.begin = begin;
58     this.end = end;
59     setItem(begin.getHostAddress() + "-" + end.getHostAddress());
60   }
61
62   /**
63    * Initializes this target.
64    * @param gui current GUI instance.
65    * @return void.
66    */

67   public void initialize(final GUI gui) {
68     super.initialize(gui);
69     if (gui != null) setImageNetwork();
70   }
71
72   /**
73    * Returns the first address in the range.
74    * @param none.
75    * @return Inet4Address first address.
76    */

77   // any thread
78
protected Inet4Address getBegin() {
79     return begin;
80   }
81
82   /**
83    * Returns the last address in the range.
84    * @param none.
85    * @return Inet4Address last address.
86    */

87   // any thread
88
protected Inet4Address getEnd() {
89     return end;
90   }
91
92   /**
93    * Checks that the parameter can be attached to this target.
94    * @param visual_element parameter to check.
95    * @return true if the parameter can be attached to this target.
96    */

97   public boolean canManageThisChild(final VisualElement visual_element) {
98     if (TargetIPv4.class.isInstance(visual_element)) return true;
99     return false;
100   }
101
102   /**
103    * Compares two targets.
104    * @param o target to compare to.
105    * @return true if the targets are equal.
106    */

107   // any thread
108
public boolean equals(final Object JavaDoc o) {
109     if (this == o) return true;
110     if ((o == null) || (o.getClass() != getClass())) return false;
111     final TargetIPv4Range target = (TargetIPv4Range) o;
112     return getBegin().equals(target.getBegin()) && getEnd().equals(target.getEnd());
113   }
114   
115   /**
116    * Returns the hashcode for this target.
117    * @param none.
118    * @return int hashcode.
119    */

120   // any thread
121
public int hashCode() {
122     return getBegin().hashCode() ^ getEnd().hashCode();
123   }
124 }
125
Popular Tags