Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

DefaultLabel.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2005 Creation P.Delrieu
00026  *  2005 Modified F.Salque
00027  * 
00028  */
00029 
00030 package org.openmobileis.modules.crm.data.common;
00031 
00032 import org.openmobileis.common.intl.IntlResourceManager;
00033 import org.openmobileis.common.util.StringFormater;
00034 import org.openmobileis.common.util.collection.Orderable;
00035 import org.openmobileis.common.util.log.*;
00036 
00044 public class DefaultLabel       implements Orderable, Label {
00045 
00046         static final long serialVersionUID = 5521257935120563452L;
00047         private String labelId;
00048         private String label = null;
00049         private String langue;
00050         private String category;
00051         private int order;
00052 
00053         protected DefaultLabel() {
00054                 super();
00055         }
00056 
00057         public DefaultLabel(String id, String category, String label) {
00058                 this.label = label;
00059                 this.labelId = id;
00060                 this.category = category;
00061                 langue = IntlResourceManager.DEFAULT;
00062         }
00063 
00064         public DefaultLabel(String id, String category, String label, String language) {
00065                 this.label = label;
00066                 this.labelId = id;
00067                 this.category = category;
00068                 langue = language;
00069         }
00070 
00071         // < 0 if p1 < p2, 0 if equal, > 0 if p1 > p2
00072         public int compareTo(Object parm1, Object parm2) {
00073                 if (!(parm1 instanceof DefaultLabel) || !(parm2 instanceof DefaultLabel)) {
00074                         LogManager.traceError(
00075                                 LogServices.WEBSERVICE,
00076                                 "Attempt to compare wrong objects, not label");
00077                         return 0;
00078                 } else {
00079                         return ((DefaultLabel) parm1).compareTo(((DefaultLabel) parm2));
00080                 }
00081         }
00082 
00083         public String getLabel() {
00084                 return label;
00085         }
00086                 
00087         public String getLabelLanguage()        {
00088                 return langue;
00089         }
00090 
00091         public String getCategory()     {
00092                 return this.category;
00093         }
00094 
00095         public String getLabelId() {
00096                 return labelId;
00097         }
00098         
00104         public void setLabelSortOrder(int o)    {
00105                 this.order = o;
00106         }
00107         public int getLabelSortOrder()  {
00108                 return this.order;
00109         }
00110 
00111         public String toString() {
00112                 return this.getLabelId()+"/"+label;
00113         }
00114 
00115         public boolean equals(Object obj) {
00116                 if (!(obj instanceof DefaultLabel)) {
00117                         throw new ClassCastException();
00118                 } else {
00119                         DefaultLabel newLab = ((DefaultLabel) obj);
00120                         if ((newLab.labelId.equals(this.labelId)) &&(newLab.category.equals(this.category)))
00121                                 return true;
00122                         return false;
00123                 }
00124         }
00125 
00126         public int hashCode() {
00127                 StringBuffer strbuff = new StringBuffer(this.category);
00128                 strbuff.append('/').append(this.labelId);
00129                 return strbuff.hashCode();
00130         }
00131         
00132         // < 0 if p1 < p2, 0 if equal, > 0 if p1 > p2
00133         public int compareTo(Object parm2) {
00134                 if (!(parm2 instanceof DefaultLabel)) {
00135                         LogManager.traceError(LogServices.WEBSERVICE, "DefaultLabel Attempt to compare wrong objects, not label");
00136                         return 0;
00137                 } else {
00138                         DefaultLabel lab2 = (DefaultLabel)parm2;
00139                         int comp = this.order - lab2.order;
00140                         if (comp == 0)  {
00141                                 comp = StringFormater.removeAccent(this.getLabel()).toUpperCase().compareTo(StringFormater.removeAccent(lab2.getLabel()).toUpperCase());
00142                         }
00143                         return comp;
00144                 }
00145         }
00146 
00147 }

Generated on Wed Dec 14 21:05:32 2005 for OpenMobileIS by  doxygen 1.4.4