001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.util.bookmark;
019:
020: public class BookmarkFolder implements Comparable {
021:
022: private String name = null;
023:
024: private int id = -1;
025:
026: /**
027: * @param name
028: * @param componentPath
029: */
030: public BookmarkFolder(String name) {
031:
032: // TODO id generieren lassen und testen ob id schon vergeben.
033: // dazu event. klasse bookmarkIds Liste von klasse vector ableiten und pflegen.
034:
035: this (name, (int) Math.round(Integer.MAX_VALUE * Math.random()));
036: }
037:
038: /**
039: * @param name
040: * @param componentPath
041: */
042: public BookmarkFolder(String name, int id) {
043: this .name = name;
044: this .id = id;
045: }
046:
047: /**
048: * @return the name
049: */
050: public String getName() {
051: return name;
052: }
053:
054: /**
055: * @return the id
056: */
057: public int getId() {
058: return id;
059: }
060:
061: /**
062: * @param name
063: * the name to set
064: */
065: public void setName(String name) {
066: this .name = name;
067: }
068:
069: /**
070: * Delivers only the name and not the id.
071: *
072: * @see java.lang.Object#toString()
073: */
074: public String toString() {
075: // TODO gibt momentan nur den namen aus und nicht pfad oder beides, weil die toArray() Methode in
076: // getBookmarkList().setListData(bookmarkManager.getBookmarks().toArray()); im ManageBookmarkDialog auf jedem
077: // element die toString() Methode aufruft. die liste wird mit dem wert gefüllt und im client angezeigt...
078: return getName();
079: }
080:
081: /*
082: * (non-Javadoc)
083: *
084: * @see java.lang.Object#equals(java.lang.Object)
085: */
086: public boolean equals(Object obj) {
087: if (this == obj)
088: return true;
089: if (obj == null)
090: return false;
091: if (obj.getClass() != getClass())
092: return false;
093: if (obj instanceof BookmarkFolder) {
094: BookmarkFolder bookmarkFolder = (BookmarkFolder) obj;
095:
096: return (getName().equals(bookmarkFolder.getName()) && getId() == bookmarkFolder
097: .getId());
098: }
099: return false;
100: }
101:
102: /* (non-Javadoc)
103: * @see java.lang.Comparable#compareTo(java.lang.Object)
104: */
105: public int compareTo(Object obj) {
106:
107: // If this < o, return a negative value
108: // If this = o, return 0
109: // If this > o, return a positive value
110:
111: if (obj == null) {
112: return 1;
113: }
114: if (obj instanceof Bookmark) {
115: return -1;
116: }
117: if (obj instanceof BookmarkFolder) {
118: BookmarkFolder bookmarkFolder = (BookmarkFolder) obj;
119:
120: int nameCompare = this .getName().compareTo(
121: bookmarkFolder.getName());
122:
123: if (nameCompare == 0) {
124: // if names are equal
125: if (this .getId() == bookmarkFolder.getId()) {
126: // if ids are equal
127: return 0;
128: } else {
129: return (this .getId() < bookmarkFolder.getId() ? -1
130: : 1);
131: }
132: } else {
133: return nameCompare;
134: }
135: }
136:
137: return 0;
138: }
139: }
|