001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.diff;
034:
035: import org.apache.log4j.*;
036:
037: /**
038: * Documents the difference, if any, for a given programming
039: * element that can be absent in either the old or the new
040: * codebase. This includes classes, interfaces, fields,
041: * constructors, and methods.
042: */
043: public abstract class RemovableDifferences implements Differences,
044: Comparable {
045: private String name;
046:
047: private String oldDeclaration = null;
048: private String newDeclaration = null;
049:
050: protected RemovableDifferences(String name) {
051: this .name = name;
052: }
053:
054: public String getName() {
055: return name;
056: }
057:
058: public String getOldDeclaration() {
059: return oldDeclaration;
060: }
061:
062: public void setOldDeclaration(String oldDeclaration) {
063: this .oldDeclaration = oldDeclaration;
064: }
065:
066: public String getNewDeclaration() {
067: return newDeclaration;
068: }
069:
070: public void setNewDeclaration(String newDeclaration) {
071: this .newDeclaration = newDeclaration;
072: }
073:
074: public boolean isRemoved() {
075: boolean result = (getOldDeclaration() != null)
076: && (getNewDeclaration() == null);
077:
078: Logger.getLogger(getClass()).debug(
079: getName() + " IsRemoved(): " + result);
080:
081: return result;
082: }
083:
084: public boolean isModified() {
085: boolean result = (getOldDeclaration() != null)
086: && (getNewDeclaration() != null)
087: && !getOldDeclaration().equals(getNewDeclaration());
088:
089: Logger.getLogger(getClass()).debug(
090: getName() + " IsModified(): " + result);
091:
092: return result;
093: }
094:
095: public boolean isNew() {
096: boolean result = (getOldDeclaration() == null)
097: && (getNewDeclaration() != null);
098:
099: Logger.getLogger(getClass()).debug(
100: getName() + " IsNew(): " + result);
101:
102: return result;
103: }
104:
105: public String toString() {
106: return getName();
107: }
108:
109: public int compareTo(Object other) {
110: int result = 0;
111:
112: if (other instanceof RemovableDifferences) {
113: result = getName().compareTo(
114: ((RemovableDifferences) other).getName());
115: } else {
116: throw new ClassCastException(
117: "Unable to compare RemovableDifferences to "
118: + other.getClass().getName());
119: }
120:
121: return result;
122: }
123: }
|