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:
020: package de.schlund.pfixcore.lucefix;
021:
022: public class Tripel implements Comparable<Tripel> {
023:
024: private Type type;
025: private String product;
026: private String part;
027: private String filename;
028:
029: /**
030: * @param product
031: * @param part
032: * @param filename
033: */
034: public Tripel(String product, String part, String filename,
035: Type type) {
036: this .product = product;
037: this .part = part;
038: this .filename = filename;
039: this .type = type;
040: }
041:
042: public Tripel(String product, String part, String filename) {
043: this .product = product;
044: this .part = part;
045: this .filename = filename;
046: this .type = Type.INSERT;
047: }
048:
049: public Tripel(String fullpath, Type type) {
050: int schnippel2 = fullpath.lastIndexOf("/");
051: int schnippel1 = fullpath.lastIndexOf("/", schnippel2 - 1);
052: filename = fullpath.substring(0, schnippel1);
053: part = fullpath.substring(schnippel1 + 1, schnippel2);
054: product = fullpath.substring(schnippel2 + 1, fullpath.length());
055: this .type = type;
056: }
057:
058: public Type setType(Type newType) {
059: Type retval = type;
060: type = newType;
061: return retval;
062: }
063:
064: public Type getType() {
065: return type;
066: }
067:
068: public String getFilename() {
069: return filename;
070: }
071:
072: public String getPart() {
073: return part;
074: }
075:
076: public String getProduct() {
077: return product;
078: }
079:
080: public String toString() {
081: StringBuffer sb = new StringBuffer();
082: sb.append(getFilename());
083: sb.append("|");
084: sb.append(getPart());
085: sb.append("|");
086: sb.append(getProduct());
087: return sb.toString();
088: }
089:
090: /**
091: * @param current
092: * @return
093: */
094: public String getPath() {
095: StringBuffer sb = new StringBuffer(getFilename());
096: // TODO: seperator irgendwo herholen?
097: sb.append("/");
098: sb.append(getPart());
099: sb.append("/");
100: sb.append(getProduct());
101: return sb.toString();
102: }
103:
104: public boolean equals(Object arg0) {
105: if (arg0 instanceof Tripel) {
106: Tripel c = (Tripel) arg0;
107: return (c.getFilename().equals(getFilename())
108: && c.getPart().equals(getPart()) && c.getProduct()
109: .equals(getProduct()));
110: }
111: return false;
112: }
113:
114: public int hashCode() {
115: return getPath().hashCode();
116: }
117:
118: public enum Type {
119: INSERT, DELETE, EDITORUPDATE;
120: }
121:
122: public int compareTo(Tripel a) {
123: int result;
124: result = a.getFilename().compareTo(this .getFilename());
125: if (result == 0) {
126: result = a.getPart().compareTo(this .getPart());
127: if (result == 0) {
128: result = a.getProduct().compareTo(this.getProduct());
129: }
130: }
131: return result;
132: }
133: }
|