001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package de.schlund.pfixcore.editor2.core.dom;
020:
021: /**
022: * Provides functionality common to all classes implementing Variant
023: *
024: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
025: */
026: public abstract class AbstractVariant implements Variant {
027: private String name;
028:
029: /**
030: * Creates a Variant object with the specified name
031: *
032: * @param name Name of the variant to create
033: */
034: public AbstractVariant(String name) {
035: this .name = name;
036: }
037:
038: /* (non-Javadoc)
039: * @see de.schlund.pfixcore.editor2.core.dom.Variant#getName()
040: */
041: public String getName() {
042: return this .name;
043: }
044:
045: /*
046: * (non-Javadoc)
047: *
048: * @see de.schlund.pfixcore.editor2.core.dom.Variant#isChildOf(de.schlund.pfixcore.editor2.core.dom.Variant)
049: */
050: public boolean isChildOf(Variant variant) {
051: return this .getName().startsWith(variant.getName() + ":")
052: && !this .equals(variant);
053: }
054:
055: /*
056: * (non-Javadoc)
057: *
058: * @see de.schlund.pfixcore.editor2.core.dom.Variant#isParentOf(de.schlund.pfixcore.editor2.core.dom.Variant)
059: */
060: public boolean isParentOf(Variant variant) {
061: return variant.getName().startsWith(this .getName() + ":")
062: && !this .equals(variant);
063: }
064:
065: /*
066: * (non-Javadoc)
067: *
068: * @see java.lang.Object#equals(java.lang.Object)
069: */
070: public boolean equals(Object obj) {
071: if (obj instanceof Variant) {
072: Variant variant = (Variant) obj;
073: return this .getName().equals(variant.getName());
074: } else {
075: return false;
076: }
077: }
078:
079: /*
080: * (non-Javadoc)
081: *
082: * @see java.lang.Object#hashCode()
083: */
084: public int hashCode() {
085: return ("VARIANT: " + this .toString()).hashCode();
086: }
087:
088: /*
089: * (non-Javadoc)
090: *
091: * @see java.lang.Object#toString()
092: */
093: public String toString() {
094: return this .getName();
095: }
096:
097: /* (non-Javadoc)
098: * @see java.lang.Comparable#compareTo(java.lang.Object)
099: */
100: public int compareTo(Variant variant) {
101: return this.getName().compareTo(variant.getName());
102: }
103: }
|