001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: DataLink.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.engine;
009:
010: class DataLink {
011: private String mOutput = null;
012: private ElementInfo mTarget = null;
013: private boolean mSnapback = false;
014: private String mInput = null;
015: private FlowLink mFlowLink = null;
016:
017: DataLink(String output, ElementInfo target, boolean snapback,
018: String input, FlowLink flowlink) {
019: assert output != null;
020: assert output.length() > 0;
021: assert target != null || snapback;
022: assert null == target || !snapback;
023: assert input != null;
024: assert input.length() > 0;
025:
026: mOutput = output;
027: mTarget = target;
028: mSnapback = snapback;
029: mInput = input;
030: mFlowLink = flowlink;
031: }
032:
033: String getOutput() {
034: return mOutput;
035: }
036:
037: ElementInfo getTarget() {
038: return mTarget;
039: }
040:
041: boolean isSnapback() {
042: return mSnapback;
043: }
044:
045: String getInput() {
046: return mInput;
047: }
048:
049: FlowLink getFlowLink() {
050: return mFlowLink;
051: }
052:
053: public int hashCode() {
054: int target = 1;
055: int snapback = 1;
056: int flowlink = 1;
057:
058: if (mTarget != null) {
059: target = mTarget.hashCode();
060: }
061: if (mSnapback) {
062: snapback = 2;
063: }
064: if (mFlowLink != null) {
065: flowlink = mFlowLink.hashCode();
066: }
067: return mOutput.hashCode() * target * snapback
068: * mInput.hashCode() * flowlink;
069: }
070:
071: public boolean equals(Object other) {
072: if (this == other) {
073: return true;
074: }
075:
076: if (null == other) {
077: return false;
078: }
079:
080: if (!(other instanceof DataLink)) {
081: return false;
082: }
083:
084: DataLink other_datalink = (DataLink) other;
085: if (!other_datalink.getOutput().equals(getOutput())) {
086: return false;
087: }
088: if (other_datalink.getTarget() != null || getTarget() != null) {
089: if (null == other_datalink.getTarget()
090: && getTarget() != null) {
091: return false;
092: }
093: if (other_datalink.getTarget() != null
094: && null == getTarget()) {
095: return false;
096: }
097: if (!other_datalink.getTarget().equals(getTarget())) {
098: return false;
099: }
100: }
101: if (other_datalink.isSnapback() != isSnapback()) {
102: return false;
103: }
104: if (!other_datalink.getInput().equals(getInput())) {
105: return false;
106: }
107: if (other_datalink.getFlowLink() != null
108: || getFlowLink() != null) {
109: if (null == other_datalink.getFlowLink()
110: && getFlowLink() != null) {
111: return false;
112: }
113: if (other_datalink.getFlowLink() != null
114: && null == getFlowLink()) {
115: return false;
116: }
117: if (!other_datalink.getFlowLink().equals(getFlowLink())) {
118: return false;
119: }
120: }
121:
122: return true;
123: }
124: }
|