001: /*
002: *
003: * The DbUnit Database Testing Framework
004: * Copyright (C)2005, DbUnit.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: */
021: package org.dbunit.util.search;
022:
023: import org.slf4j.Logger;
024: import org.slf4j.LoggerFactory;
025:
026: import org.apache.commons.lang.builder.EqualsBuilder;
027: import org.apache.commons.lang.builder.HashCodeBuilder;
028:
029: /**
030: * Basic implementation of the IEdge interface.
031: * TODO: add test cases (specially for the equals/compare methods)
032: *
033: * @author Felipe Leme <dbunit@felipeal.net>
034: * @version $Revision: 554 $
035: * @since Aug 25, 2005
036: */
037: public class Edge implements IEdge {
038:
039: /**
040: * Logger for this class
041: */
042: private static final Logger logger = LoggerFactory
043: .getLogger(Edge.class);
044:
045: private final Comparable nodeFrom;
046: private final Comparable nodeTo;
047:
048: public Edge(Comparable nodeFrom, Comparable nodeTo) {
049: if (nodeFrom == null) {
050: throw new IllegalArgumentException(
051: "node from cannot be null");
052: }
053: if (nodeTo == null) {
054: throw new IllegalArgumentException("node to cannot be null");
055: }
056: this .nodeFrom = nodeFrom;
057: this .nodeTo = nodeTo;
058: }
059:
060: public Object getFrom() {
061: logger.debug("getFrom() - start");
062:
063: return this .nodeFrom;
064: }
065:
066: public Object getTo() {
067: logger.debug("getTo() - start");
068:
069: return this .nodeTo;
070: }
071:
072: public String toString() {
073: logger.debug("toString() - start");
074:
075: return this .nodeFrom + "->" + this .nodeTo;
076: }
077:
078: public int compareTo(Object o) {
079: logger.debug("compareTo(o=" + o + ") - start");
080:
081: Edge otherEdge = (Edge) o;
082: int result = this .nodeFrom.compareTo(otherEdge.getFrom());
083: if (result == 0) {
084: result = this .nodeTo.compareTo(otherEdge.getTo());
085: }
086: return result;
087: }
088:
089: public boolean equals(Object obj) {
090: logger.debug("equals(obj=" + obj + ") - start");
091:
092: return EqualsBuilder.reflectionEquals(this , obj);
093: }
094:
095: public int hashCode() {
096: logger.debug("hashCode() - start");
097:
098: return HashCodeBuilder.reflectionHashCode(this);
099: }
100:
101: }
|