001: /*
002: * GNetWatch
003: * Copyright 2006, 2007 Alexandre Fenyo
004: * gnetwatch@fenyo.net
005: *
006: * This file is part of GNetWatch.
007: *
008: * GNetWatch is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License as published by
010: * the Free Software Foundation; either version 2 of the License, or
011: * (at your option) any later version.
012: *
013: * GNetWatch is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with GNetWatch; if not, write to the Free Software
020: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
021: */
022:
023: package net.fenyo.gnetwatch.targets;
024:
025: import net.fenyo.gnetwatch.*;
026: import net.fenyo.gnetwatch.GUI.GUI;
027: import net.fenyo.gnetwatch.GUI.VisualElement;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import java.net.*;
032:
033: /**
034: * TargetIPv4Range implements a range defined by two IPv4 adresses.
035: * @author Alexandre Fenyo
036: * @version $Id: TargetIPv4Range.java,v 1.10 2007/03/03 00:38:19 fenyo Exp $
037: */
038:
039: public class TargetIPv4Range extends Target {
040: private static Log log = LogFactory.getLog(TargetIPv4Subnet.class);
041:
042: private Inet4Address begin; // not null
043: private Inet4Address end; // not null
044:
045: /**
046: * Constructor.
047: * @param name target name.
048: * @param begin first address.
049: * @param end last address.
050: * @throws AlgorithmException exception.
051: */
052: // GUI thread
053: public TargetIPv4Range(final String name, final Inet4Address begin,
054: final Inet4Address end) throws AlgorithmException {
055: super (name);
056: if (begin == null || end == null)
057: throw new AlgorithmException("begin or end is null");
058: this .begin = begin;
059: this .end = end;
060: setItem(begin.getHostAddress() + "-" + end.getHostAddress());
061: }
062:
063: /**
064: * Initializes this target.
065: * @param gui current GUI instance.
066: * @return void.
067: */
068: public void initialize(final GUI gui) {
069: super .initialize(gui);
070: if (gui != null)
071: setImageNetwork();
072: }
073:
074: /**
075: * Returns the first address in the range.
076: * @param none.
077: * @return Inet4Address first address.
078: */
079: // any thread
080: protected Inet4Address getBegin() {
081: return begin;
082: }
083:
084: /**
085: * Returns the last address in the range.
086: * @param none.
087: * @return Inet4Address last address.
088: */
089: // any thread
090: protected Inet4Address getEnd() {
091: return end;
092: }
093:
094: /**
095: * Checks that the parameter can be attached to this target.
096: * @param visual_element parameter to check.
097: * @return true if the parameter can be attached to this target.
098: */
099: public boolean canManageThisChild(final VisualElement visual_element) {
100: if (TargetIPv4.class.isInstance(visual_element))
101: return true;
102: return false;
103: }
104:
105: /**
106: * Compares two targets.
107: * @param o target to compare to.
108: * @return true if the targets are equal.
109: */
110: // any thread
111: public boolean equals(final Object o) {
112: if (this == o)
113: return true;
114: if ((o == null) || (o.getClass() != getClass()))
115: return false;
116: final TargetIPv4Range target = (TargetIPv4Range) o;
117: return getBegin().equals(target.getBegin())
118: && getEnd().equals(target.getEnd());
119: }
120:
121: /**
122: * Returns the hashcode for this target.
123: * @param none.
124: * @return int hashcode.
125: */
126: // any thread
127: public int hashCode() {
128: return getBegin().hashCode() ^ getEnd().hashCode();
129: }
130: }
|